Why are the x,y,z,w members of the quaternion class protected?
-Ike
Why are the x,y,z,w members of the quaternion class protected?
-Ike
Because if you think you need to set them directly then you are confused about what a quaternion is.
I understand what they are⦠Iāve run into a case where I need to do this. And it got me curious as to why you didnāt make them public. It doesnāt hurt.
Well, you can do it with the
set(float x, float y, float z, float w)
right?
99.9999999999999999999999999999999999999999999% of the time someone wants to do this, they think quaternions are an angle-axis. The other 0.00000000000000000000000001% of the time, the experts know they can just call set() since setting one value of a quaternion at a time makes no sense at all. 0.
And here I was thinking the opposite, donāt make internal class members public, please, it ONLY HURTS.
Hah you should see the official oracle JavaFX library though. EVERYTHING PRIVATE.
I need it for my animation format. All my frame data is packed and I pull out the data with masks.
For rotations:
jointPose.rotation.x = channelOffset[3];
if ((mask & 0x08) != 0) {
jointPose.rotation.x += frameData[frameD++] * channelScale[3];
}
At the moment Iām just putting them all into floats then creating the quaternion.
And no Iām pretty sure it will not hurt. I think of them as essentially being structs. They just hold data and do some maths.
Random thought:
Wouldnāt it be better to have vecs,quats and matrices as float arrays and their respective classes to be static
You can think of them being unicorns if you like, doesnāt make it a good future proof design though
There is no future for such a class. It is simply a utility. A storage bin.
I also think, that using stupid get/set to encapsulate a private field is a āwrongā habit of java. A Legacy of OO and āhow do I manage evolution of a field that move from āanniversary dateā to ābirth dateāā. In the fact, 99.99999% of the time, when you change the private, you also change the public. (get/set are just boilerplate)
Now, Quaternion are as is in jME and 99.9999% of java dev like to wrap/encapsulate field with get/set. So itās easier to have 0.0001% that ask āwhy not a struct/array/data type + functions ?ā vs 99.9999% that ask 'why not a POJO ?"
Then if itās just a storage bin for 4 floats then use Vector4f.
Quaternion values are all interdependent so it never makes any sense to set one without the other and is almost always a mistake. And by āalmost alwaysā, Iāve never once seen it not be a mistake if your intent is to actually have valid quaternions.
No, because there is a pretty measurable performance benefit for accessing fields directly, especially through final methods that might get inlined.
This is NEVER a valid operation for a quaternion. So itās good that we donāt let you make invalid ones here.
Okay, I give up.
(it is a valid operation in this case. Since Iām unpacking dataā¦)
Also not my pointā¦
Still there
What remembers meā¦
https://en.wikipedia.org/wiki/Technology_in_The_Hitchhiker's_Guide_to_the_Galaxy
A whole thread to get here. If you include your use-case up front next time then it will save a lot of trouble.
For unpacking data, keep four floats. Call set() when done. It will be faster and doesnāt expose users to problems.
ā¦and there WILL be problems because there are already a large number of posts from people who have messed up their Quaternions and they canāt even set the values directly.
While it sounds like you would really enjoy procedural languages (it was really nice in its own way), sometimes itās ok to let object oriented programming do what itās really good at: encapsulation.