Shouldn't Camera.getRotation() have by-value semantics?

Spatial.getWorldRotation() and Transform.getRotation return a copy of the Quaternion which represents their rotation, but Camera.getRotation() returns an actual reference to the internal quaternion it uses to store its rotation.

Thus, Camera.getRotation() is by-reference while Spatial.getWorldRotation() and Transform.getRotation() are by-value.

Are the different semantics of these intentional, and even if they are, might it be better to make Camera.getRotation() by-value so that it is consistent with its cousins?

I say this because I just spent 30 mins trying to figure out why the “Initial Position” Quaternion I got from my Camera kept changing :frowning:

Keep up the great work everyone!

–Robert McIntyre

I don’t see a real case for having it by-reference, it might have just been convenience at the time, or just overlooked.

And it doesn’t make sense having it by-reference when everything else is by-value.

getLocalTranslation() also gives you an internal vector, as should getWorldRotation the last time I checked. There are some of these that should not be changed and we intend to mark these using annotations and then using an annotation processor in the compiler (standard java function since java6). These can even traceback variables and check if they get changed later etc. Work has been laid out here but its in a very early stage I fear. Basically you should never store or change the vectors you get really. This is basically a measure to reduce garbage overhead.

^^ Yeah, JME (thankfully) seems to take the line that more people would want fast than would want “hand holding”… and rightfully then lets you shoot yourself in the foot if you do strange things. In this case, by not taking extra garbage and construction time to return a copy just so you can look at some values. (Hoping that you won’t then directly change those values.)


Yeah I take that back — Spatial.getWorldRotation() is by-reference after all, so there’s no consistency problems, and it is faster to do it by-reference. Sorry for the noise.

sorry I forgot that the setters copy the value but the getters use the reference, at least for set/getLocalTranslation/Rotation/Scale.