Transformation matrix / translation problem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Re: Transformation matrix / translation problem

Postby Julio Jerez » Sat Mar 12, 2016 1:31 pm

Shaderman wrote:q.m_q0 = -q.m_q0;
q.m_q1 = -q.m_q1;


I thought that was wrong too.
in the last image I though, it look to me that you seem is rotated by 180. degrees
try using reversing the quats like thing
when getting a quat from newton
Code: Select all
dQuat rot;
MyQuatertion (rot.q1, rot.q2, rot.q3, rot.q0);


when setting a newton matrix
Code: Select all
MyQuatertion rot;
dMatrix (dQuat (rot.w, rot.x, rot.y, rot.z));


if you still see the 180 dress rotation the try this

Code: Select all
dQuat rot;
MyQuatertion (rot.q1, rot.q2, rot.q3, -rot.q0);


when setting a newton matrix
Code: Select all
MyQuatertion rot;
dMatrix (dQuat (-rot.w, rot.x, rot.y, rot.z));
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Transformation matrix / translation problem

Postby Shaderman » Sat Mar 12, 2016 5:51 pm

Hi guys,

I think I've made it work with some voodoo. Maybe one of you understands what I did and knows a better way. I really need to learn more about this topic to make sense of it :roll:

@JoeJ thanks for your detailed post, I really appreciate your help. To be honest I need to read it over again to understand all of it :oops:
JoeJ wrote:This has to happen to anybody at least once in life :)

Can't wait for the next time lol

@Julio your hint partially helped, let me explain what I did.

In my last attempt, I've made the scene objects face in the correct direction, but the collision was off. All this was done with disabled transformation updates to verify the base setup.

Now I've built on that and think I was able to fix the collision rotation with this setup code:

Code: Select all
S3DX::AIVariable hObject = S3DX::object.fromStaticHandle(staticHandle);
S3DX::AIVariables<3> pos = S3DX::object.getTranslation(hObject, S3DX::object.kGlobalSpace);
dVector position(pos[0], pos[1], pos[2]);

S3DX::AIVariables<4> rot = S3DX::object.getRotationQuaternion(hObject, S3DX::object.kGlobalSpace);
dQuaternion rotation(rot[1], rot[2], rot[3], rot[0]);
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;

dMatrix matrix(rotation, position);
NewtonBody* const body = NewtonCreateDynamicBody(world, collision, &matrix[0][0]);


This is how it looks like, still no collision updates...

Image

Since I'm still working with just box collisions, I need to check the rotation somehow, maybe with debug drawing a vector or a convex hull...

Next I've enabled the ForceAndTorque and Transform Callback and used this code for the updates:

Code: Select all
void SetTransformCallback(const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
   dVector position;

   BodyUserData* bud = (BodyUserData*)NewtonBodyGetUserData(body);
   S3DX::AIVariable hObject = S3DX::object.fromStaticHandle(bud->staticHandle);

   dMatrix transform (matrix);
   dQuaternion rotation (transform);
   S3DX::object.setRotationQuaternion(hObject, rotation.m_q1, rotation.m_q2, rotation.m_q3, rotation.m_q0, S3DX::object.kGlobalSpace);

   NewtonBodyGetPosition(body, &position.m_x);
   S3DX::object.setTranslation(hObject, position.m_x, position.m_y, position.m_z, S3DX::object.kGlobalSpace);
}


Here's the result:

Image

The collision looks ok, but the gizmo scene objects are rotated... like 180 degree on the local Y axis.

So right after setting the rotation quaternion, I now rotate the objects around Y axis in local space.

Code: Select all
   S3DX::object.setRotationQuaternion(hObject, rotation.m_q1, rotation.m_q2, rotation.m_q3, rotation.m_q0, S3DX::object.kGlobalSpace);
   S3DX::object.rotateAxisAngle(hObject, 0.f, 1.f, 0.f, 180.f, S3DX::object.kLocalSpace); // rotate 180 degree around Y in local space


This way it looks at least like a solution. As stated above, I still need to check the rotation.

Isn't that voodoo? The way I did it looks weird. Do you guys have an explanation why it works this way and probably a better solution?

Thanks

Shaderman
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby JoeJ » Sat Mar 12, 2016 6:42 pm

Why don#t you do the same negation in Transform feedback like in setup?

dQuaternion rotation (transform);
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;
S3DX::object.setRotationQuaternion(hObject, rotation.m_q1, rotation.m_q2, rotation.m_q3, rotation.m_q0, S3DX::object.kGlobalSpace);

Does this work without the 180 degree rot?
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Transformation matrix / translation problem

Postby Shaderman » Sat Mar 12, 2016 7:04 pm

That was my first thought and attempt, like "hey, now you've got the setup working correctly, just do it the same way for the updates". Failed - object and collision rotation are off.

Image
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby JoeJ » Sun Mar 13, 2016 3:03 am

I think i've got it, this code

Code: Select all
// setup

      dVector pSetup (1,2,3);
      sQuat qSetup (0.1, 0.2, 0.3, 0.4); qSetup.Normalize();
      SystemTools::Log ("qSetup %f %f %f %f\n", qSetup[0], qSetup[1], qSetup[2], qSetup[3]);

      dQuaternion qSetupN( qSetup[1], qSetup[2], qSetup[3], qSetup[0] );
      qSetupN.m_q0 = -qSetupN.m_q0;
      qSetupN.m_q1 = -qSetupN.m_q1;
      SystemTools::Log ("qSetupN %f %f %f %f\n", qSetupN.m_q0, qSetupN.m_q1, qSetupN.m_q2, qSetupN.m_q3);

      dMatrix matrix(qSetupN, pSetup);
      NewtonBodySetMatrix (ground, &matrix[0][0]);

      // Transform callback

      dMatrix transform;
      NewtonBodyGetMatrix (ground, &transform[0][0]);
      dQuaternion rotation (transform);

      SystemTools::Log ("rotation %f %f %f %f\n", rotation.m_q0, rotation.m_q1, rotation.m_q2, rotation.m_q3);
      rotation.m_q0 = -rotation.m_q0;
      rotation.m_q1 = -rotation.m_q1;

      sQuat qCallback (rotation.m_q1, rotation.m_q2, rotation.m_q3, rotation.m_q0);
      SystemTools::Log ("qCallb %f %f %f %f\n", qCallback[0], qCallback[1], qCallback[2], qCallback[3]);
      
      SystemTools::Log ("WTF???\n");
   
      qCallback = sQuat (rotation.m_q3, rotation.m_q0, rotation.m_q1, rotation.m_q2);
      SystemTools::Log ("qCallb %f %f %f %f\n", qCallback[0], qCallback[1], qCallback[2], qCallback[3]);


gives this output:

Code: Select all
qSetup 0.182574 0.365148 0.547723 0.730297
qSetupN -0.365148 -0.547723 0.730297 0.182574
rotation -0.365148 -0.547723 0.730297 0.182574
qCallb 0.547723 0.730297 0.182574 0.365148
WTF???
qCallb 0.182574 0.365148 0.547723 0.730297


So i get back to the original quat by doing another kind of swizzling at the end.
I refuse trying to understand this :roll: , but most probably you do a 180 rotation at setup by negating,
and the swizzling is an optized way to reverse it.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Transformation matrix / translation problem

Postby Shaderman » Sun Mar 13, 2016 3:29 am

Thanks a lot JoeJ,

that's very interesting and I'll give it a try, because with a convex hull, I just noticed that the collision is rotated :roll:

Image
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby Shaderman » Sun Mar 13, 2016 1:07 pm

Update:

I've logged the rotations on setup and updates. Between setup and the first update, there's a positive/negative swap happening. I didn't find a solution for this problem and from searching the internet, I didn't find a solution.

The order I used was m_q0, m_q1, m_q2, m_q3, because it seems like it matches.

Code: Select all
SHIVA  Setup -0.104713 0.465566 -0.473035 -0.740622
NEWTON Setup -0.104713 0.465566 -0.473035 -0.740622

NEWTON Update 0.104713 -0.465566 0.473035 0.740622
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622


Btw I found this info about ShiVa's coordinate system:

ShiVa internally uses only quaternions. Euler angles are issued from a conversion from those quaternions, so there should be no particular order. At least it is not as simple as if we were storing Euler angles, in which case we would have an application order (XYZ or ZYX or ...).
Now, what I can say, is that ShiVa uses a right handed coordinate system, with Y up.


I think I need to get around this issue by working with (euler?)angles instead of matrices/quaternions, or do you guys have an idea how to solve this?

Thanks

Shaderman
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby JoeJ » Sun Mar 13, 2016 2:09 pm

No, euler angles are series of 3 rotations, quat or matrix do any rotation in one step.
Euler angles make no sense hare and are surely unrelated, their primary use are human interfaces.

Shaderman wrote:Between setup and the first update, there's a positive/negative swap happening


That swapping has no effect, it negates the axis and also angle.
Resulting in the same rotation.
(Usually the angular number w is always positive, and the signs of the axis numbers define in which direction the rotation happens)
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Transformation matrix / translation problem

Postby Julio Jerez » Sun Mar 13, 2016 2:10 pm

Code: Select all
SHIVA  Setup -0.104713 0.465566 -0.473035 -0.740622
NEWTON Setup -0.104713 0.465566 -0.473035 -0.740622

NEWTON Update 0.104713 -0.465566 0.473035 0.740622
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622


those two rotations are equivalent.
the matrix that you get from quaternion q Is the same that you get from -q
whoever if Shiva is dong frame interpolation, the you will see a flip.

this is why I say that instead of getting quaternion from the matrix in the callback you get the quaternion from the newton object by using function NewtonBodyGetRotation.

if those are the values you get then your scene should be ok now. Unless there is frame interpolation on the Shiva side.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Transformation matrix / translation problem

Postby JoeJ » Sun Mar 13, 2016 2:16 pm

I really thought the issue should be fixed, i'll post and update your code.
Try again, it should work:

Setup (no changes)
Code: Select all
S3DX::AIVariables<4> rot = S3DX::object.getRotationQuaternion(hObject, S3DX::object.kGlobalSpace);
dQuaternion rotation(rot[1], rot[2], rot[3], rot[0]);
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;

dMatrix matrix(rotation, position);
NewtonBody* const body = NewtonCreateDynamicBody(world, collision, &matrix[0][0]);


Transform Feedback
Code: Select all
void SetTransformCallback(const NewtonBody* body, const dFloat* matrix, int threadIndex)
{
   dVector position;

   BodyUserData* bud = (BodyUserData*)NewtonBodyGetUserData(body);
   S3DX::AIVariable hObject = S3DX::object.fromStaticHandle(bud->staticHandle);

// change this:

   //dMatrix transform (matrix);
   //dQuaternion rotation (transform);

NewtonBodyGetRotation (body, (float*)&rotation);
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;
S3DX::object.setRotationQuaternion(hObject, rotation.m_q3, rotation.m_q0, rotation.m_q1, rotation.m_q2, S3DX::object.kGlobalSpace);
//

   NewtonBodyGetPosition(body, &position.m_x);
   S3DX::object.setTranslation(hObject, position.m_x, position.m_y, position.m_z, S3DX::object.kGlobalSpace);
}


No 180 rotation after that.

EDIT: Added Julios suggestion
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Transformation matrix / translation problem

Postby Shaderman » Sun Mar 13, 2016 3:49 pm

@Julio sorry, I went back to a backup for testing which didn't use NewtonBodyGetRotation again. It seems to make no difference though, but I'll stay with it now.

@JoeJ I've tried your suggestion, but the collision still appears to be flipped around 180 degree, which can be seen on the collision hull.

Image

Are you sure this setup is the one you wanted me to try or is there possibly a copy & paste error? I wonder if the q- order is correct and also the negation of the two q- values.

Code: Select all
dQuaternion rotation(rot[1].GetNumberValue(), rot[2].GetNumberValue(), rot[3].GetNumberValue(), rot[0].GetNumberValue());
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;


Code: Select all
rotation.m_q0 = -rotation.m_q0;
rotation.m_q1 = -rotation.m_q1;
S3DX::object.setRotationQuaternion(hObject, rotation.m_q3, rotation.m_q0, rotation.m_q1, rotation.m_q2, S3DX::object.kGlobalSpace);


Here's the relevant code I used:

Code: Select all
   S3DX::AIVariables<4> rot = S3DX::object.getRotationQuaternion(hObject, S3DX::object.kGlobalSpace);
   
   logRotation(staticHandle, "SHIVA  Setup", rot[0].GetNumberValue(), rot[1].GetNumberValue(), rot[2].GetNumberValue(), rot[3].GetNumberValue());

   dQuaternion rotation(rot[1].GetNumberValue(), rot[2].GetNumberValue(), rot[3].GetNumberValue(), rot[0].GetNumberValue());
   rotation.m_q0 = -rotation.m_q0;
   rotation.m_q1 = -rotation.m_q1;
   
   logRotation(staticHandle, "NEWTON Setup", rotation.m_q0, rotation.m_q1, rotation.m_q2, rotation.m_q3);

   dMatrix matrix(rotation, position);
   NewtonBody* const body = NewtonCreateDynamicBody(world, collision, &matrix[0][0]);


Code: Select all
   dQuaternion rotation;
   dVector position;

   NewtonBodyGetRotation (body, (float*)&rotation);

   logRotation(bud->staticHandle, "NEWTON Update", rotation.m_q0, rotation.m_q1, rotation.m_q2, rotation.m_q3);

   rotation.m_q0 = -rotation.m_q0;
   rotation.m_q1 = -rotation.m_q1;
   S3DX::object.setRotationQuaternion(hObject, rotation.m_q3, rotation.m_q0, rotation.m_q1, rotation.m_q2, S3DX::object.kGlobalSpace);

   S3DX::AIVariables<4> rot = S3DX::object.getRotationQuaternion(hObject, S3DX::object.kGlobalSpace);

   logRotation(bud->staticHandle, "SHIVA  Update", rot[0].GetNumberValue(), rot[1].GetNumberValue(), rot[2].GetNumberValue(), rot[3].GetNumberValue());


I'm really out of ideas and feel like I've tried everything I can try. Having a hard time with this and you guys with me :roll:
I wonder why I didn't have this quaternion problem with PhySx and Havoc Plugins I've worked on before. I just had to use setRotationQuaternion on ShiVa side to make it work.
Is there anything I could ask the ShiVa devs which could be of help here?

EDIT: here is the log output

Code: Select all
SHIVA  Setup -0.104713 0.465566 -0.473035 -0.740622
NEWTON Setup -0.465566 0.473035 -0.740622 -0.104713
NEWTON Update 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622
NEWTON Update 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622
NEWTON Update 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622
NEWTON Update 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update 0.104713 -0.465566 0.473035 0.740622


Thanks

Shaderman
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby JoeJ » Sun Mar 13, 2016 4:05 pm

I can see nothing wrong in your code :|

Can you post the logging output, with an idditional ID per body so that we can see if it fails for all or just a few?
Also i can double check with my code if i can reproduce the error - i need this to believe :)
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Transformation matrix / translation problem

Postby Shaderman » Sun Mar 13, 2016 4:12 pm

Sure, I'll do anything to help you helping me :D

Code: Select all
SHIVA  Setup [ground] 0.120023 -0.108798 0.982603 -0.090818
NEWTON Setup [ground] 0.108798 -0.982603 -0.090818 0.120023
SHIVA  Setup [box] -0.104713 0.465566 -0.473035 -0.740622
NEWTON Setup [box] -0.465566 0.473035 -0.740622 -0.104713
SHIVA  Setup [cube] 0.091013 0.316101 0.261593 -0.907395
NEWTON Setup [cube] -0.316101 -0.261593 -0.907395 0.091013
SHIVA  Setup [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Setup [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
SHIVA  Update [gizmo] -0.637058 -0.600159 0.313780 -0.368115
NEWTON Update [cube] 0.316101 0.261593 0.907395 -0.091013
SHIVA  Update [cube] -0.091013 -0.316101 -0.261593 0.907395
NEWTON Update [box] 0.465566 -0.473035 0.740622 0.104713
SHIVA  Update [box] 0.104713 -0.465566 0.473035 0.740622
NEWTON Update [gizmo] 0.600159 -0.313780 -0.368115 -0.637058
Shaderman
 
Posts: 66
Joined: Tue Mar 08, 2016 2:51 am

Re: Transformation matrix / translation problem

Postby Julio Jerez » Sun Mar 13, 2016 4:30 pm

I do not understand why you get this problem, if you look at the values

they are transposed

Code: Select all
SHIVA  Setup [ground] 0.120023 -0.108798 0.982603 -0.090818
NEWTON Setup [ground] 0.108798 -0.982603 -0.090818 0.120023

if I take the shiva quat and I do this

newton[0] = -Shiva [1]
newton[1] = -Shiva [2]
newton[2] = Shiva [3]
newton[3] = Shiva [0]

then the two quat match, the reverse should be

Shiva [0] = newton[3]
Shiva [1] = -newton[0]
Shiva [2] = -newton[1]
Shiva [3] = newton[2]

try that see if is does it.

But it has to be some more insidious than that because this seem to match for the few values only.
in general the rotation with be the same not matter who you encode them in the vector, but her I see the different component by components. There must be something wrong on the Shiva conversion to matrix.
I once saws en engine that some wacky conversion routine form Quake that I have to reverse enginire to figure out what was doing. Is this a quake base engine?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Transformation matrix / translation problem

Postby JoeJ » Sun Mar 13, 2016 4:43 pm

Ok, missed the edited log.
I get the same result with those numbers.
Also, i see at Shiva doc that their order is as expected:

x, y, z, w = object.getRotationQuaternion ( hObject, kSpace )


That means it should work - at update you give Shiva the same rotation that Shiva gave you at setup.
Did you try to negate all numbers at setup, so that all signs match? No difference i guess:

S3DX::AIVariables<4> rot = S3DX::object.getRotationQuaternion(hObject, S3DX::object.kGlobalSpace);
dQuaternion rotation(rot[1], rot[2], rot[3], rot[0]);
rotation.m_q2= -rotation.m_q0;
rotation.m_q3 = -rotation.m_q1;




The math is right, something else does not work as expected.
S3DX::AIVariables<4> rot =
Is this modern C++ or templates? Does that return an array of 4 floats and preservis it the order of values?
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

PreviousNext

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest