Math/quaternion help! [Answered]

How can I make a quaternion that I can use in setQuat() out of a 4x4 list that my program has computed?

And how do I use the setQuat() method at all? :slight_smile:

Assuming you mean NodePath.setQuat; why not use NodePath.setMat(LMatrix4f) instead? (There’s LMatrix4f::set() to convert from the list)

Overall, easier to use matrices and skipping conversions, I’d say

I use NodePath.setMat(LMat4f) in my PyODE integration (see code snippets).

Miel

I absolutely agree. Unecessary conversions are expensive and lead to numerical inaccuracy. If you have a matrix, use a matrix.

Still, to answer the original question, if you have a matrix and for some reason you really want a quaternion, you could do:

q = LRotationf()
q.setFromMatrix(m)

And then to apply it to a node:


np.setQuat(q)

David

Thanks for the help :slight_smile:

New Question:
How do I use a 3x3 matrix to transform an object? NodePath.setMat() seems to only accept 4x4 matrices.

Thanks everyone you are very helpful.

nodePath.setMat(Mat4(m3))

setHprScale takes a 3x3 matrix and I don’t know about any others. You should check the API reference. It’s all in there.

greets,

Miel

Thanks a lot guys :smiley: Everything works now.
I got my program to work (its a fps, the matrix stuff was to get the mouse-controlled camera to work).
Sometimes I have a hard time understanding the organization of the documentation.