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


Various 3D Programming Questions

Recommended Posts

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.) 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=-

Share this post

Link to post
Share on other sites
1) Most objects have three vectors to describe their orientation:
forward (or look at), up, and center. (these are not the commonly used names but. . .)
Imagine that the object that you are dealing with is a camera.
Forward is basically what you are looking at. Forward forms a vector from center (ie if center is 1,1,1 and forward is 1,1,2 then the camera is looking straight down the z axis, with an orientation of 0,0,1). Up forms a vector up from center.
Now, when you rotate the object rotate ALL of the points using the same transforms. Then, simply subtract forward from center, which will give you a direction vector, which we will call x.
If x started all of these calculations normalized, then it will still be normalized after doing the rotations (if you did them right.) Simply multiply x by a scalar and add that value to all three vectors (forward, center, and up) in order to move the camera forward by a normalized amount.

vect3 up, center, forward; //assume values are assigned.
vect3 x;
up = rotationMat * up;
center = rotationMat * camera;
forward = rotationMat * forward;
x = forward - camera;
float s = ; //assign any value
up += s * x;
center += s*x;
forward += s*x;

Up is technically not required for this example. However, having an up vector allows you to roll the camera.

2) order of matrices all depends on frame of reference. if you are rotating around something in a local frame of reference, do all local stuff first. . . i''ll let someone else answer this one, cause i don''t think i''ll be able to explain it well.

3) see above.
4) you''re welcome!

Share this post

Link to post
Share on other sites