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
  #21  
Old 16-May-2007, 01:02
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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


Using the second program(?) you posted on page 1 of this yesterday I had taken this approach to designing a structure to hold the entire triangle as an object (that is I think it would be an object):
CPP / C++ / C Code:
/* promsan2_x4.c  */
#include <stdio.h>
#include <graphics.h>

struct triangle
{
  int T1x;
  int T1y;
  int T2x;
  int T2y;
  int T3x;
  int T3y;
  int colour;
} tangle;

struct triangle *Tptr;

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

int main(void)
{
  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.T1x, tangle.T1y, tangle.T2x, tangle.T2y, tangle.T3x, tangle.T3y, tangle.T1x, tangle.T1y,  tangle.colour);

  display_line(Tptr);

  getch();

  return 0;
}

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

void display_line(struct triangle *Tptr)
{
  initwindow(600, 400);
  setcolor(Tptr->colour);
  line(Tptr->T1x, Tptr->T1y, Tptr->T2x, Tptr->T2y);
  line(Tptr->T2x, Tptr->T2y, Tptr->T3x, Tptr->T3y);
  line(Tptr->T3x, Tptr->T3y, Tptr->T1x, Tptr->T1y);

  /* 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       T1x: ");
  scanf ("%d", &Tptr->T1x);
  printf("       T1y: ");
  scanf ("%d", &Tptr->T1y);
  printf("       T2x: ");
  scanf ("%d", &Tptr->T2x);
  printf("       T2y: ");
  scanf ("%d", &Tptr->T2y);
  printf("       T3x: ");
  scanf ("%d", &Tptr->T3x);
  printf("       T3y: ");
  scanf ("%d", &Tptr->T3y);
  printf("and colour: ");
  scanf ("%d", &Tptr->colour);
  printf("%d, %d, %d, %d, %d, %d, %d <-and there they are. \n", Tptr->T1x, Tptr->T1y, Tptr->T2x, Tptr->T2y, Tptr->T3x, Tptr->T3y, Tptr->colour);
}
/*
If using \cs1300 crank it up with:
C:\cs1300\gocs

compile with:
g++ promsan2_x4.c -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -o promsan2_x4.exe

or alternate method:
bgi++ promsan2_x4.c -o promsan2_x4.exe
   (automatically loads libraries needed)
*/
That compiles and runs ok for me.
I see your now getting different user input,, so then just calculate the x and y of the points.

The main thing is , you can just refer to those six values defining the three points of the triangle and manipulate all six any way you want. For example a function could be made to loop through them all with the adjustment for your rotation.

Glad to see your making some headway. Take it slow and compile/run often as you go. Handle mistakes as soon as possible instead of 50 lines down the road !! Hi to the queen for us,
Howard;
  #22  
Old 16-May-2007, 01:13
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


Wow! That's impressive... thanks for putting so much effort in!

At the moment I'm trying to translate the user input for centre point coordinates and size to be used by the prog to draw lines:

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 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 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>

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

int main()
{

	/* DECLARE VARIABLES */
	int x;
	int y;
	int size;
 //int start_x;
 //int start_y;
 //int end_x;
 //int end_y;
 int radius;
   
	shape_type st;
    line_type lt;

	line_type line;
 //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);

 /* Converting User input into shape variables */
	 start_x = x;
	 start_y = y+(size/2);
	 end_x = x;
	 end_y = y-(size/2);

	/* 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 = 300;
	lt.start_y = 300;
	lt.end_x = 360;
	lt.end_y = 360;
	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);


    
    return 0;
}

this bit (lines 65-68 inclusive):
CPP / C++ / C Code:
 /* Converting User input into shape variables */
	 start_x = x;
	 start_y = y+(size/2);
	 end_x = x;
	 end_y = y-(size/2);
, results in the following errors:
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(65) : error C2065: 'start_x' : undeclared identifier
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(66) : error C2065: 'start_y' : undeclared identifier
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(67) : error C2065: 'end_x' : undeclared identifier
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(6 : error C2065: 'end_y' : undeclared identifier
Error executing cl.exe.

shapeshifter.obj - 4 error(s), 0 warning(s)
  #23  
Old 16-May-2007, 01:16
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


D'oh

(fixed it -> you don't need to tell me!)

; )
  #24  
Old 16-May-2007, 01: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


I've put in your Triangle thing:

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 T1x;
  int T1y;
  int T2x;
  int T2y;
  int T3x;
  int T3y;
  int colour;
} tangle;



struct triangle *Tptr;

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

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

int main()
{

	/* DECLARE VARIABLES */
	int x;
	int y;
	int size;

	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.T1x, tangle.T1y, tangle.T2x, tangle.T2y, tangle.T3x, tangle.T3y, tangle.T1x, tangle.T1y,  tangle.colour);

	display_line(Tptr);

	getch();
    
    return 0;
}

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

void display_line(struct triangle *Tptr)
{
  initwindow(600, 400);
  setcolor(Tptr->colour);
  line(Tptr->T1x, Tptr->T1y, Tptr->T2x, Tptr->T2y);
  line(Tptr->T2x, Tptr->T2y, Tptr->T3x, Tptr->T3y);
  line(Tptr->T3x, Tptr->T3y, Tptr->T1x, Tptr->T1y);

  /* 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       T1x: ");
  scanf ("%d", &Tptr->T1x);
  printf("       T1y: ");
  scanf ("%d", &Tptr->T1y);
  printf("       T2x: ");
  scanf ("%d", &Tptr->T2x);
  printf("       T2y: ");
  scanf ("%d", &Tptr->T2y);
  printf("       T3x: ");
  scanf ("%d", &Tptr->T3x);
  printf("       T3y: ");
  scanf ("%d", &Tptr->T3y);
  printf("and colour: ");
  scanf ("%d", &Tptr->colour);
  printf("%d, %d, %d, %d, %d, %d, %d <-and there they are. \n", Tptr->T1x, Tptr->T1y, Tptr->T2x, Tptr->T2y, Tptr->T3x, Tptr->T3y, Tptr->colour);
}
/*
With help from HowardL
[url]http://www.gidforums.com/showthread.php?p=59711&posted=1#post59711[/url]

If using \cs1300 crank it up with:
C:\cs1300\gocs

compile with:
g++ promsan2_x4.c -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -o promsan2_x4.exe

or alternate method:
bgi++ promsan2_x4.c -o promsan2_x4.exe
   (automatically loads libraries needed)
*/

...and I'm getting the following errors that I can't seem to shake:
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Linking...
shapeshifter.obj : error LNK2001: unresolved external symbol _line
shapeshifter.obj : error LNK2001: unresolved external symbol _setcolor
shapeshifter.obj : error LNK2001: unresolved external symbol _initwindow
Debug/shapeshifter.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

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

  #25  
Old 16-May-2007, 01:54
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


I don't really understand what you've put at the end after the functions, but it seems related to the errors
  #26  
Old 16-May-2007, 06:54
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


Well, it worked on other computers and it's very nice... but I need to change it so that the user doesn't enter co-ords for each vertex (it's for little kiddies).

So I'm looking at using a rotation matrix and doing some normalising of coords
for the rotation (calc of relativ new coords); and then the poxy size adjust anim.
...lots of switches to tap in this aft too.

CPP / C++ / C Code:
       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);
	 
	x_temp= normalize(tangle.T1x);

  //{	x_temp=x-central_x;
	//	y_temp=y-origin_x;}
//	} need to calc vertex coords as relative to screen not relative to centre point


	y_temp= normalize(point1.T1y);


  // nor


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

     tangle.T1x=(((point1.T1x*cos_value )-(point1.T1y*sin_value)));
     tangle.T1y=(((point1.T1y*cos_value )+(point1.T1x*sin_value)));

     tangle.T2x=(((point2.T2x*cos_value )-(point2.T2y*sin_value)));
     tangle.T2y=(((point2.T2y*cos_value)+(point2.T2x*sin_value)));


     tangle.T3x=(((point3.T3x*cos_value )-(point3.T3y*sin_value)));
     tangle.T3y=(((point3.T3y*cos_value)+(point3.T3x*sin_value )));
     told(point1,point2,point3,0);
     new_triangle(shape_type,3,1);
     copyvalue();
     //[source " http://lavluda.x10hosting.com/download/2d.doc"]


   need to "normalise" T1x etc by creating a new temp variable called T1xt
 */ 
  #27  
Old 16-May-2007, 08:43
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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:
I don't really understand what you've put at the end after the functions
Oh, that's my compiling instructions to myself.
It refers to the gnu gcc/ g++ compiler that I am using which I found here:
'http://www.cs.colorado.edu/~main/cs1300/doc/bgi/bgi.html'

It shouldn't effect things IF it is still commented out. These errors:
Quote:
Linking...
shapeshifter.obj : error LNK2001: unresolved external symbol _line
shapeshifter.obj : error LNK2001: unresolved external symbol _setcolor
shapeshifter.obj : error LNK2001: unresolved external symbol _initwindow
Debug/shapeshifter.exe : fatal error LNK1120: 3 unresolved externals
...seem like from graphics_lib.h not being found or implimented correctly.
Hence those functions: line, setcolor and initwindow are not being found.

Are you compiling the same way you did when you were drawing a line successfully?
I see that in the header you are using this:
#include "graphics_lib.h"

Keep in mind that you must then have that file, "graphics_lib.h" , in your
pwd (present working directory (the same directory as the .c file))
...as opposed to using like this:
#include <graphics_lib.h>

...where you compiler will look for it automatically in the compilers "includes" directory.
At least that's been my experience so far.

Howard;
PS: you DO realize that this SECOND thread is now about to go to 4 pages...
Try to refrain from sending gobs of non-pertinent info.
  #28  
Old 16-May-2007, 14:28
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


Quote:
Don't you have web space on the campus computer?
never set it up or used it, the point is I don't know how to post it on a site neatly, other than here with its simple tags..

Although I get 0 errors or warnings on compiling, I get the same 4 errors mentioned above when I go to build .exe:
Same compiler... I posted that GIF to show that I had the "graphics_lib.h" in the same file as the .c file.

When I changed the #include to
CPP / C++ / C Code:
#include <graphics_lib.h>
I only got one error:
Quote:
--------------------Configuration: shapeshifter - Win32 Debug--------------------
Compiling...
shapeshifter.c
C:\Documents and Settings\...\shapeshifter\shapeshifter\shapeshifte r.c(27) : fatal error C1083: Cannot open include file: 'graphics_lib.h': No such file or directory
Error executing cl.exe.
shapeshifter.exe - 1 error(s), 0 warning(s)
Which I understand (I don't this would flag as an error on the campus machines).
I've put the "graphics_lib.h" file in every bloody folder there is in my c programming folders... I mean it is where its supposed to be as far as I can tell.
  #29  
Old 16-May-2007, 15:36
shalombi shalombi is offline
Junior Member
 
Join Date: Feb 2007
Posts: 47
shalombi is on a distinguished road

Re: Linked Lists advice request


A stupid question but what about permissions on the file, I've had such problems before .

max
  #30  
Old 16-May-2007, 16:41
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
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


Permissions? -no he's using XP I believe.

OK ,
So your first run was finding the graphics_lib.h then. This second is definitely not.
There should be a companion .cpp or .a file that goes along with it.
On mine it's libbgi.a and I put it in the compilers lib directory.
I was getting linking errors similar to yours when that second file was not in place.
I don't know exactly how that gets used, but it's essential.
They both came with the cs1300 I am using for this I downloaded from the colorado.edu site I mentioned above.

- What compiler is it that both your university and laptop are using?
- Did you get your laptop's graphics_lib.h from the university or out on the web somewhere.

See if there is some info at your university about the winbgi installation they are using. Try to match it on your laptop.

If all else fails, download the cs1033 gcc for win32 setup from the above site above. 30mb but I'm liking having gcc in windows!
Good luck, gotta go,
Howard;
 
 

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 14:05.


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