Slopey
Volunteer Moderator
Hi All,
Ok - here's one which I've never quite got my head around, and which would be quite handy to understand...
Lets say (for sake of argument), I'm making an Elite clone. I have my player ship entity which is really just the camera viewpoint and I can pitch my ship up/down (along the Y axis), roll left/right (around the z axis) in the same way as the original Elite control method. (The X axis would be yaw left/right in this example).
This is all in cartesian space, and I know the camera's position and can assign pitch/roll angles in degrees to the camera position.
In that scenario, it'll be fairly easy to achieve gimbal lock and I could limit the pitch/roll range to +/- 89 degrees to avoid ever being aligned along an axis, but it's a bit primitive.
What I'd like to do is use Quaternions, which I believe I could multiply by a rotational matrix for the desired rotation and that would prevent gimbal lock?
But how (in code or pseudo code, perferrably some derivative of Basic) do you represent a point in cartesian space as a quaternion? And once you've applied the rotational matrix, transpose that back into cartesian co-ordinates/pitch or roll angles?
i.e. for the players ship/viewpoint stationary at 0,0,0 orientated so the Y axis is "up", the X axis is "left" and the Z axis is "forward". With no movement/velocity, how would you represent a roll right of 30 degrees, then pitch up of 20 degrees?
And if you then apply a velocity to that so the viewpoint is moving along the Z axis at a given speed (or units per second), how do work out the new position of the ship translating to/from vectors/quaternions?? (at given intervals, i.e. recalculating once per frame).
Any help appreciated - I knew I should have paid more attention in Maths at Uni, but they lost me irrevocably at integration!
Cheers,
S.
Ok - here's one which I've never quite got my head around, and which would be quite handy to understand...
Lets say (for sake of argument), I'm making an Elite clone. I have my player ship entity which is really just the camera viewpoint and I can pitch my ship up/down (along the Y axis), roll left/right (around the z axis) in the same way as the original Elite control method. (The X axis would be yaw left/right in this example).
This is all in cartesian space, and I know the camera's position and can assign pitch/roll angles in degrees to the camera position.
In that scenario, it'll be fairly easy to achieve gimbal lock and I could limit the pitch/roll range to +/- 89 degrees to avoid ever being aligned along an axis, but it's a bit primitive.
What I'd like to do is use Quaternions, which I believe I could multiply by a rotational matrix for the desired rotation and that would prevent gimbal lock?
But how (in code or pseudo code, perferrably some derivative of Basic) do you represent a point in cartesian space as a quaternion? And once you've applied the rotational matrix, transpose that back into cartesian co-ordinates/pitch or roll angles?
i.e. for the players ship/viewpoint stationary at 0,0,0 orientated so the Y axis is "up", the X axis is "left" and the Z axis is "forward". With no movement/velocity, how would you represent a roll right of 30 degrees, then pitch up of 20 degrees?
And if you then apply a velocity to that so the viewpoint is moving along the Z axis at a given speed (or units per second), how do work out the new position of the ship translating to/from vectors/quaternions?? (at given intervals, i.e. recalculating once per frame).
Any help appreciated - I knew I should have paid more attention in Maths at Uni, but they lost me irrevocably at integration!
Cheers,
S.