|
Quarry
|
 |
« on: October 27, 2012, 11:35:12 AM » |
|
Can anyone help me with the equations for plane-like movement with only pitch, roll and speed?
|
|
|
|
|
Logged
|
|
|
|
|
rivon
|
 |
« Reply #1 on: October 27, 2012, 01:24:53 PM » |
|
Could you be more specific? Plane physics is quite a lot of things...
|
|
|
|
|
Logged
|
|
|
|
|
Quarry
|
 |
« Reply #2 on: October 27, 2012, 01:28:46 PM » |
|
I have a 3D position vector (x, y and z, y being vertical), a speed value, a pitch value and a roll value.
How do I know where the object (plane, spaceship, helicopter) will be when the next physics update is triggered? Consider it to be a spaceship as there's no form of gravity affecting the object.
|
|
|
|
« Last Edit: October 28, 2012, 03:18:38 AM by Quarry »
|
Logged
|
|
|
|
|
randomnine
|
 |
« Reply #3 on: October 27, 2012, 03:36:58 PM » |
|
Assuming that: - +z is forward
- +x is right
- yaw is clockwise around +y (0 is forward, 90 is right)
- pitch is anti-clockwise around +x (0 is forward, 90 is up)
then: forward.x = sin( yaw ) * cos( pitch ) forward.y = sin( pitch ) forward.z = cos( yaw ) * cos( pitch ) "forward" is now a unit length vector pointing in the direction of travel, so: position = position + forward * speed * delta_time
|
|
|
|
|
Logged
|
|
|
|
|
ThemsAllTook
|
 |
« Reply #4 on: October 27, 2012, 04:41:57 PM » |
|
I'd use a quaternion for the spaceship's orientation, then multiply some vector you define to be "forward" in the identity orientation by the quaternion and the speed scalar. Simple enough. If you're not familiar with quaternions, I happen to have written a tutorial on them.
|
|
|
|
|
Logged
|
|
|
|
|
Quarry
|
 |
« Reply #5 on: October 28, 2012, 02:39:03 AM » |
|
Assuming that: - +z is forward
- +x is right
- yaw is clockwise around +y (0 is forward, 90 is right)
- pitch is anti-clockwise around +x (0 is forward, 90 is up)
then: forward.x = sin( yaw ) * cos( pitch ) forward.y = sin( pitch ) forward.z = cos( yaw ) * cos( pitch ) "forward" is now a unit length vector pointing in the direction of travel, so: position = position + forward * speed * delta_time I didn't ask for yaw, I asked for roll, roll
|
|
|
|
|
Logged
|
|
|
|
|
BorisTheBrave
|
 |
« Reply #6 on: October 28, 2012, 03:17:47 AM » |
|
I didn't ask for yaw, I asked for roll, roll
I have a 3D position vector (x, y and z, y being vertical), a speed value, a pitch value and a yaw value.
You should be more careful what you wish for. Your roll has no effect on your position given the figures above, you just determine the forward vector as given, and then use that to update the position just like randomnnine said. The roll only affects what the new velocity and rotation will be, based on the lift of the plane wing. The position is the easy part - generally one needs to know the new velocity and rotation, too. The full formulas are involved, as planes have various flaps that they use to control their rotations. But assuming you don't care about that, the main part is just making sure you apply the lift force in the right direction and magnitude, which this post should help you do. But even for that, you are better off learning quaternions than using yaw-pitch-roll. Otherwise, you will need dozens of formulas involving random cos and sin calls, and it will probably break when you pitch to 90 degrees. Even if you start with yaw-pitch-roll, it is literally going to be easier to work with quaternions and convert back afterwards.
|
|
|
|
|
Logged
|
|
|
|
|
Quarry
|
 |
« Reply #7 on: October 28, 2012, 03:30:30 AM » |
|
How did Elite manage to do all those equations to move in space?
|
|
|
|
|
Logged
|
|
|
|
|
BorisTheBrave
|
 |
« Reply #8 on: October 28, 2012, 04:10:17 AM » |
|
Spaceships do not behave the same as planes - they have no lift (wings moving through air) or air resistance, instead they have thrust (rockets pointing in a given direction). The formulas are quite different, rockets are a bit simpler (but still going to require quaternions).
|
|
|
|
|
Logged
|
|
|
|
|
Quarry
|
 |
« Reply #9 on: October 28, 2012, 04:12:40 AM » |
|
Consider it to be a spaceship as there's no form of gravity affecting the object. I already said what kind of equations I'll be needing and for what, I don't think that I can explain what I want further. I also don't think that I'll be able to study quaternions with the scarce amount of time I have
|
|
|
|
|
Logged
|
|
|
|
|
randomnine
|
 |
« Reply #10 on: October 28, 2012, 04:41:18 AM » |
|
How are you modelling orientation with just pitch and roll?
You don't have to understand quaternions to use them, btw, just grab an existing quaternion library or copy the math. The essential functions you'll need will be:
- applying rotations around arbitrary axes to turn the ship, by converting them to quaternions and adding them - converting the quaternion to an orientation matrix for rendering, physics and other calculations (such as finding the axes around which to rotate for the above)
|
|
|
|
|
Logged
|
|
|
|
|
Eigen
|
 |
« Reply #11 on: October 28, 2012, 04:47:15 AM » |
|
Without quaternions I believe you will eventually run into Gimbal lock.
|
|
|
|
|
Logged
|
|
|
|
|
st33d
Guest
|
 |
« Reply #12 on: October 28, 2012, 05:09:59 AM » |
|
I will also say suck it up, quarternions.
The reason you're going to have to go with them in the end is because of rendering. Painful bit now, smooth ride later on.
|
|
|
|
|
Logged
|
|
|
|
|
moi
|
 |
« Reply #13 on: October 28, 2012, 05:51:55 AM » |
|
I wonder if you still run into the gimbal lock problem if you: 1-restrain yourself to two axis of rotation 2-zero everything out on each frame before reapplying the new rotations in the correct order I run into gimbal lock problems for one of my projects and I just wouldn't care enough for bothering with quaternions
|
|
|
|
|
Logged
|
subsystems subsystems subsystems
|
|
|
|
BorisTheBrave
|
 |
« Reply #14 on: October 28, 2012, 05:55:28 AM » |
|
iirc elite style games have no defined sense of up/down, so you will run into gimbal lock fairly frequently.
|
|
|
|
|
Logged
|
|
|
|
|
Xienen
|
 |
« Reply #15 on: October 28, 2012, 07:27:59 AM » |
|
I don't believe you ever run into Gimbal Lock if you are continuously recalculating the final matrix from yaw, pitch, and roll values. Gimbal Lock, if I understand it correctly, only comes into play when using a matrix as the main storage and updating rotations from there.
|
|
|
|
|
Logged
|
|
|
|
|
ThemsAllTook
|
 |
« Reply #16 on: October 28, 2012, 10:14:42 AM » |
|
I don't believe you ever run into Gimbal Lock if you are continuously recalculating the final matrix from yaw, pitch, and roll values. Gimbal Lock, if I understand it correctly, only comes into play when using a matrix as the main storage and updating rotations from there.
Nope - gimbal lock results from using euler angles, which is what storing pitch, yaw, and roll as separate scalar values would give you. Storing your rotation as a quaternion or a matrix doesn't inherently solve the problem if you're still rotating them on each axis separately. However, without matrices or a quaternions, doing any kind of rotation other than euler angles is wayyyyy harder than it needs to be.
|
|
|
|
|
Logged
|
|
|
|
|
powly
|
 |
« Reply #17 on: October 28, 2012, 10:27:52 AM » |
|
Gimbal lock is largely dependent on how large steps your angles take. If you only do a few degrees each frame, it probably isn't a problem.
|
|
|
|
|
Logged
|
|
|
|
Cheezmeister
Level 1
|
 |
« Reply #18 on: October 28, 2012, 12:08:55 PM » |
|
That's a pretty solid guide, nice job!
|
|
|
|
|
Logged
|
|
|
|
|
Evan Balster
|
 |
« Reply #19 on: October 29, 2012, 12:35:09 PM » |
|
+1 on quaternions. The phenomenon of gimbal lock occurs when a set of euler angles has no way of making a specific small change in its rotation with a proportionally small change in the values involved -- it doesn't matter whether your rotational steps are large or small. Because euler angles don't map continuously to the domain of 3D rotations they don't work well in unconstrained systems such as Elite's. Quaternions are really very easy to use if you have a good class for them. Such classes aren't hard to write, either. (Just don't count on being able to clearly visualize how a quaternion represents rotation) The main disadvantage they have is that it's more efficient to convert them to matrices if you're going to be transforming a lot of points. Here's a simple header I programmed with a Quat class. Consider it MIT-licensed. You can probably ignore the Bend functions... evanbalster.com/goodies/pg_geometry3D.hTo simulate a ship moving through space, assuming the model points forward along the Z-negative axis and the "top" side of the ship is Y-positive: multiply the "roll" speed each frame like this: ori = Quat(Point3D(0, 0, 1), rollSpeed)*ori;the "pitch" speed: ori = Quat(Point3D(1, 0, 0), pitchSpeed)*ori;the "yaw" or "turn" speed: ori = Quat(Point3D(0, 1, 0), yawSpeed)*ori;Note that doing the rotations in the opposite order ( ori*Quat(...)) will result in rotations in the global coordinate system rather than the local one, which is almost certainly not what you want.
|
|
|
|
« Last Edit: October 29, 2012, 12:41:47 PM by Evan Balster »
|
Logged
|
Creativity births expression. Curiosity births exploration. Our work is as soil to these seeds; our art is what grows from them...Wreath, SoundSelf, Infinite Blank, Cave Story+, <plaid/audio>
|
|
|
|