Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quaternion object rotation

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)).

like image 741
user2282428 Avatar asked Dec 06 '25 00:12

user2282428


1 Answers

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.

like image 73
Delyan Avatar answered Dec 08 '25 14:12

Delyan