OK, I've put together a quick example.

http://swingpantsflash.com/roller_coaster/

I've demonstrated to myself that I'm on the right track. The upAxis
vector calculation seems to work for some of the time.

In the demo I've created a mock coaster track, and my cart is
travelling along it. I'm using the cart to represent the camera here
(for ease of visualisation) - if I can get the cart to perform
correctly I can apply that learning to the camera and everything
should be fine (the real idea is to have the camera following the cart
including with the rotating twists).

The problem is demonstrated by checking out how the cart rotates
around the track - use the arrow keys to affect a rotation. For 1/2
the track I'm able to twist around the track with no issues, the other
1/2 the rotation inverts.

What is the best way to fix this? I realise it is probably simple trig
inversion (but it is late my head hurts and any help will be greatly
received)

The source for the demo is here:
http://swingpantsflash.com/roller_coaster/CameraTest.as

The main frame update code:

                        //Calculate Sin/Cos for Cart rotational position
                        var rSin:Number = Math.sin(Math.PI * 2 * _rot)
                        var rCos:Number = Math.cos(Math.PI * 2 * _rot)

                        //Init rotational position for cart (Move a radius of 
10 away from
track position)
                        _matrix.identity()
                        _matrix.appendTranslation( 10*rSin, 10*rCos, 0)
                        //Calc track position
                        _vec = trackPosition(_count * 0.001, _trackRadius)
                        //Apply translation matrix to the vector
                        _vec = _matrix.transformVector(_vec)
                        //Position the cart
                        _actor.x = _vec.x
                        _actor.y = _vec.y
                        _actor.z = _vec.z

                        //Calc position in front to use as 'look at' vector ( 
using +2 as
nudged in front)
                        _vec = trackPosition((_count + 2) * 0.001, _trackRadius)
                        _scratchVec = _vec.clone()
                        //Transform the position vector
                        _vec = _matrix.transformVector(_vec)
                        //Create scratch vector for use as upAxis
                        _scratchVec.x = (_scratchVec.x - _vec.x)
                        _scratchVec.y = (_scratchVec.y - _vec.y)
                        _scratchVec.z = (_scratchVec.z - _vec.z)
                        //Look at the vector in front using the calced upAxis
                        _actor.lookAt(_vec, _scratchVec)

 This seems to work beautifully with a fair wind, but I need to make
it more robust. How do I make sure that I don't suffer from inverse
rotation?

Reply via email to