Archived

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

3D Movement

This topic is 6163 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

This may sound remarkably basic but I''m curious about moving object around in 3d space in a relative manner. For example. I have a model at location L and with an orientation vector of O. What kind of calculations do I perform to move ''forward'' X units. Moving ''forward'' is a term that specifies relative movement to an existing point. That movement must take the current orientation vector in to account to calculate the new spacial position. I can imagine that rotating like ''Turn Left X units'' would be pretty simple, ie just turn the ''left by'' in to a vector then add it to the current rotation vector. Many thanks for any help you can provide helping me understand the mathematics(code wise) invoved in making this work. Chris

Share this post


Link to post
Share on other sites
The simple way of moving forward along an orientation is like moving forward on a line (think 2d, back to middle school when you were learning about lines and slopes.)

To move forward on a line with slope 2/1 just involves moving 2 up for every 1 right. Or moving some factor of 2 up and that same factor of 1 right.

So moving to three dimensions, you have an object at (1,1,1) and an orientation of (.4,.6,0). The orientation is essentially the same as the slope in the 2d example. You simply move like this:
(1,1,1) + (.4, .6, 0) = (1+.4,1+.6,1+0) = (1.4, 1.6, 1). That''s your new position.

Basically you have just added your original position plus the orientation.

Now there are some more tricky aspects:
1) What happens if your orientation vector gets scaled up somehow? For example, (4, 6, 0)? Everytime you add the orientation, you are going to move a giant leap forward. So, we normalize the orientation vector -- in other words we make hte magnitude always equal to 1. That way, we always move the same amount.

2) How do we control the amount of movement? Well, you simply multiply the orientation vector by a scalar: 5 * (.4, .6, 0) will make your object move 5 times as much.


Easy, huh?

DmGoober

Share this post


Link to post
Share on other sites
(1,1,1) + (.4, .6, 0) = (1+.4,1+.6,1+0) = (1.4, 1.6, 1). That''s your new position.
+++++++++++++++++++++++++++++++++++++++++++

That didn''t seem right. Just having a direction seem to move your position. But it did get me thinking... Adding a unit vector pointing in the direction of your orientation represents moving in that by one unit, so I can, as you said scale that to get relative distances by multiplying the unit vector by the distance intended. To move 10 units forward in the current direction I just Add 10*CurrentOrientation to the position.

Is that right? Did I miss anything? This seems more simple that the 3D trig method I was considering.

Thanks (and let me know if I got it wrong)

Chris

Share this post


Link to post
Share on other sites