Skip to main content
gamedev.net
🔒 Locked

View matrix setup

Started by gio 2 replies 750+ views
Original Post
gio
gio
There-s been an article, "360 degree rotation..HELP" a long time ago, posted by Jehsup. The fragment of code posted was: void CAMERA::ComputeNewView( float deltaTime ) { if( ( Yaw>=360.0f) || ( Yaw<=-360.0f ) ) Yaw = 0.0f; if( ( Pitch>=360.0f) || ( Pitch<=-360.0f ) ) Pitch = 0.0f; if( ( Roll>=360.0f) || ( Roll<=-360.0f ) ) Roll = 0.0f; float cosYaw = (float)cosf( DEG_TO_RAD( Yaw ) ); float sinYaw = (float)sinf( DEG_TO_RAD( Yaw ) ); float sinPitch= (float)sinf( DEG_TO_RAD( Pitch ) ); float cosPitch= (float)cosf( DEG_TO_RAD( Pitch ) ); float cosRoll = (float)cosf( DEG_TO_RAD( Roll ) ); float sinRoll = (float)sinf( DEG_TO_RAD( Roll ) ); vecForward[0]= sinYaw; vecForward[1]= sinPitch; vecForward[2]= cosPitch * -cosYaw; vecForward.Normalize(); vecUp[0] = sinRoll; vecUp[1] = cosRoll * cosPitch; vecUp[2] = sinPitch; vecUp.Normalize(); vecSide= vecForward.CrossProduct( vecUp ); vecSide.Normalize(); vecLookAt= vecEyePos + vecForward; //check DOT Product outputs are 90 degrees apart dot_up_side = m_vecUp.DotProduct(vecSide); dot_up_forward = m_vecUp.DotProduct(vecForward); dot_forward_side = m_vecForward.DotProduct(vecSide); }// end CCAMERA::ComputeNewView What i am interested is what are the math formula for: vecForward[0]= sinYaw; vecForward[1]= sinPitch; vecForward[2]= cosPitch * -cosYaw; vecForward.Normalize(); vecUp[0] = sinRoll; vecUp[1] = cosRoll * cosPitch; vecUp[2] = sinPitch; I also know that the rotation matrix is calculated like the rotation around all the three axes: [Cf] = Rz * Ry * Rx * [C] => „¡ „¢ „¡ „¢„¡ „¢„¡ „¢„¡ „¢ „ xf „ = „ cz -sz 0 0 „ „ cy 0 sy 0 „ „ 0 0 0 0 „ „ x „ „ yf „ „ sz cz 0 0 „ „ 0 1 0 0 „ „ 0 cx -sx 0 „ „ y „ „ zf „ „ 0 0 1 0 „ „ -sy 0 cy 0 „ „ 0 sx cx 0 „ „ z „ „ 1 „ „ 0 0 0 1 „ „ 0 0 0 1 „ „ 0 0 0 1 „ „ 1 „ „¤ „£ „¤ „£„¤ „£„¤ „£„¤ „£ „¡ „¢ „¡ „¢„¡ „¢ „ xf „ = „ cy*cz sx*sy*cz-cx*sz cx*sy*cz+sx*sz 0 „ „ x „ „ yf „ „ cy*sz sx*sy*sz+cx*cz cx*sy*sz-sx*cz 0 „ „ y „ „ zf „ „ -sy sx*cy cx*cy 0 „ „ z „ „ 1 „ „ 0 0 0 1 „ „ 1 „ „¤ „£ „¤ „£„¤ „£ I do not understand, if vecForward is against z axis, and the vecUp is along y axis, it does not make sense to me. Thank you for any help, in advance.
gio
gio
Sorry, the formula written above were supposed to be:

[C_ ] = Rz * Ry * Rx * [C]

[ x_ ] = [ cz -sz 0 0 ][ cy 0 sy 0 ][ 0 0 0 0 ][ x ]
[ y_ ] [ sz cz 0 0 ][ 0 1 0 0 ][ 0 cx -sx 0 ][ y ]
[ z_ ] [ 0 0 1 0 ][-sy 0 cy 0 ][ 0 sx cx 0 ][ z ]
[ 1 ] [ 0 0 0 1 ][ 0 0 0 1 ][ 0 0 0 1 ][ 1 ]

[ x_ ] = [ cy*cz sx*sy*cz-cx*sz cx*sy*cz+sx*sz 0 ][ x ]
[ y_ ] [ cy*sz sx*sy*sz+cx*cz cx*sy*sz-sx*cz 0 ][ y ]
[ z_ ] [ -sy sx*cy cx*cy 0 ][ z ]
[ 1 ] [ 0 0 0 1 ][ 1 ]


relsoft
relsoft
Vec_forward is the vector you are facing into and vec_up is the projected up vector(perpendicular to the plane you are standing on).

Haven't looked much of the code but try to plug those vectors on the gluLookat function to see the results.

Hi.
gio
gio

Thanks, i do not have code for mouse input yet, but i am working on it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.