[DX9] Following 3d path

Started by
4 comments, last by Buckeye 13 years, 4 months ago
I created a 3D curve (e.g. a Viviani curve) and now I would like a simple 3D object to follow the curve and, at the same, change its orientation to face the curve direction.

Following the path is easy (just a translation matrix) but changing the orientation is more tricky.

I figured out that it will be a combination of rotations. I tried many methods but none of them seemed to work (D3DXMatrixRotationX/Y/Z, D3DXMatrixRotationAxis, etc.). At some point I think I hit the gimbal lock problem as the object went upside-down.

Is there any "good practice" of moving an object in the 3D space? If I have to use quaternions, no problem. I just need to know what options I have.

Advertisement
Quote:... at the same, change its orientation to face the curve direction

The curve direction (I assume you derive the tangent to the curve) is only one of three axes you must define to orient the object.

Actually, you only need to choose a second (probably orthogonal) axis to that direction. The third axis can be the cross-product of the direction and the second axis. You'll have to define a method to choose that second axis.

One possibility is to assume that all changes in direction are about an axis which is "right/left" to the object. That is, when there's a change in direction, calculate the cross-product of the new direction with the old and use that as your second axis. The third axis is the cross-product of the new direction and the second axis. That 3rd axis will be the object's new "up" direction.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I'll also recommend the 'parallel transport frame' as an effective means of orienting an object as it moves along a spline. (Search the forums for that term and you should find plenty of info.)
Thanks for your help, both of you.

Some comments:

Buckeye:
The method you've described is very similar to the "Fixed Up" method, isn't it? It also uses a direction vector, an "up" vector, and a "right" vector. It's definitely worth giving a try as it seems to be simple enough for quick implementation.

jyk:
I've read the chapter from "Game Programming Games 2" about 'parallel transport frame'. It is explained very clear and I think I'll try this method first. I also had a look at the forum posts.

Although nobody mentioned quaternions I think they could be combined with both techniques. For example in the 'parallel transport frame' method quaternions could be used to generate smooth rotations between the frames. The "Game Programming Games 2" book suggests that.

Thanks again.

The 'parallel transport frame' method works like a charm. I followed the directions from the "Game Programming Games 2" book and I did not find any major obstacles.

There is only one caveat. The books says to set the initial frame to an arbitrary frame calculated using the Fixed Up method or the Frenet Frame method. The problem is that I can't find a DirectX 9 method that would create a frame given three ortogonal axes:

Fixed Up method (V is an arbitrary vector):

D = T / |T|
R = DxV / |DxV|
U = RxD

We have three vectors that describe three axes: D - direction, R - right, and U - up. What method should I use to create a matrix given these three vectors?

For the time being, I calculated the initial frame using the 'parallel transport frame' method but it's a bit overkill.

Any suggestions?
I think this may be what you're looking for (I may be confused):

Given right (r), up (u) and foreward (f) vectors,
M =   | rx  ry  rz 0 |   | ux  uy  uz 0 |   | fx  fy  fz 0 |   |  0   0   0 1 |

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement