# Space ship control

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

## Recommended Posts

I'm trying to implement space control like that found in Starlancer, Freespace, etc. I'm using the mouse to control yaw and pitch with no roll. In Starlancer, no matter what your pitch, left is still left, right is still right, etc. I've got it close by reversing yaw if 90 < pitch < 270. This still leads to the feeling of roll if you yaw while looking close to straight up or down. I'm using matrix rotation by computing the look/right/up vectors, similar to FPS camera controls. Anyone have experience in implementing this type of control? Am I missing something? Thanks!

##### Share on other sites
It sounds like you need local axis rotations. Can you post your current code for computing the orientation matrix?

##### Share on other sites
Sure, here it is. The rotation vector stores the yaw (Y), pitch(X) and roll(Z). So my character movement works perfectly for a quake style control, as long as you clamp the pitch to straight up or down. What I am looking for is regardless of the up vector, left is left, right is right, etc. I would like to add roll as well.

            this.up = new Vector3(0.0f, 1.0f, 0.0f);            this.look = new Vector3(0.0f, 0.0f, 1.0f);            this.right = new Vector3(1.0f, 0.0f, 0.0f);            Matrix yawMatrix = Matrix.RotationY(MathUtil.DegreesToRadians(-this.rotation.Y));            this.look = yawMatrix.TransformCoord(look);            this.right = yawMatrix.TransformCoord(right);            Matrix pitchMatrix = Matrix.RotationAxis(right, MathUtil.DegreesToRadians(-this.rotation.X));            this.look = pitchMatrix.TransformCoord(this.look);            this.up = pitchMatrix.TransformCoord(this.up);            this.look.Normalize();            this.up.Normalize();            this.right.Normalize();            this.velocity = this.look * this.speed * elapsed;

##### Share on other sites
I think you'll probably have to abandon Euler angles and switch to local-axis rotations. (I know one of your rotations is about a local axis, but in this particular case that doesn't really change anything.)

I posted some code in this thread which shows how to do 6dof motion of the sort you describe. I'll be glad to answer questions about it, or offer further explanation if necessary.

##### Share on other sites
The code looks great. One question. To transmit over the wire, I was just using a Vector3 that stored the x,y and z rotations. What would be the best way to transmit the angles now, so that they can be turned into a proper model matrix for rendering on the client? I'd like to avoid sending 3 Vector3's across.

##### Share on other sites
Quote:
 The code looks great. One question. To transmit over the wire, I was just using a Vector3 that stored the x,y and z rotations. What would be the best way to transmit the angles now, so that they can be turned into a proper model matrix for rendering on the client? I'd like to avoid sending 3 Vector3's across.
I don't know much about networking, but I'll just tell you some ways you can compress the representation.

1. Only send two of the direction vectors, and reconstruct the third on the other side using the cross product (6 floats).

2. Send it as a quaternion or axis-angle pair (4 floats).

3. Send it as a compressed quaternion or axis-angle pair (3 floats).

4. Send it as an Euler angle triple (3 floats).

It sounds like you'd like to do number 4. For this you'll need to extract the Euler angles on one side and then reconstruct from them on the other. It doesn't really matter what order you use, but the order has to be the same on both sides. Do you already have Euler angle extraction and construction code?

There was a thread on this topic recently in Math & Physics. It was a while ago though, and without search I'm not sure how I'd find it. But it was a discussion of this very issue - if you think it might help you, you might go looking for it (it's probably in the last 10-20 pages).

Let me know if you have any other questions.

##### Share on other sites
Perhaps my understanding would be better if I understood the definition of "local axis". Does this mean starting with one world axis (perhaps a look of (0,0,1), do a pitch, for example, then construct up, right, etc as well as further rotations (yaw,roll) based on the results? So you pitch up, construct the up from look x right (since right hasn't rotated yet), yaw the look, then construct right from look x up, etc.?

##### Share on other sites
Quote:
 Perhaps my understanding would be better if I understood the definition of "local axis". Does this mean starting with one world axis (perhaps a look of (0,0,1), do a pitch, for example, then construct up, right, etc as well as further rotations (yaw,roll) based on the results? So you pitch up, construct the up from look x right (since right hasn't rotated yet), yaw the look, then construct right from look x up, etc.?
By local axis, I mean a basis vector (up, forward, side) of a local coordinate frame. These basis vectors can be extracted from any orientation representation (matrix, quat, axis-angle, Euler angles, etc.).

The key to 6dof movement, though, is incremental rotations. That means that instead of constructing your orientation from scratch each frame, you maintain it from frame to frame and update incrementally through axis-angle rotations (that's what the code I referred you to does). With this method you'll usually have to normalize occasionally to prevent drift.

I also wanted to add something. I specifically wrote the code I posted not to use quaternions, for simplicity, and also to demonstrate that gimbal lock-free motion does not require them. However, for a game like yours I would probably choose quaternions as the fundamental representation for orientation, for the following reasons:

1. Efficient interpolation (if you need it)
2. No conversion required (except perhaps compression) to send it over the net
3. Integrates with a physics system more easily than three direction vectors

Anyway, I have to run, but let me know if you have any other questions.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634135
• Total Posts
3015752
×