From: joshuahab AT aol DOT com (Joshua Hab) Newsgroups: comp.os.msdos.djgpp Subject: Newbie seeks help with rotating triangle program Date: 15 Oct 1997 04:11:16 GMT Lines: 108 Message-ID: <19971015041101.AAA17302@ladder01.news.aol.com> NNTP-Posting-Host: ladder01.news.aol.com Organization: AOL http://www.aol.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi everyone, I'm relatively new to programming and very new to DJGPP, and I was wondering if some kind soul(s) would help me with a program I'm writing that rotates a triangle (just an outline though) around the center of the screen (also the triangle's center) The problem I'm having is that the function I wrote to determine the x and y values of the vertices is returning a value of 210 for x and 100 for y no matter what I put into them. The formula I'm using is as follows: (RADIUS_LENGTH is the radius of the circumscribed circle and CENTER_X is the center of it) x=(RADIUS_LENGTH*(cos(theta/360*6.28)))+CENTER_X ^^^^^^^^^^^^^^ this converts the degree based 'theta' to radians (this is derived from the polar equation x=r cos theta) and likewise: y=(RADIUS_LENGTH*(sin(theta/360*6.28)))+CENTER_Y (derived from y=r sin theta) So anyway, here is my source code. Any comments regarding programming style would be greatly appreciated, as I am very new and have only a vague definition of what is good and what is not good. _________________________________ #include #include #include #include #define CENTER_X 160 #define CENTER_Y 100 #define RADIUS_LENGTH 50 void main() { int x1, x2, x3, y1, y2, y3; //x and y coordinates for the 3 points of a triangle int theta1=90, theta2=210, theta3=330; //rotation in degrees PALETTE palette; allegro_init(); set_gfx_mode(GFX_VGA, 320, 200, 0, 0); install_keyboard(); palette[20].g=63; //I want the triangle to be green palette[20].r=0; palette[20].b=0; set_palette(palette); clear(screen); do { x1=calculate_x(theta1); //calculate the x coordinate based x2=calculate_x(theta2); //on the rotation or theta value x3=calculate_x(theta3); y1=calculate_y(theta1); //likewise with y y2=calculate_y(theta2); y3=calculate_y(theta3); draw_triangle(x1, x2, x3, y1, y2, y3); //draw the triangle outline with //our newly discovered points theta1=theta1+5; //increment the theta values, rotating the figure theta2=theta2+5; theta3=theta3+5; } while ((readkey() & 0xFF) != 27); //exit if "ESC" detected allegro_exit(); return; } calculate_x(theta) int theta; { int x=0; x=(50*(cos(theta/360*6.28)))+160; //our equation for determining x return(x); } calculate_y(theta) int theta; { int y=0; y=100-(50*(sin(theta/360*6.28))); //our equation for determining y return(y); } draw_triangle(x1, x2, x3, y1, y2, y3) int x1, x2, x3, y1, y2, y3; { line(screen, x1, y1, x2, y2, 20); //draw 3 lines, connecting the 3 vertices line(screen, x2, y2, x3, y3, 20); //in color 20, previously defined as line(screen, x3, y3, x1, y1, 20); //green return; }