Archived

This topic is now archived and is closed to further replies.

This topic is 6820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

ha! this isn''t about 3D graphics. my other post wasn''t getting any attention , even though it was a problem all you hard-core programmers could solve in 3 nano seconds. here it is; its not hard (well, to me it is). i am working on my polygon engine, and for some reason there is a delema. i have a function that rotates a polygon, but however, whenever i pass the function a positive angle, the polygon rotates the polygon clock-wise, and vise versa, which is wrong. i know i can easily get around it by negating the angle, but it''s still bothering me. heres the code (BTW, i have look-up tables for the sin and cos functions for optimization, and i''m SURE they work): int Rotate_Polygon(POLYGON_PTR poly, int angle) { int index; if (poly->side == NULL) { return(-1); } if (angle < 0) { angle += 360; } for (index = 0; index < poly->num_sides; index++) { float xr = (float)poly->side[index].x1*cos_look[angle] - (float)poly->side[index].y1*sin_look[angle]; float x2r = (float)poly->side[index].x2*cos_look[angle] - (float)poly->side[index].y2*sin_look[angle]; float yr = (float)poly->side[index].x1*sin_look[angle] + (float)poly->side[index].y1*cos_look[angle]; float y2r = (float)poly->side[index].x2*sin_look[angle] + (float)poly->side[index].y2*cos_look[angle]; float cx = (float)poly->side[index].Cen_X*cos_look[angle] - (float)poly->side[index].Cen_Y*sin_look[angle]; float cy = (float)poly->side[index].Cen_X*sin_look[angle] + (float)poly->side[index].Cen_Y*cos_look[angle]; poly->side[index].x1 = xr; poly->side[index].y1 = yr; poly->side[index].x2 = x2r; poly->side[index].y2 = y2r; poly->side[index].Cen_X = cx; poly->side[index].Cen_Y = cy; } return(1); }

Share on other sites
I could be going mad, but it looks like you have a left handed matrix transformation going on, and you need a right handed one.

Share on other sites
This is the rotation formula:
xr = x cos a - y sin ayr = x sin a + y cos a

From what I can see this is exactly what you are using. What you are missing is that the computer screen has the origo at the top-left corner, as opposed to your normal cartesian system that has it in the bottom left corner.

Edited by - Spellbound on 3/13/00 4:34:55 PM

Share on other sites
unfortunatly, im no trig genius. all i know is that the formula works. when i was programming in DOS in Mode X 320x240, i used the exact same code and it worked.

however, i understand what you mean. so how do i fix it? switch sin and cos? switch signs? both?

Share on other sites
If I remember it correctly it should be enough to transpose the transform matrix. Or as in the case with separate formulas:

xr = x cos a + y sin a
yr = -x sin a + y cos a

I''m not sure though. Try it, if it wasn''t correct then ask again.

Share on other sites
Just negate all the sin terms to convert between rt-handed and lt-handed systems. This is exactly the same as simply negating the angle. This is why:

sin(-x) == -sin(x)
cos(-x) == cos(x)

Share on other sites
thats what ive been doing to solve the problem. i just wasn''t sure if that was the most "professional" way to do it.

Share on other sites
If it works and is fast, it''s profressional. (Actually, in my experience if it works most of the time and is somewhat fast then it is professional. I''m not bitter, oh, no of course not.)

Wraith

Share on other sites
In my opinion, the professional way is to understand what goes on.

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 9
• 20
• 20
• 14
• 14
• Forum Statistics

• Total Topics
633383
• Total Posts
3011583
• Who's Online (See full list)

There are no registered users currently online

×