Vexator

02-06-2007, 03:18 AM

hi!

i'm using quaternions to simulate rotations. now i need to multiply a vector by a quaternion in a vertex shader:

vec3 MultiplyVectorByQuaternion( vec3 vector, vec4 quaternion )

{

vec3 kVector1 = vec3( quaternion.x, quaternion.y, quaternion.z );

vec3 kVector2 = cross( kVector1, vector );

kVector2 += vector*quaternion.w;

vec3 kVector3 = cross( kVector2, kVector1 );

kVector1 *= vector*kVector1;

kVector1 += kVector2*quaternion.w;

return vec3( kVector1-kVector3 );

}this works fine but i guess there are better ways to do it - is there a chance that i can take advantage of glsl's built-in functions to do such calculations?

i'm using quaternions to simulate rotations. now i need to multiply a vector by a quaternion in a vertex shader:

vec3 MultiplyVectorByQuaternion( vec3 vector, vec4 quaternion )

{

vec3 kVector1 = vec3( quaternion.x, quaternion.y, quaternion.z );

vec3 kVector2 = cross( kVector1, vector );

kVector2 += vector*quaternion.w;

vec3 kVector3 = cross( kVector2, kVector1 );

kVector1 *= vector*kVector1;

kVector1 += kVector2*quaternion.w;

return vec3( kVector1-kVector3 );

}this works fine but i guess there are better ways to do it - is there a chance that i can take advantage of glsl's built-in functions to do such calculations?