avc81's picture

conversion from matrix to quaternion and back

Project:The Open Toolkit library
Version:1.1-2014-01-02
Component:Code
Category:feature request
Priority:normal
Assigned:avc81
Status:closed
Description

why don't we add these methods to Matrix,Matrix4d and Quaternion,Quaternion4d? They will be useful


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
puklaus's picture

#14

I would like to see this in OpenTK. And maybe changing Matrix & Quaternion results from 'ref' to 'out',
ie
public static void CreateFromQuaternion(ref Quaternion q,ref Matrix4 m)
->
public static void CreateFromQuaternion(ref Quaternion q,out Matrix4 m)

avc81's picture

#15

i agree. if fiddler agrees i will create a final patch when opentk 1.1 is ready to be released

phq's picture

#18

Avc81 your code looks like it generates the transpose of the rotation matrix compared to other sources:

If found 4 other sources but the spam filter blocked the post but I guess any search will give them.

avc81's picture

#19

i have no time to check now but i think you should take a look at Matrix4d,Matrix4 internal representation

phq's picture

#20

Apparently this is depending on the coordinate system, your implementation is the correct one for right handed systems which OpenGL by default is.

avc81's picture

#21

ok so i think this mod could be integrated in opentk (since opentk is a wrapper for opengl ;))

AndyKorth's picture

#22

It appears that this patch never made it into SVN, so I'm adding it to the repository here, in addition to a at least one more missing matrix function... Mult(Matrix4 left, Vector4 right), which I noticed was missing when I was working on my project.

Robmaister's picture

#23

It doesn't look like that particular commit is on github yet, but in case you don't already know Mult(Matrix4, Vector4) is functionally equivalent to Vector4.Transform(Vector4, Matrix4). Between those two and the operator overload, have only one implementation and the other two chaining off to the implementation if it isn't that way already.

AndyKorth's picture

#24

Yeah, haven't pushed this one yet. I did find the Vector4.Transform and noticed some things I considered odd. I don't want to change the "openTK" way of doing things, so I'm still pondering what to do.. (and if I want make changes for my own purposes and leave the OpenTK unchanged.)

In this case, we might not want Matrix4 * Vector4, since matrix multiplication is not commutative. The Vector4.Transform(Vector4, Matrix4) implies an ordeer, and switching those around willy-nilly would not be correct.

AndyKorth's picture

#25

Addressed these issues here: https://github.com/andykorth/opentk

* Issue 1880, Fix non-locale Vector ToString method
* Add create from quaternion method to Matrix4
* Added index getters and setters to all vector and matrix classes
* added Robmaister's Matrix3 implementations