Since few days I'm trying to implement quaternion rotation for android OpenGL ES. I would like to get function with input quaternion(x,y,z,w). This function will be set rotation for GL10 object. GL10 object have only gl.glRotatef(y, 1.0f, 0.0f, 0.0f) function providing setting position in Euler angles. I tried that class https://github.com/TraxNet/ShadingZen/blob/master/library/src/main/java/org/traxnet/shadingzen/math/Quaternion.java to create Matrix but it still don't work. I would be grateful if someone could show/write how to set position of GL10 object by putting as parameter quaternion(GL10setRotation(Quaternion q)).
glRotatef is just a multiplication of the current matrix with a rotation matrix (plus associated boundary checks).
One way to do this in OpenGL 1 (using the linked Quaternion class) is:
Matrix rotation = new Matrix();
quaternion.toMatrix(rotation);
glMultMatrixf(rotation.getAsArray(), 0);
Do note that glRotate and glTranslate are slower than doing the Matrix math yourself and using glLoadMatrix. In general, if performance is important, I'd advise against using OpenGL 1 entirely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With