Using Quaternions in Panda3d

Hi to all,
I’ve noticed that there aren’t any proper tutorials on how to use quaternions with panda3d. Calling this page to learn more also yields a 404 error:
quat reference?
All I’ve found are calls to getQuat and setQuat, though it’s not clear to me what exactly to do with them. For example, say I wanted to set an object’s Heading so that it looks to it’s left or right. I would do the same by calling:


Same for its P and R to make it look different directions etc. So how would I do the same with quaternions? Basically an introduction as to how to properly use quaternions (use, not understand, for all those who are about to tell me they’re impossible to comprehend :stuck_out_tongue:) in panda3d? The forum discussions aren’t that helpful and are kinda overly-specific.I’m sure someone familiar with them could explain their use with a few simple examples in a few lines here.

Thank you so much in advance.
(P.s. not sure if this is a scripting issue, since it does pertain to writing scripts, or more of a general discussion issue, since it’s a general inquiry of sorts as well.)

Perhaps you were trying to visit an old API-reference page (from before the move to the new website)?
If you go here, and search for quat, you will probably first find the namespace page and eventually you should end up here.

To get a quaternion that describes the rotation you want, there are several ways, but the easiest is probably to use its set_hpr method:

quat = Quat()
quat.set_hpr((90., 0., 0.))

The same could be accomplished using a call to set_from_axis_angle (in this particular case you know that the rotation happens about the Z-axis, so the axis vector is Vec3(0., 0., 1.) or just Vec3.up(), but for a more general orientation the axis vector is harder to determine):

quat.set_from_axis_angle(90., Vec3.up())

Finally you can also convert a matrix to a quaternion:

rotation_mat = Mat4.rotate_mat(90., Vec3.up())
quat = Quat()

and the other way around:


Then you just pass that quaternion into the call to NodePath.set_quat().

That should get you started :slight_smile: !

Thanks for clearing up some mysteries.