Rotating vector

Started by
0 comments, last by janci123 16 years, 10 months ago
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 --
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));

This topic is closed to new replies.

Advertisement