Archived

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

Pontius

Pointing objects in a direction

Recommended Posts

I am making a very primitive flight simulator. I have a set of points that my plane (a teapot for now) flies to on autopilot. I have got the movement down, going from point to point, but what i need is for the teapot to point in the direction of the next point it''s traveling to. In terms of X and Y, I can get it to do this. but I can''t figure it out for Z. Sometimes it works, sometimes it points in the wrong dir. I was wondering if there are any tutorials that demonstrate pointing an object in a certain direction? Let me know, thanks Pontius

Share this post


Link to post
Share on other sites
i dont know the functions since i haven''t begun to learn opengl yet, but for rotation (which you say you have working) you can just find the angle between the two points, or just point it at the second point (like i said, i don''t know the functions so i don''t know what''s easier)

for pitch you would think of it like a right triangle...

/| destination z
/ |
/ |
current z /a__|

then just find the angle of "a" and use that to point the plane...

it would be like....

angle = arctan((destination_z-current_z)/sqrt((destination_x-currentx)^2+(destination_y-currenty)^2))

(psuedo code because, again, i haven''t got into C++ or OpenGL programming much, I just know the concepts and the math.





Share this post


Link to post
Share on other sites
zRotationAngle = atan2(yTargetLocation - yCurrentLocation, xTargetLocation - xCurrentLocation);
xRotationAngle = atan2(yTargetLocation - yCurrentLocation, zTargetLocation - zCurrentLocation);
yRotationAngle = atan2(zTargetLocation - zCurrentLocation, xTargetLocation - xCurrentLocation);

zRotationAngle /= (3.1415926535897932 / 180);
xRotationAngle /= (3.1415926535897932 / 180);
yRotationAngle /= (3.1415926535897932 / 180);

If I remember right you rotate by the negative of those values... not sure, try it.

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

Share this post


Link to post
Share on other sites
quote:
Original post by LockePick
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."


Let me guess - Yes, Prime Minister ?

Crispy

Share this post


Link to post
Share on other sites
quote:
Original post by Crispy


Let me guess - Yes, Prime Minister ?




either that or it's an ARB meeting discussing the high level shading language for GL 2.0 ;¬)



[edited by - mrbastard on December 25, 2002 5:06:12 PM]

Share this post


Link to post
Share on other sites