Jump to content
  • Advertisement
Sign in to follow this  
glmisscelan

OpenGL Rotating vector

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!