PDA

View Full Version : Quaterion selective rotation

Sagaceil
02-15-2010, 10:32 AM
Hello,

I'm working on a game, and I found some trouble with World Editor - rotation of obiects. Only rotating of vector works and dunno how to implement rotating around that vector of obiect.

_rv[4] is _rv[0] - rotation angle , _rv[1..3] - vector of quaternion
cx - cy is how much we want to rotate ( in radians )

if( i == 0 &amp;&amp; rv ){ //rotacja pochylenia
Vector3f vec = RotateVector3f( _rv[1], _rv[2], _rv[3] , cx - cy );
vec . normalize();
quat = RotationQuaternion( vec , _rv[ 0 ] * Pidiv180 );
quat . normalize();
} else
if( i == 1 &amp;&amp; rv ){ // Rotation via OZ axis ony .. ???
Vector3f vec( _rv[1], _rv[2], _rv[3] );
vec . normalize();
quat = RotationQuaternion( vec , _rv[ 0 ] * Pidiv180 ); //( RotationQuaternion( vec , cy - cx ) * RotationQuaternion( kXaxis , (float)M_PI_2 ) ) * RotationQuaternion( vec , _rv[ 0 ] * Pidiv180 );
quat . normalize();
} else
if( i == 2 &amp;&amp; rv ){ // stopie&amp;#324; nachylenia
Vector3f vec( _rv[1], _rv[2], _rv[3] );
vec . normalize();
quat = RotationQuaternion( vec , _rv[ 0 ] * Pidiv180 + ( cx - cy ) );
quat . normalize();
}

Image to ilustrate:
http://img704.imageshack.us/img704/3734/beztytuuexd.png

X - Blue ( i == 0 )
Y - Green ( i == 1 ) ?? We are looking it ??
Z - Red ( i == 2 )

Rotating X we rotate also Z one. If someone has an idea how to compute the Y one, please write. Thanks.

Sagaceil
02-15-2010, 11:45 AM
[ SOLVED ]

Matrix4x4f matrix; // obrót obiektu wzgl&amp;#281;dem nachylenie .. ???

glPushMatrix();