Various 3D Programming Questions

Started by
1 comment, last by Foible 23 years, 2 months ago
Thanks for your help in advance, here's my questions: 1) How do I find the distance to move an object on diagonals in 3D? Like so it doesn't move at different speeds going diagonal as going parallel to an axis... Like in 2D I do X += speed*(cos(angle)), Y += speed*(sin(angle)) where angle is the angle the object is traveling and speed is the speed it is going. I don't know if thats the right way but thats how I do it. Anyway is there something like that I can do in 3D? I was thinking of having a normalized (think thats the right word) vector for the way it is traveling and just rotate it the same way the object rotates then add the vector's x,y,z to the object's (after multiplying by speed)? 2) I know that the order matters in rotating objects in 3D (like x first then y then z isnt the same as y then x then z, etc.)....so how do I take care of that? Like what order is the right one? 3) I remember reading something about having 3 different vectors to describe the direction an object is traveling (up, right, and forward I think). I think I understand why, I think it has something to do with my previous question..but how do I implement this? Like...I don't know I'm just confused about it. 4)Thanks! (oh if it matters I'm using OpenGL) -=Foible=- Edited by - Foible on January 31, 2001 5:30:02 PM
-=Foible=-
Advertisement
2) Remember, in 3D, not only do you perfrom operations on an object, but also on that object''s axis. In order to figure out what tramsformation order is correct, you need to first identify what you want. Then you can determine what effect the order will have on the local axis that will affect future operations.
The reason for using up, forward and right vectors is to represent the orientation of the object. You still need a point to represent the position of the object, and probably another vector to represent the velocity .

In fact, you only need two of up, forward and right - the third is the cross-product of the other two. One, however, isn''t enough - if, for example, you just have the up vector you still don''t know which direction the object is facing.

The velocity vector is indeed a normalized direction vector multiplied by the speed of the object. I don''t know which is easier to store. To calculate the new position of the object you need to scale the velocity vector by the time between frames, and then add the resulting vector to the position of the object.

You can still use the speed*cos(angle) and speed*sin(angle) method if you prefer that to the velocity method, but it''s computationally more expensive, so I''ve not seen it done. The difference is that you need two angles to specify the direction in 3D.

HTH!

This topic is closed to new replies.

Advertisement