Sign in to follow this  
glmisscelan

OpenGL Rotating vector

Recommended Posts

hi, I have a direction vector(vDir). I have an origin point(vStart) and a end point (vEnd). I calculate vEnd: Code: vEnd.x = vStart.x + Radio * vDir.x; vEnd.y = vStart.y + Radio * vDir.y; vEnd.z = vStart.z + Radio * vDir.z; Now i wanted to rotate vDir by Y axis and calculate vEnd again. I make Y rotation: Code: vDir.x = (vDir.z * cos(ang_rad)) - (vDir.x * sin(ang_rad));//y vDir.z = (vDir.x * cos(ang_rad)) + (vDir.z * sin(ang_rad)); It doesnt work as i wanted, however if a make this, the rotation works perfect: Code: vEnd.x = Radio * vDir.x; vEnd.y = Radio * vDir.y; vEnd.z = Radio * vDir.z; glPushMatrix(); glTranslatef(vStart.x, vStart..y, vStart..z); glRotatef(angle, 0.0, 1.0, 0.0); glBegin(GL_LINES); glVertex3f(0, 0, 0); glVertex3f(vEnd.x, vEnd.y, vEnd.z); glEnd(); glPopMatrix(); Here what im doing is rotating the point, but if i rotate vEnd with no-opengl-code it doesnt work neither. Any body can help me? Thanks in advance _________________ -- http://www.mierdapatuboca.com --

Share this post


Link to post
Share on other sites
basic problem is that you use rotated x to compute z

>>vDir.x = (vDir.z * cos(ang_rad)) - (vDir.x * sin(ang_rad));//y
>>vDir.z = (vDir.x * cos(ang_rad)) + (vDir.z * sin(ang_rad));

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this