Quaternion usage

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Quaternion usage

Postby Nairou » Sun Mar 22, 2009 2:23 pm

While searching around this forum, I stumbled over this discussion which seems to indicate that Newton 2.0 now supports Quaternions. Awesome!!

However, it is not immediately obvious how to use them, and the function mentioned, NewtonBodyGetRotation, doesn't actually take any quaternion parameters. It takes a dFloat pionter, I'm assuming this is used as a pointer to the internal floats of a quaternion? Does NewtonBodyGetRotation always assume the dFloat points to a quaternion, or are there cases where it is used differently? (I just don't understand why the parameter is a dFloat and not a dQuaternion to begin with...)

Also, while NewtonBodyGetRotation lets me retrieve the quaternion rotation of a body, I haven't seen any function for actually setting the rotation of a body using a quaternion (i.e. NewtonBodySetRotation doesn't exist). Is there a way to do this as well?

Thanks!
Nairou
 
Posts: 1
Joined: Tue Jun 06, 2006 5:39 pm

Re: Quaternion usage

Postby Sury » Sun Mar 22, 2009 5:48 pm

It should work the same way as matrices for example. NewtonBodyGetMatrix and i guess it uses memcpy or something to quickly fill the data to your structure, beginning from the address of the dFloat you provide and the size of a 4x4 matrix or Quaternion in your case. It's a C style interface and passing a pointer is faster than passing whole structures around.
User avatar
Sury
 
Posts: 193
Joined: Sat Aug 14, 2004 5:32 am
Location: Bulgaria

Re: Quaternion usage

Postby Julio Jerez » Mon Mar 23, 2009 9:54 am

a quation sins and array of flor float (q0, q1, q2, q3)
NewtonGetRotation returns those values who are already in the body structure.
there is not need for NewtonSetQuaterion since convertion for quatertion to matrix is a standard function in any quaternion library.

the quaternion format is,
Q (q0, q1, q2, q3) = Q (cos(ang/2), sin (and/2) * x, sin (and/2) * y, sin (and/2) * z);
x, y, z is a unit vector
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 16 guests

cron