Haxe - iron.math.Quat

#1

Hello guys! Since february I really spend my avaible time in Armory3d haxe. I still have questions.

Can someone explain me what iron.math.Quat is.

I really don’t know how I can use it and for what.

Have a good day!!

0 Likes

#2

iron.math.Quat is the Armory Quaternion class. Quaternions are a way to represent rotation in 3D space with a 4 dimensional value. The other common way to represent rotations is with Euler angles which use X, Y, and Z rotation values. Quaternions can be superior to Euler angles for engine internals because Euler angles can run into problems when trying to smoothly interpolate them, but Euler angles are obviously way more intuitive. You can checkout the OpenGL Tutorial’s explanation of rotations to get more details.

Quaternions in Armory can be useful when you want to rotate an object a certain number of degrees around an axis or when you want to smoothly go from one rotation to another.

2 Likes

#3

Also – “Armory3D” is a Haxe “package” that depends on several other packages including Iron and Kha. The source libraries use the traditional directory structure so there’s a file at /iron/math/Quat.hx.

The basic definition of a Quaternion object will be found in this file, and any other Haxe file which refers to a Qaternion must reference it.

“Quats” are an alternative representation of a 3D vector angle that does not have “gymbal lock” and other similar mathematical problems when you start to do math with them. Very commonly used in all 3D applications for this reason. Can be mapped to Eulers and vice-versa. (getEuler(), fromEuler() …)

If you’re curious … find the Haxe source-code here.

2 Likes

#4

Hey @zicklag!!! Your description is insane!!! Thank you so much. It helped me. I saw in the rotation node source the quat class. Can you give me a tip how I can set this up in a haxe script. I try to create a rotation script for a cube. For me it didn’t worked.

Have a nice day!

0 Likes

#5

Hi @MikeRobinson. I also want to thank you for your desciption. I saw the source code but I don’t know how to use the Quat class. I’m not new to Armory but I still don’t know how those iron.math’s classes works. I also saw the Armory3d haxe api site but I still don’t get it.

But anyways thank you for your support :wink:

0 Likes

#6

Hi – “just read more about the topic.” 3D applications do lots of things that involve vectors, and “quats” are a faster and more-compact way to do these things which also neatly avoid the “gymbal lock” problem. If you’re a “voodoo mathematician,” you might be able to say with a straight face that you understand how they work. Otherwise, you just know that they do. :smiley:

1 Like

#7

@MikeRobinson it’s better to feel by yourself the power of quaternions through making your own experiences … you will discover how your brain is powerfull to adapt and maths is like to discover new countries.

Lubos’ highly targeted and well-done examples are here to support you during this exploration.

But if you feel discouraged during this exploration, the community of this forum is always happy to help you overcome its obstacles, all being to share explicitly where it gets stuck for you during this exploration.

It is also a good way and help for the community to feel which documents will be the most useful for the greatest number of people and to retrieve exchanges on the forum to build them.

2 Likes

#8

Quaternions give my brain gymbal lock. :roll_eyes:

2 Likes

#9

Qats give my brain gymbal lock …

Most of the math that’s associated with 3D graphics causes my brain to melt down. “It’s voodoo. Really. Voodoo.”

0 Likes

#10

@Armored_Blob maybe harder for your brain but it’s known as a less CPU demanding technic.:slightly_smiling_face:

A way to approach the thing in a more relaxed way, visualize/imagine them like if you where at the command of a plane and flying where you want.

Looking here to simply get in mind the rotations for a finite subset of the rotation group may help you too.
image https://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/steps/index.htm

0 Likes

#11

Glad it helped. :slight_smile:

Here is some code for rotating an object:

// Rotate the object using x, y, and z Euler angles
var q  = new Quat().fromEuler(xRot, yRot, zRot);

// Or rotate the object by specifying an axis vector and an angle measurement
var axis = new Vec4.xAxis(); // The X axis ( which is the same as `new Vec4(1, 0, 0)`.
var angle = 123; // Which I think is in radians
var q = new Quat().fromAxisAngle(axis, angle);

// object.transform.rot is a Quat. To rotate a quat with another one you
// multiply them using the `mult()` function.
object.transform.rot.mult(q);

// Every time you modify the loc, rot, or scale of the object transform you must
// rebuild the matrix to apply it.
object.transform.buildMatrix();
1 Like