# Issues in applying Quaternion

Hi guys,

I’m trying to build a simple shape which is shown below. The above shape is rendered using Cocos3D.I’m trying to build the same shape using Jmonkey in android. The shape shown above is constructed using Jmonkey.I’m using the same values for Cocos3d and Jmonkey, but the results are different.I cross checked with some of the rendering tools available for desktop and found the shape rendered from cocos3d is correct.

Totally i’m drawing 3 boxes.The code used by me is

[java]minVect = new Vector3f(0,0,0);

maxVect = new Vector3f(4.2005f, 0.435f, 1.25f);

quaternion = quaternion.set(0, 0, 1, 0);

box = new Box(minVect,maxVect);

Geometry player = new Geometry(“box”, box);

player.setLocalRotation(quaternion);

minVect = new Vector3f(0,0,0);

maxVect = new Vector3f(4.2005f, 0.435f, 1.25f);

quaternion = quaternion.set(0,0,0,1);

box = new Box(minVect,maxVect);

Geometry player = new Geometry(“box”, box);

player.setLocalRotation(quaternion);

minVect = new Vector3f(0,0,0);

maxVect = new Vector3f(1.765f, 0.435f, 1.123f);

quaternion = quaternion.set(0, 0, -0.707107f, 0.707107f);

box = new Box(minVect,maxVect);

Geometry player = new Geometry(“box”, box);

player.setLocalRotation(quaternion);[/java]

Thanks & Regards,

Sree Harsha.P

Just a guess, but setting the raw values of a Quaternion (the magic numbers) as you do makes a lot of assumptions about the coordinate system that may not be true.

Can you get your rotation values in some other more transportable way like euler angles or something?

I’m calculating these values from [java]quaternion.fromRotationMatrix()[/java]. So, should i have to change the method to [java]quaternion.fromAngles()[/java]?

I tried using [java]quaternion.fromAngles()[/java].But, i didn’t get the correct results.

I calculated the angles using the formula mentioned in this link.

I don’t have enough information to help you. I have no idea what data you start with that you’re trying to inject into a quaternion.

If the angles you got are correct then the most likely mistake is that you are passing them in the wrong order… or that it relies on an order different than fromAngles() applies them. In Euler angles, the order they are applied is important. If the order of x, y, z are important then you will have to build multiple Quaternions and combine them.

…since I don’t know what you start with, that’s all I can offer.

Thanks a lot @pspeed.

Actually, i’m passing MAtrix3f to [java]quaternion.fromRotationMatrix()[/java]. The Matrix3f contains the vectors which define the rotation of the axis.

Anyways, i solved my problem.previously, i constructed Matrix3f as row major.Now,I passed the vectors to MAtrix3f as column major.Now it’s working as i expected.

More precisely,

I am using quaternion.fromRotationMatrix() for applying rotation.I passed Matrix3f as parameter.

I’m having 3 axis vectors, XVector(x1,y1,z1) , YVector(x2,y2,z2) , ZVector(x3,y3,z3).

Mistake : i constructed Matrix3f as row major like new Matrix3f( x1,y1,z1,x2,y2,z2, x3,y3,z3)

Solution : i constructed Matrix3f as column major like new Matrix3f( x1,x2, x3,y1,y2,y3,z1,z2,z3).

Don’t know what difference it makes, but solved my issue. Once again thanks @pspeed.

Regards,

Sree Harsha.P