Rotation with Quaternion

I have tried to rotate the position of teh vertex over an axis in 3d. But with no success. So I read some topics about programming quaternions and so on, but I didn’t find the mistake in my code. :frowning:
My shader is still running, but the newPos isn’t there where it habe to be …

Maybe someone knows where the code is wrong …

vec4 mult (vec4 qa, vec4 qb)
	vec4 result;
	result.w   = qa.w * qb.w   - dot(,; = cross (, + ( * qb.w) + ( * qa.w);

	return (result);

vec3 rotate (vec3 vector, vec3 axis, float angle)
	axis = normalize(axis);
	float sin_a = sin(angle/2.0);
	float cos_a = cos(angle/2.0);

	vec4 quaternion;
	quaternion.x = axis.x * sin_a;
	quaternion.y = axis.y * sin_a;
	quaternion.z = axis.z * sin_a;
	quaternion.w = cos_a;
	quaternion   = normalize(quaternion);

	vec4 rotVector = mult (quaternion, vec4 (vector.x, vector.y, vector.z, 0.0));
	rotVector      = mult (rotVector, vec4 (-quaternion.x, -quaternion.y, -quaternion.z, quaternion.w));

	return (;

// In Application:

vec4 newPos = vec4(rotate(, axis, 30.0), 1.0);
gl_Position = gl_ModelViewProjectionMatrix * vec4(, 1.0);

The old Position and the axis is wright, I’ve proofed this a several times. But why doesn’t this work? :confused:

Your angle appears to be in degrees, but sin() and cos() expects radians.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.