Forums > Jitter

# jitter.gl.handle rotation problem

October 26, 2006 | 6:23 pm

Hi,
Im using a maxmspjitter interface to control 3d objects in blender’s game engine- communicating between the two via opensoundcontrol.
Im having troubles trying to mimic the rotation of a 3d object from jitter- in blender.

When i move an 3d object with the mouse in a jitter.gl.handle object i can- route rotate – to get a list of 4 numbers:

one number is between 0 and 360 [a]
another between -1 and 1 [x]
another between -1 and 1 [y]
another between -1 and 1 [z]

[letter in brackets are what i guess these to be]

I need to convert these numbers into a format Blender will understand, either;
a 3×3 rotation matrix, or Quaternion

–or–

place them in this python script (by spike1907);

def matToEuler():
ori = GCC().getOwner().getOrientation()
J = -asin(ori[0][2])
cJ = cos(J)
if cJ!=0.0:
cJ = 1.0/cJ
I = atan2(ori[1][2] * cJ , ori[2][2] * cJ)
K = atan2(ori[0][1] * cJ , ori[0][0] * cJ)
return (degrees(I) , degrees(J) , degrees(K))

def eulerToMat(I, J, K):
A , B = sin(I), cos(I)
C , D = sin(J), cos(J)
E , F = sin(K), cos(K)
AC, BC = A*C, B*C
return [[D*F , D*E , -C],
[AC*F-B*E, AC*E+B*F, A*D],
[BC*F+A*E, BC*E-A*F, B*D]]

o.setOrientation( eulerToMat(45,0,0) )

I have tried multiplying the jit.gl.handle’s numbers to leave me with ax, ay and az. Then placing them into the script so the last line reads;

o.setOrientation( eulerToMat(ax,ay,az) )

but this does not produces really wacky rotation in Blender, when the object in jitter is spinning slowly the one in Blender is speding up and slowing down.

If anyone whos knows a bit about maths can help me out id be really thankful. Even just telling me what jit.gl.handles roatation numbers actually are would help.

Cheers.

October 26, 2006 | 7:50 pm

On Oct 26, 2006, at 11:23 AM, will wrote:

> I need to convert these numbers into a format Blender will
> understand, either;
> a 3×3 rotation matrix, or Quaternion
> If anyone whos knows a bit about maths can help me out id be really
> thankful. Even just telling me what jit.gl.handles roatation
> numbers actually are would help.

As is typical in OpenGL, the rotation is specified in angle/axis
format. Check out Jitter3DUtils.js or online resourcea for an example
of how to convert an angle/axis pair to either a quaternion or a
rotation matrix. Here’s the relevant JS functions to go back and
forth from angle/axis and quaternion representations.

// convert angle/axis rotation to quaternion.
this.axis_to_quat = function (axis, quat)
{
var d2r = (Math.PI / 180.);
var phi = axis[0]*d2r;
var mag;
var scale;

mag = Math.sqrt(axis[1]*axis[1] + axis[2]*axis[2] + axis[3]*axis[3]);

if (mag < 0.0005)
mag = 1;

scale = Math.sin(phi/2.0)/mag;

quat[0] = axis[1]*scale;
quat[1] = axis[2]*scale;
quat[2] = axis[3]*scale;
quat[3] = Math.cos(phi/2.0);
}

this.quat_to_axis = function (quat,axis)
{
var cos_a, sin_a;
var r2d = (180. / Math.PI);
cos_a = quat[3];
axis[0] = (Math.acos(cos_a) * 2.)*r2d;
sin_a = Math.sqrt(1.0 – cos_a * cos_a);

if (Math.abs(sin_a) < 0.00005)
sin_a = 1;

axis[1] = quat[0] / sin_a;
axis[2] = quat[1] / sin_a;
axis[3] = quat[2] / sin_a;
}

-Joshua

October 26, 2006 | 10:33 pm

Hi Joshua,

Thanks for the help, everythings up and running now. If anyones interested heres some equations. And importantly if youre using python then unlike opengl everythings in radians not degrees- had me stumped for a while.

http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToMatrix/index.htm

http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

Viewing 3 posts - 1 through 3 (of 3 total)