hi everyone!
when i started to play with the jmonkeyengine some weeks ago, i quickly realized that i have some serious problems with angles in 3D. and judging by the topics in the forum… heck i am not the only one.
so, i decided to invest some of my time into an exercise: write a java applet that displays something (in the moment a “log”), that can be rotated either by angle axis, or by a rotational matrix, or by a quaternion, hopefully learning something about the topic in the process… in short, i learned loads, although mostly about different topics, not so much about angles (ironic, isn’t it?).
the fruits of my labor can be observed by anyone at, at least if your willing to to trust me far enough to give my applet the right to start an opengl thread:
http://www.myjavasite.cwsurf.de/
so anyone who did trust me far enough: thank you!
nevertheless, i am sure you quickly realized that some things are still behaving rather strangly: for instance while yaw and role seem to work fine, pitch produces some kind of problem when you intend to increase the value above pi/2. or if you increase the values of the quaternion, at some point the model simply plainly disappears…
anyone being able to shed some light on this weird behaviours, i would be very thankfull! you can find the entire source code in the jar file from which the applet is started, but i doubt that any sane person would go through the trouble, so let me just explain the gist about how i dealt with the angles so far:
from the values entered in either of the three systems (angle axes, rotational matrix or quaternion), i construct a quaternion (odd, isn’t it?)
Matrix3f m = new Matrix3f(
((SpinnerNumberModel) m11.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m12.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m13.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m21.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m22.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m23.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m31.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m32.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) m33.getModel()).getNumber().floatValue());
Quaternion quat = computeFromMatrix(m);
Quaternion quat = new Quaternion(
((SpinnerNumberModel) it.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) jt.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) kt.getModel()).getNumber().floatValue(),
((SpinnerNumberModel) rt.getModel()).getNumber().floatValue());</div>
public float[] computeAngles(Quaternion q) {
float[] v = new float[3];
q.toAngles(v);
return v;
}</div>
http://hub.jmonkeyengine.org/groups/gui/forum/topic/com-jme3-system-nullcontext-cannot-be-cast-to-com-jme3-system-jmecanvascontext-yet-another-swing-problem-from-a-jme-newbie/
so what do i do? in the jmonkey application i first apply the inverse of any former rotation that i might have been applied, then i apply the new rotation:
private void reverseOldRotation() {
this.n.rotate(this.oldRotation.inverse());
}</div>
for any idea, advice, reference that might help, i wouldf be very thankfull! of course any comment about the applet is also most welcome :)