aircraft rotation
by Henry Shilling · in Torque X 3D · 06/06/2010 (10:32 am) · 7 replies
I am trying to make an aircraft "fly" in a realistic or some semblance of realistic manner. Moving the stick left/right should roll the aircraft. This all works great while the aircraft is parallel with the horizon, however if I pitch up or down the roll is not longer a roll. At 90degrees perpendicular the roll becomes a spin. I guess I need to know how to roll the T3DObject in it's own space not the scene. Here is what I am doing
As you can see I tried using the SceneGroup and the objects SceneComponent, the results are the same.
float rotX = move.Sticks[0].X; rotX = (float)Math.Pow(Math.Abs(rotX), Math.E) * (rotX > 0.0f ? -1.0f : 1.0f); float rotY = _invertedCamera ? -move.Sticks[0].Y : move.Sticks[0].Y; rotY = (float)Math.Pow(Math.Abs(rotY), Math.E) * (rotY > 0.0f ? 1.0f : -1.0f); _playerRollAngle = (_playerRollAngle - (_turnSpeed * dt * rotX)) % (2.0f * (float)Math.PI); _playerPitchAngle = (_playerPitchAngle - (_turnSpeed * dt * rotY)) % (2.0f * (float)Math.PI); //SceneGroup.Rotation = Quaternion.CreateFromYawPitchRoll(_playerRollAngle, _playerPitchAngle, 0.0f); _playerSceneComponent.Rotation = Quaternion.CreateFromYawPitchRoll(_playerRollAngle, _playerPitchAngle, 0.0f);
As you can see I tried using the SceneGroup and the objects SceneComponent, the results are the same.
About the author
http://twitter.com/theBigDaddio
#2
06/08/2010 (2:05 pm)
Very Nice, I am jealous! This video sure is making torque x 3D look appealing.
#3
06/08/2010 (7:12 pm)
Oh wow, This is great Henry. Do you have any good links for flying physics information, I plan to have flying in a RC game i'm currently working on, I got the car's working will be starting the flying soon.
#4
One of the real bummers is the particle effects on the wing tips really eat up the frame rate. This is recorded on my PC, on the xbox I get around 55 fps, without the particles I get over 100 fps.
06/08/2010 (8:41 pm)
There are no "real" flying physics involved. Basically I don't use gravity. I was looking into doing some sort of gravity physics thing, we'll see.One of the real bummers is the particle effects on the wing tips really eat up the frame rate. This is recorded on my PC, on the xbox I get around 55 fps, without the particles I get over 100 fps.
#5
You are also correct in that XNA coords are not the same as Torque. Torque uses Z Up, XNA uses Z backwards, which is different to DirectX which uses Z Forwards. That is the biggest travesty imho, and I've said it to Shawn before but he disagrees with me. It makes coding for XNA painful, you can't just take your code straight from DirectX, which XNA interfaces with!
06/09/2010 (4:37 pm)
Quaternions are far more efficient that matrices, in that they store a rotation around an abitrary axis in 4 floats rather than 16. You are also correct in that XNA coords are not the same as Torque. Torque uses Z Up, XNA uses Z backwards, which is different to DirectX which uses Z Forwards. That is the biggest travesty imho, and I've said it to Shawn before but he disagrees with me. It makes coding for XNA painful, you can't just take your code straight from DirectX, which XNA interfaces with!
#6
Like Trent said quats are way more efficient, faster and they solve the gimbal lock problem when using matrices for rotations.
06/09/2010 (4:55 pm)
I agree about the Z up, it just doesn't follow the norm, and is very painful, especially with regards to dx and xna. Most people don't think that way. Like Trent said quats are way more efficient, faster and they solve the gimbal lock problem when using matrices for rotations.
Torque 3D Owner Henry Shilling
Smokin Skull
float _roll = move.Sticks[0].X; float _pitch = _invertedCamera ? -move.Sticks[0].Y : move.Sticks[0].Y; _roll = (float)Math.Pow(Math.Abs(_roll), Math.E) * (_roll > 0.0f ? -1.0f : 1.0f); _pitch = (float)Math.Pow(Math.Abs(_pitch), Math.E) * (_pitch > 0.0f ? -1.0f : 1.0f); _roll *= _turnSpeed * dt; _pitch *= _turnSpeed * dt; Quaternion _rot = Quaternion.CreateFromAxisAngle(Vector3.Right, _pitch) * Quaternion.CreateFromAxisAngle(Vector3.Up, _roll) * Quaternion.CreateFromAxisAngle(Vector3.Backward, 0); SceneGroup.Rotation *= _rot;I do not understand what all those Quaternions are, I kind of get it, but not really. This also shows that the TX3D coords are not the same as the XNA coords. Who made that decision?
I'll have to post a video of the results
Nothing like answering my own questions ;)