# [DX9] Following 3d path

This topic is 2782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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.)

##### Share on other sites
Thanks for your help, both of you.

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.

##### Share on other sites
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?

##### Share on other sites
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 |

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631710
• Total Posts
3001845
×