GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #31  
Old 16-May-2007, 16:49
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road
Thumbs up

Re: Linked Lists advice request


Yes there is a companion cpp file... added it to project; pasted it into t' file, SORTED!!! - sorry it took 4 pages!!!
(with #include as "graphics_lib.h")

(yes I use XP Pro at home; Win 2000 or summat on campus).
(Mentioned on the first post is that I'm using MS Visual Basic C++ 6.0)
(The link is to the header file location is on the first thread, but not needed now)


Now for the rotation matrix and temporary normalisation of the triangle vertex co-ordinates!
  #32  
Old 16-May-2007, 18:39
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road
Question

Re: Linked Lists advice request


Here's where I am:
CPP / C++ / C Code:
typedef struct long_shape_type {
    int start_x1, start_y1;
    int start_x2, start_y2;
    int start_x3, start_y3;
    int x;
    int y;
    int size;
    int radius;
    int colour;
    struct long_shape_type *prev;
    struct long_shape_type *next;
} shape_type;

typedef struct long_line_type {
    int start_x, start_y;
    int end_x, end_y;
    int x;
    int y;
    int size;
    int radius;
    int colour;
    struct long_line_type *prev;
    struct long_line_type *next;
} line_type;

#include <stdio.h>
#include "graphics_lib.h"
#include <math.h>
#include <conio.h>

struct triangle
{
  int corner1x;
  int corner1y;
  int corner2x;
  int corner2y;
  int corner3x;
  int corner3y;
  int colour;
  float theta;
} tangle;

//copied from ["http://lavluda.x10hosting.com/download/2d.doc"]
// My intention is to adapt this code to suit my assignment requirements, and cite this as a reference
struct point
{
	float corner1x;
	float corner1y;
	float corner2x;
	float corner2y;
	float corner3x;
	float corner3y;
	float x;
	float y;
	float theta;
	int colour;
	int size;
}point1,point2,point3,newpoint1,newpoint2,newpoint3;


void copyvalue()
{
	point1.x=newpoint1.x,point1.y=newpoint1.y;
	point2.x=newpoint2.x,point2.y=newpoint2.y;
	point3.x=newpoint3.x,point3.y=newpoint3.y;
}


//end of copied code

struct triangle *Tptr;

void display_line(struct triangle *Tptr);
void get_tangle(struct triangle *Tptr);

#define PI 3.14159265

 /*
 * THE MAIN FUNCTION - the programme starts executing here
 */

int main()
{

    /* DECLARE VARIABLES */
    int x;
    int y;
    int size;
	int choice;
	int moveshape_x;
	int moveshape_y;
	int sizeshape_x;
	int sizeshape_y;
	float sin_value;
	float cos_value;
	float theta;

    shape_type st;
    line_type lt;

 //shape_type circle;
 //shape_type triangle;
 //shape_type square;

/*
EASEL SCREEN - USER INPUT
*/

     /* Size Selection */
     printf("please enter a number for the size of your shape:\n");
     scanf("%d",&size);

     /* Get initial coordinates */
     printf("please enter an x and a y co-ordinate for your shape\n");
     printf("x position is: \n");
     scanf("%d",&x);
     printf("y position is: \n");
     scanf("%d",&y);

    /* SHAPE CONSTRUXION */

    st.start_x1 = 12;
    //lt.start_x = 34;
    printf("st.start_x1 = %d\n", st.start_x1);
   // printf("lt.start_x  = %d\n", lt.start_x);

    /* Line Construxion */
    lt.start_x = x;
    lt.start_y = y+(size/2);
    lt.end_x = x;
    lt.end_y = y-(size/2);
    printf("lt.start_x = %d\n", lt.start_x);
    printf("lt.start_y = %d\n", lt.start_y);
    printf("lt.end_x = %d\n", lt.end_x);
    printf("lt.end_y = %d\n", lt.end_y);

    /* Circle Construxion */
    lt.start_x = x;
    lt.start_y = y;
    lt.radius = size;
    printf("lt.start_x = %d\n", lt.start_x);
    printf("lt.start_y = %d\n", lt.start_y);
    printf("lt.radius = %d\n", lt.radius);

    /* Triangle Construction */

    Tptr = &tangle;
    get_tangle(Tptr);

    printf("The line goes from (%d,%d) to (%d,%d) to (%d,%d) and finally back to (%d,%d); it's colour is code %d \n", tangle.corner1x, tangle.corner1y, tangle.corner2x, tangle.corner2y, tangle.corner3x, tangle.corner3y, tangle.corner1x, tangle.corner1y ,  tangle.colour);

    display_line(Tptr);

 /* A MENU OF SWITCHES

 switch
  case 'a' = choose new shape
  case 'b' = choose colour
  case 'c' = choose size
  case 'd' = choose points
  case 'e' = choose undo shape
  case 'f' = choose next shape
  case 'g' = choose exit

/*

 x_temp= normalize(tangle.corner1x);

{ cornerxtemp=x-centrepoint_x;
cornerytemp=y-centrepoint_x;}
} 

need to calc vertex coords as relative to screen not relative to centre point

 cornerytemp= normalize(point1.corner1y);

nor
/* SWITCHCRAFT */

	printf("Menu\n");
	printf("1.Translation\n2.Scaling\n3.Rotation\n4.Fig\n5.Exit\n");
	printf("Enter your choice: ");
	scanf("%d",&choice);
	printf("\n");
	switch(choice)
	{
		case 1:
			printf("Translation:\n");
			printf("Please enter the translation value (x,y):");
			scanf("%d %d",&moveshape_x,&moveshape_y);
			newpoint1.x=point1.x+moveshape_x,newpoint1.y=point1.y+moveshape_y;
			newpoint2.x=point2.x+moveshape_x,newpoint2.y=point2.y+moveshape_y;
			newpoint3.x=point3.x+moveshape_x,newpoint3.y=point3.y+moveshape_y;
			//told(point1,point2,point3,0);
			tnew(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 2:
			printf("Scaling:\n");
			printf("Please enter the Scaling value (x,y):");
			scanf("%f %f",&sizeshape_x,&sizeshape_y);
			newpoint1.x=(float)(point1.x*sizeshape_x),newpoint1.y=(float)(point1.y*sizeshape_y);
			newpoint2.x=(float)(point2.x*sizeshape_x),newpoint2.y=(float)(point2.y*sizeshape_y);
			newpoint3.x=(float)(point3.x*sizeshape_x),newpoint3.y=(float)(point3.y*sizeshape_y);
			//told(point1,point2,point3,0);
			new_triangle(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 3:	
			printf("Rotation:\n");
			printf("please enter an angle to rotate your shape by\n");
		getch();
		printf("angle:\n");
		scanf("%d",&theta);
		getch();
		printf("press any key to continue\n");
		

     sin_value = sin (theta*PI/180);
     cos_value = cos (theta*PI/180);

     newpoint1.corner1x=(((point1.corner1x*cos_value )-(point1.corner1y*sin_value)));
     newpoint1.corner1y=(((point1.corner1y*cos_value )+(point1.corner1x*sin_value)));

     newpoint2.corner2x=(((point2.corner2x*cos_value )-(point2.corner2y*sin_value)));
     newpoint2.corner2y=(((point2.corner2y*cos_value)+(point2.corner2x*sin_value)));

     newpoint3.corner3x=(((point3.corner3x*cos_value )-(point3.corner3y*sin_value)));
     newpoint3.corner3y=(((point3.corner3y*cos_value)+(point3.corner3x*sin_value )));

     //told(point1,point2,point3,0);
     new_triangle(tangle,3,1);
     copyvalue();
//[source " http://lavluda.x10hosting.com/download/2d.doc"]
/*
   need to "normalise" cornerx etc by creating a new temp variable called cornerxtemp
 */
    getch();
   
    return 0;
}

/* **********  functions  *********** */

void display_line(struct triangle *Tptr)
{
  initwindow(600, 400);
  setcolor(Tptr->colour);
  line(Tptr->corner1x, Tptr->corner1y, Tptr->corner2x, Tptr->corner2y);
  line(Tptr->corner2x, Tptr->corner2y, Tptr->corner3x, Tptr->corner3y);
  line(Tptr->corner3x, Tptr->corner3y, Tptr->corner1x, Tptr->corner1y);

  /* Draw the line (set a co-ord to draw line )
  [url]http://www.cs.colorado.edu/~main/cs1300/doc/bgi/index.html[/url]
  void line(int x1, int y1, int x2, int y2);
  Description -  line draws a line in the current color, using the current line style and thickness between the two points specified, (x1,y1) and (x2,y2), without updating the current position (CP).
  */
}


void get_tangle(struct triangle *Tptr)
{
  printf("The Display is 600 x 400.  Enter COORDs for: \n       corner1x: ");
  scanf ("%d", &Tptr->corner1x);
  printf("       T1y: ");
  scanf ("%d", &Tptr->corner1y);
  printf("       T2x: ");
  scanf ("%d", &Tptr->corner2x);
  printf("       T2y: ");
  scanf ("%d", &Tptr->corner2y);
  printf("       T3x: ");
  scanf ("%d", &Tptr->corner3x);
  printf("       T3y: ");
  scanf ("%d", &Tptr->corner3y);
  printf("and colour: ");
  scanf ("%d", &Tptr->colour);
  printf("%d, %d, %d, %d, %d, %d, %d <-and there they are. \n", Tptr->corner1x, Tptr->corner1y, Tptr->corner2x, Tptr->corner2y, Tptr->corner3x, Tptr->corner3y, Tptr->colour);
}
Here's the error (and 4 warnings I get):
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(195) : warning C4013: 'tnew' undefined; assuming extern returning int
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(207) : warning C4013: 'new_triangle' undefined; assuming extern returning int
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(221) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(222) : warning C4244: '=' : conversion from 'double ' to 'float ', possible loss of data
C:\Documents and Settings\...shapeshifter\shapeshifter\shapeshifter .c(247) : error C2143: syntax error : missing ';' before 'type'
Error executing cl.exe.

shapeshifter.obj - 1 error(s), 4 warning(s)

This is as a result of including a new switch. I think the structures and linked lists are alright, I've been panning through it all for an hour now, and I still don't really understand why the prog wants a semicolon there... I suspect there's some other problem, but I'm too tired to think of much more than bed.

Any ideas please anyone?
  #33  
Old 17-May-2007, 00:54
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Linked Lists advice request


Your post is much more orderly and concise now, much easier for people to understand.
Your code is too! but you sure are writing way ahead of your testing.

I attempted compiling and got similar results which I addressed like this:
CPP / C++ / C Code:
/*  D:\C\mystuff\graphics\promsan>  bgi++ promsan4_0.c  -o promsan4_0.exe
promsan4_0.c: In function `int main()':
promsan4_0.c:195: error: `tnew' undeclared (first use this function)
promsan4_0.c:195: error: (Each undeclared identifier is reported only once for
   each function it appears in.)
promsan4_0.c:207: error: `new_triangle' undeclared (first use this function)
promsan4_0.c:248: error: syntax error before `{' token


1 L195- //tnew(newpoint1,newpoint2,newpoint3,5,1);
-- only place I even saw it used, looks like future function call. I commented out.

2 L207- //new_triangle(newpoint1,newpoint2,newpoint3,5,1);
. L234- //new_triangle(tangle,3,1);
-- again function with no prototype in header , not used (I think) , commented out.

3 L264- void display_line(struct triangle *Tptr)
{

-- looks ok to me , look up above for unclosed set of braces-> {}...
. . uh huh , at the end of the switch.
. . but where is it supposed to be closed???
. . I just stuck at 219...

see what happens... ... compiled , running , first triangle prints ok, 
second part results vary depending on choice. */
Now you try it out and see your results and start refining.
Do not go any further with the program until you have fixed what you have the way you want it.
You're already trying to manipulate a figure when you don't even know if it prints!
Get it drawing correctly first then work on ONE (1) ((uno)) manipulation routine at a time until it works the way you want.
I might also suggest a little better description and instruction to user, like I'm a dummy at computers, I don't know what to do.... which, the more I learn the more it is true ....
  #34  
Old 17-May-2007, 08:19
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road

Re: Linked Lists advice request


Aye lad.

I appreciate that I'm trying too rush in too much code, but I wanted to test out this rotation code from a Bengali university site.
I'll try and replace the lines with printfs as you say.
I know the instruxions are naff, I just want to get the screen sequence up and running, so that there's a couple of printf screens before you get to the actual drawing part.

Works a treat at the moment:
CPP / C++ / C Code:
typedef struct long_shape_type {
    int start_x1, start_y1;
    int start_x2, start_y2;
    int start_x3, start_y3;
    int x;
    int y;
    int size;
    int radius;
    int colour;
    struct long_shape_type *prev;
    struct long_shape_type *next;
} shape_type;

typedef struct long_line_type {
    int start_x, start_y;
    int end_x, end_y;
    int x;
    int y;
    int size;
    int radius;
    int colour;
    struct long_line_type *prev;
    struct long_line_type *next;
} line_type;

#include <stdio.h>
#include "graphics_lib.h"
#include <math.h>
#include <conio.h>

struct triangle {
  int corner1x;
  int corner1y;
  int corner2x;
  int corner2y;
  int corner3x;
  int corner3y;
  int colour;
  float theta;
} tangle;

//copied from ["http://lavluda.x10hosting.com/download/2d.doc"]
// My intention is to adapt this code to suit my assignment requirements, and cite this as a reference
struct point
{
	double corner1x;
	double corner1y;
	double corner2x;
	double corner2y;
	double corner3x;
	double corner3y;
	double x;
	double y;
	double theta;
	int colour;
	int size;
}point1,point2,point3,newpoint1,newpoint2,newpoint3;


void copyvalue()
{
	point1.x=newpoint1.x,point1.y=newpoint1.y;
	point2.x=newpoint2.x,point2.y=newpoint2.y;
	point3.x=newpoint3.x,point3.y=newpoint3.y;
}


//end of copied code

struct triangle *Tptr;

void display_line(struct triangle *Tptr);
void get_tangle(struct triangle *Tptr);

#define PI 3.14159265

 /*
 * THE MAIN FUNCTION - the programme starts executing here
 */

int main()
{

    /* DECLARE VARIABLES */
    int x;
    int y;
    int size;
	int choice;
	int moveshape_x;
	int moveshape_y;
	int sizeshape_x;
	int sizeshape_y;
	double sin_value;
	double cos_value;
	float theta;

//    shape_type st;
    line_type lt;

 //shape_type circle;
 //shape_type triangle;
 //shape_type square;

/*
INTRO SCREENS
*/

/* SWITCH */

//	do{
	int menu_array[1][6]={1,2,3,4,5};

	char Menu1[]="Move Shape";
	char Menu2[]="Size Shape";
	char Menu3[]="Rotate Shape";
	char Menu4[]="Instructions";
	char Menu5[]="Exit";

	printf("Menu\n");
	printf("1.Move shape\n2.Size shape\n3.Rotate shape\n4.Instruxions\n5.Exit\n");
	printf("Enter your choice: ");
	scanf("%d",&choice);
	printf("\n");
	switch(choice)
	{
		case 1:
			printf("Move shape:\n");
			printf("Please enter the translation value (x,y):");
			scanf("%d %d",&moveshape_x,&moveshape_y);
			newpoint1.x=point1.x+moveshape_x,newpoint1.y=point1.y+moveshape_y;
			newpoint2.x=point2.x+moveshape_x,newpoint2.y=point2.y+moveshape_y;
			newpoint3.x=point3.x+moveshape_x,newpoint3.y=point3.y+moveshape_y;
			//told(point1,point2,point3,0);
			//tnew(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 2:
			printf("Scaling:\n");
			printf("Please enter the Scaling value (x,y):");
			scanf("%f %f",&sizeshape_x,&sizeshape_y);
			newpoint1.x=(float)(point1.x*sizeshape_x),newpoint1.y=(float)(point1.y*sizeshape_y);
			newpoint2.x=(float)(point2.x*sizeshape_x),newpoint2.y=(float)(point2.y*sizeshape_y);
			newpoint3.x=(float)(point3.x*sizeshape_x),newpoint3.y=(float)(point3.y*sizeshape_y);
			//told(point1,point2,point3,0);
			//new_triangle(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 3:	
			printf("Rotation:\n");
			printf("please enter an angle to rotate your shape by\n");
		getch();
		printf("angle:\n");
		scanf("%d",&theta);
		getch();
		printf("press any key to continue\n");
/*
		break;
		case 4:	
			printf("Instruxions:\n");
			getch();
			printf("Return to menu? (Y/N):\n");
			scanf("%c",&key_select);

			break;
		case 5:	
			printf("bye bye!:\n");
			printf("Return to menu? (Y/N):\n");
			scanf("%c",&key_select);
			getch();
*/		

     sin_value = sin (theta*PI/180);
     cos_value = cos (theta*PI/180);

     newpoint1.corner1x=(((point1.corner1x*cos_value )-(point1.corner1y*sin_value)));
     newpoint1.corner1y=(((point1.corner1y*cos_value )+(point1.corner1x*sin_value)));

     newpoint2.corner2x=(((point2.corner2x*cos_value )-(point2.corner2y*sin_value)));
     newpoint2.corner2y=(((point2.corner2y*cos_value)+(point2.corner2x*sin_value)));

     newpoint3.corner3x=(((point3.corner3x*cos_value )-(point3.corner3y*sin_value)));
     newpoint3.corner3y=(((point3.corner3y*cos_value)+(point3.corner3x*sin_value )));
	}
	//while key_select !=6;

     //told(point1,point2,point3,0);
     //new_triangle(tangle,3,1);
     //copyvalue();
//[source " http://lavluda.x10hosting.com/download/2d.doc"]


/*
EASEL SCREEN - USER INPUT
*/

     /* Size Selection */
     printf("please enter a number for the size of your shape:\n");
     scanf("%d",&size);

     /* Get initial coordinates */
     printf("please enter an x and a y co-ordinate for your shape\n");
     printf("x position is: \n");
     scanf("%d",&x);
     printf("y position is: \n");
     scanf("%d",&y);

    /* SHAPE CONSTRUXION */

    //st.start_x1 = 12;
    //lt.start_x = 34;
    //printf("st.start_x1 = %d\n", st.start_x1);
    // printf("lt.start_x  = %d\n", lt.start_x);

    /* Line Construxion */
    lt.start_x = x;
    lt.start_y = y+(size/2);
    lt.end_x = x;
    lt.end_y = y-(size/2);
    printf("lt.start_x = %d\n", lt.start_x);
    printf("lt.start_y = %d\n", lt.start_y);
    printf("lt.end_x = %d\n", lt.end_x);
    printf("lt.end_y = %d\n", lt.end_y);

    /* Circle Construxion */
    lt.start_x = x;
    lt.start_y = y;
    lt.radius = size;
    printf("lt.start_x = %d\n", lt.start_x);
    printf("lt.start_y = %d\n", lt.start_y);
    printf("lt.radius = %d\n", lt.radius);

    /* Triangle Construction */

    Tptr = &tangle;
    get_tangle(Tptr);

    printf("The line goes from (%d,%d) to (%d,%d) to (%d,%d) and finally back to (%d,%d); it's colour is code %d \n", tangle.corner1x, tangle.corner1y, tangle.corner2x, tangle.corner2y, tangle.corner3x, tangle.corner3y, tangle.corner1x, tangle.corner1y ,  tangle.colour);

    display_line(Tptr);


/*

 x_temp= normalize(tangle.corner1x);

{ cornerxtemp=x-centrepoint_x;
cornerytemp=y-centrepoint_x;}
} 

need to calc vertex coords as relative to screen not relative to centre point

 cornerytemp= normalize(point1.corner1y);

nor
/*
   need to "normalise" cornerx etc by creating a new temp variable called cornerxtemp
 */
    getch();
   
    return 0;
}

/* **********  functions  *********** */

void display_line(struct triangle *Tptr)
{
  initwindow(600, 400);
  setcolor(Tptr->colour);
  line(Tptr->corner1x, Tptr->corner1y, Tptr->corner2x, Tptr->corner2y);
  line(Tptr->corner2x, Tptr->corner2y, Tptr->corner3x, Tptr->corner3y);
  line(Tptr->corner3x, Tptr->corner3y, Tptr->corner1x, Tptr->corner1y);

  /* Draw the line (set a co-ord to draw line )
  [url]http://www.cs.colorado.edu/~main/cs1300/doc/bgi/index.html[/url]
  void line(int x1, int y1, int x2, int y2);
  Description -  line draws a line in the current color, using the current line style and thickness between the two points specified, (x1,y1) and (x2,y2), without updating the current position (CP).
  */
}


void get_tangle(struct triangle *Tptr)
{
  printf("The Display is 600 x 400.  Enter COORDs for: \n       corner1x: ");
  scanf ("%d", &Tptr->corner1x);
  printf("       T1y: ");
  scanf ("%d", &Tptr->corner1y);
  printf("       T2x: ");
  scanf ("%d", &Tptr->corner2x);
  printf("       T2y: ");
  scanf ("%d", &Tptr->corner2y);
  printf("       T3x: ");
  scanf ("%d", &Tptr->corner3x);
  printf("       T3y: ");
  scanf ("%d", &Tptr->corner3y);
  printf("and colour: ");
  scanf ("%d", &Tptr->colour);
  printf("%d, %d, %d, %d, %d, %d, %d <-and there they are. \n", Tptr->corner1x, Tptr->corner1y, Tptr->corner2x, Tptr->corner2y, Tptr->corner3x, Tptr->corner3y, Tptr->colour);
}

Just hunting for a way to construct a nice menu... are there any in-biult funcitons for centreing printfs? as you can see I'm trying to do an array; and trying to work out how to do a "return to menu" thing... I need to make this Key-press function
  #35  
Old 17-May-2007, 08:40
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Linked Lists advice request


whatever...
Ahem, I know your quite proud of it and all,
but why did you repost your experimental code ???
You did'nt even have a question about it. ? c'mon man !
- it's useless page size that dialupers have to wait for,
- it's useless junk for us to have to pagedown through,
- it's useless use of bandwidth for gidforums.
need more?
  #36  
Old 17-May-2007, 09:51
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road
Question

Re: Linked Lists advice request


sorry, I think you misinterpreted me, I was asking:

Quote:
are there any in-built functions for centreing printfs?
...and fishing for some ideas on
Quote:
a way to construct a nice menu
...I admit it's trivial; but there were questions, and I would have got slammed for not posting the code that I'm using that shows what I've been doing in a way people could copy and run if they wanted, am I right?
Do you want me to just post sections that I've changed from above with line numbers instead? Isn't there a risk of it being confusing?

Anyway, I'm more interested in implementing a rotation matrix for the triangle. It's quite hard conceptually to translate stratforward maths like this into code I think.

So I'm looking at summat like this:
CPP / C++ / C Code:

/*
ROTATION MATRIX IMPLEMENTATION:
 
I need to calculate vertex co-ords as relative to the screen not relative to centre point;
so I need to "normalise" corner1x etc by creating a new temp variable called corner1xtemp.

e.g.: 
corner1x_temp= normalise(tangle.corner1x);
corner1y_temp= normalise(tangle.corner1y);

or in algorithmic and maths form

cornerA'=normalised(cornerA)
cornerA'=cornerA-centrepoint

|Y'| |X | |Yc|
|  |=|  |-|  |
|Y'| |Y | |Yc|

e.g.:
         x , y
cornerA=(30,60)
cornerA'=(30-Xc,60-Yc)


As a function:

double rotation_matrix(struct triangle *Tptr)
{
corner1xtemp=corner1x-centrepoint_x;
corner1ytemp=corner1y-centrepoint_y;

corner2xtemp=corner2x-centrepoint_x;
corner2ytemp=corner2y-centrepoint_y;

corner3xtemp=corner3x-centrepoint_x;
corner3ytemp=corner3y-centrepoint_y;
} 

*/
Does this make any sense?
  #37  
Old 17-May-2007, 10:28
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 803
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Linked Lists advice request


Quote:
Do you want me to just post sections that I've changed from above with line numbers instead?
YES , Only the pertinent sections PLEASE!
Quote:
Isn't there a risk of it being confusing?
Not if your question and reference make sense.
For example you could have posted this:
CPP / C++ / C Code:
	int menu_array[1][6]={1,2,3,4,5};

	char Menu1[]="Move Shape";
	char Menu2[]="Size Shape";
	char Menu3[]="Rotate Shape";
	char Menu4[]="Instructions";
	char Menu5[]="Exit";

	printf("Menu\n");
	printf("1.Move shape\n2.Size shape\n3.Rotate shape\n4.Instruxions\n5.Exit\n");
	printf("Enter your choice: ");
	scanf("%d",&choice);
	printf("\n");
	switch(choice)
	{   /* blah blah blah (we wouldn't need to see what you did with a choice) */
And asked your questions, and ONE might reply:
- center printf()'s .....no function for that , just pad with spaces, ie:
CPP / C++ / C Code:
	char Menu1[]="       Move Shape:";
	char Menu2[]="       Size Shape:";
	char Menu3[]="     Rotate Shape:";
	char Menu4[]="     Instructions:";
	char Menu5[]="             Exit:";
- menu . .... No function , but what you've got going works and it could be a function to keep main() cleaner. Lot's of options there. The beauty of C.
No time to look at more, gotta go, good luck...
  #38  
Old 17-May-2007, 11:01
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road

Re: Linked Lists advice request


used outtextxy

Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(174) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(176) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(177) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(17 : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(179) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(180) : error C2143: syntax error : missing ';' before 'type'
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(245) : warning C4047: '!=' : 'int (__stdcall *)(int ,struct fd_set *,struct fd_set *,struct fd_set *,const struct timeval *)' differs
in levels of indirection from 'const int '
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(370) : error C2143: syntax error : missing ';' before 'type'
Error executing cl.exe.

shapeshifter.obj - 7 error(s), 1 warning(s)


what's all this about?

I've stuck this in above and below that array
CPP / C++ / C Code:
/*
INTRO SCREENS
*/

 setcolor(YELLOW);
 outtextxy(50,200, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");     
 outtextxy(50,210, "			Welcome to SHAPESHIFTER											  "); 
 outtextxy(50,220, "				1.Move shape\n											   	  ");
 outtextxy(50,230, "				2.Size shape\n												  "); 
 outtextxy(50,240, "				3.Rotate shape\n											  ");
 outtextxy(50,250, "				4.Instruxions\n												  "); 
 outtextxy(50,260, "				5.Exit\n													  ");
 outtextxy(50,260, "																			  ");
 outtextxy(50,270, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");


 outtextxy(100,320, "Please select difficulty level: easy; medium; hard.\n"); 
 setcolor(RED);
 outtextxy(150,360, "Press any key to continue.\n");
/*
 do 
    {
 move=getch();
 if( move == 0 )
  move=getch();
    switch(move)
        {
    //scroll left
 case 77:
            {
                outtextxy(100,405, "Easy")
          } 
  break;
    //scroll right
 case 75:
            {
                outtextxy(100,405, "Hard")
          }
    break;
        } 
    }
while(select!=13);
*/
 getch();
cleardevice();

setcolor(BLUE);
 outtextxy(50,200, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");     
 outtextxy(50,210, "							Instructions:									  "); 
 outtextxy(50,220, "																			  ");
 outtextxy(50,230, "							Select Shape;		                              ");
 outtextxy(50,240, "							Select Size of shape						      "); 
 outtextxy(50,250, "                            Select Colour of shape                            ");
 outtextxy(50,260, "                            Select Orientation of shape					      ");
 outtextxy(50,270, "							Select Position of shape						  ");
 outtextxy(50,280, "																			  "); 
 setcolor(RED);
 outtextxy(50,290, "                            Press any key to start.                           ");
  setcolor(BLUE);
 outtextxy(50,300, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); 
  
 getch();
cleardevice();



/* SWITCH */

	int menu_array[1][6]={1,2,3,4,5};

	char Menu1[]="Move Shape";
	char Menu2[]="Size Shape";
	char Menu3[]="Rotate Shape";
	char Menu4[]="Instructions";
	char Menu5[]="Exit";

	printf("Menu\n");
	printf("1.Move shape\n2.Size shape\n3.Rotate shape\n4.Instruxions\n5.Exit\n");
	printf("Enter your choice: ");
	scanf("%d",&choice);
	printf("\n");
	

	do 
    {
	choice=getch();
	if(choice == 0 )
	move=getch();
	switch(choice)
		{
		case 1:
			printf("Move shape:\n");
			printf("Please enter the translation value (x,y):");
			scanf("%d %d",&moveshape_x,&moveshape_y);
			newpoint1.x=point1.x+moveshape_x,newpoint1.y=point1.y+moveshape_y;
			newpoint2.x=point2.x+moveshape_x,newpoint2.y=point2.y+moveshape_y;
			newpoint3.x=point3.x+moveshape_x,newpoint3.y=point3.y+moveshape_y;
			//told(point1,point2,point3,0);
			//tnew(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 2:
			printf("Scaling:\n");
			printf("Please enter the Scaling value (x,y):");
			scanf("%f %f",&sizeshape_x,&sizeshape_y);
			newpoint1.x=(float)(point1.x*sizeshape_x),newpoint1.y=(float)(point1.y*sizeshape_y);
			newpoint2.x=(float)(point2.x*sizeshape_x),newpoint2.y=(float)(point2.y*sizeshape_y);
			newpoint3.x=(float)(point3.x*sizeshape_x),newpoint3.y=(float)(point3.y*sizeshape_y);
			//told(point1,point2,point3,0);
			//new_triangle(newpoint1,newpoint2,newpoint3,5,1);
			copyvalue();

		break;
		case 3:	
			printf("Rotation:\n");
			printf("please enter an angle to rotate your shape by\n");
		getch();
		printf("angle:\n");
		scanf("%d",&theta);
		getch();
		printf("press any key to continue\n");

		break;
		case 4:	
			printf("Instruxions:\n");
			getch();
			printf("Return to menu? (Y/N):\n");
			//scanf("%c",&key_select);

			break;
		case 5:	
			printf("bye bye!:\n");
			printf("Return to menu? (Y/N):\n");
			//scanf("%c",&key_select);
			getch();
		}
	
	}
	while(select!=13);
  #39  
Old 17-May-2007, 15:52
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road

Re: Linked Lists advice request


CPP / C++ / C Code:
while(select!=13);
right, I know this bit's wrong, and so I've changed it,
I solved the other errors by moving the array above the outtestxy menus;
and I'm getting this error again:
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(371) : error C2143: syntax error : missing ';' before 'type'
Error executing cl.exe.

shapeshifter.obj - 1 error(s), 0 warning(s)
It hangs it on this line (372):
CPP / C++ / C Code:
void display_line(struct triangle *Tptr)
  #40  
Old 17-May-2007, 16:25
promsan promsan is offline
Junior Member
 
Join Date: May 2007
Location: North of the rhubarb triangle, GB
Posts: 53
promsan is on a distinguished road

Re: Linked Lists advice request


got it.. I commented out the last bit of the main() function by accident
CPP / C++ / C Code:
    getch();
   
    return 0;
}
I now get these warnings, and a weird crash when I execute it:
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(303) : warning C4700: local variable 'x' used without having been initialized
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(304) : warning C4700: local variable 'size' used without having been initialized
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(304) : warning C4700: local variable 'y' used without having been initialized
Linking...

shapeshifter.exe - 0 error(s), 3 warning(s)

The crash seems to be caused by the "outtextxy" stuff - it don't like it much - any ideas why?
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
triangle (polygon), drawing, sizing, and rotation programme using linked lists... promsan C Programming Language 12 14-May-2007 15:03
Doubly linked lists in C++ sweeeeeeetlipss C++ Forum 1 24-Oct-2006 00:27
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
help on linked lists any1????? nick4 C Programming Language 1 17-May-2004 10:32
linked lists, newbie needs help moltarim C Programming Language 4 06-May-2004 12:32

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:52.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.