# Basic network play: Quaternions -> Torque

aybiss

10-11-2007 02:44:12

I'm developing a *very* simple P2P network play system, where the opponent's position is simply updated over a socket, and forces applied to correct the position of the opponent on the player's screen.

Forces are no problem, but I also need to apply torque to correct the orientation of the object. Can anyone tell me what f(q1, q2) would be in the equation:

Vector3 currTorque = f(currentOrientation, targetOrientation)?

bleubleu

11-11-2007 21:24:55

Well good, we have something in common. We both suck at geometry.

As you probably know, the torque is basically a rotation force and it is given by the cross product of two vectors r and F. You also already probably know the right-hand-rule that helps remember those 2 vectors.

r is the axis of rotation, imagine it is a screw or a bolt you are trying to screw/unscrew and this is your thumb.. F is the direction you would pull or push if you were using a wrench to screw/unscrew and this is your other 4 fingers.

The cross product of these 2 vectors r x F will give you the torque that you are applying and it also can be vizualized as the area of the parallelogram spanned by these two vectors. So, the longer wrench and the more perpendicular you push, the easier it will be to unscrew that bolt.

So, where do quaternions fit into that ? I am not sure. There is some information missing. I assume they represent your 2 vector or directions. If it is the case, you could transform some unit vector with the 2 quaternions a use the cross product between those 2 vectors. But still, where is the mass, the inertia tensor, etc. ? I would need more info.

Mat

aybiss

12-11-2007 06:06:20

In MOGRE, torques are represented as a Vector3. This means rotation around three axes, IIRC around the X, Y and Z axes, since to apply the torque to your object in-situ you apply a torque of [objectorientation]*[torque vector].

Quaternions represent a full rotation operation with pitch yaw and roll, which cannot be represented by a single rotation. I believe they can be decomposed into three axes and three angles.

Since two quaternions can have different axes, I cannot simply calculate the difference in angles between two quaternions. If I could make them use common axes or something I might be able to get started.

Mass, MOI are unimportant, since Newton will take care of that. I just need a rough idea of what torque to apply this frame to get the object rotating towards the orientation required.

aybiss

13-11-2007 02:45:32

I figured it out. For the benefit of anyone using my search terms here is the solution

Quaternion rotError = theBody.Orientation.UnitInverse() * targetOri;
Matrix3 rotMat = rotError.ToRotationMatrix();