Jump to content
  • Advertisement
Sign in to follow this  
rakoon2

Matrix2.RotateClockWise rotates the matrix counterclockwise after some time..

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I have a problem with my Matrix2.RotateClockWise( angle ) method! It works perfectly for a while. But it changes from clockwise rotation to countercockwise rotation after ~ 2/3 * PI. Itthen changes back to clockwise after ~2/3 * PI. Why? =§ Here the pseudo function:
cos = cos(angle);
sin = sin(angle);

rotmat = [ cos -sin ]
         [ sin cos  ]

newRotatedMatrix = oldMatrix * rotmat;


Maybe my drawing code is wrong.. or the function that produces the angle of a matrix2. ( I will post the source code a lil bit later ) Angle method: Returns the angle to the identity matrix.

return Acos(  m00 / sqrt( m00² + m01² ) )

Thank you guys! :)

Share this post


Link to post
Share on other sites
Advertisement

Okay :) This is my other account(wasn't at home yesterday), so don't be scared! XD


Problem:

Here the full C# code:
(I have to use a calculator for add/subs bcs the matrix is generic. )


#region RotateClockWise( Type angle )

/// <summary> Rotates the matrix for the given angle.(radiants)</summary>
/// <param name="angle"></param>
public void RotateClockWise( Type angle )
{
Type cos = calc.Cos( angle );
Type sin = calc.Sin( angle );

Matrix2<Type, Calc> rotM = new Matrix2<Type, Calc>(

cos, sin,
calc.Negate( sin ), cos
);

this = this * rotM ; // Tried this = rotM * this; too- no difference.
}

#endregion RotateClockWise( Type angle )





#region Angle

/// <summary> Returns the angle to the Idendity-Matrix. </summary>
/// <returns></returns>
public Type Angle
{
get
{
return calc.Acos(
calc.Div( m00, calc.Sqrt(
calc.Add( calc.Mul( m00, m00 ), calc.Mul( m01, m01 ) )))
);
}
}

#endregion Angle





Used render- function:

#region RenderPolygon( Polygon2<float, FloatCalc> poly, Vector2<float, FloatCalc> position, ..

/// <summary> Renders the given polygon. </summary>
/// <param name="poly"></param>
/// <param name="position"></param>
/// <param name="angle"></param>
/// <param name="fillA"></param>
/// <param name="fillR"></param>
/// <param name="fillG"></param>
/// <param name="fillB"></param>
/// <param name="lineA"></param>
/// <param name="lineR"></param>
/// <param name="lineG"></param>
/// <param name="lineB"></param>
public void RenderPolygon( Polygon2<float, FloatCalc> poly, Vector2<float, FloatCalc> position,
float angle, byte fillA, byte fillR, byte fillG, byte fillB,
byte lineA, byte lineR, byte lineG, byte lineB )
{
if( poly == null ) return;

#region Point

// deleted for you guys. (not important)

#endregion Point

Gl.glMatrixMode( Gl.GL_MODELVIEW );
Gl.glPushMatrix();

Gl.glTranslatef( position.x, position.y, 0.0f );

Gl.glRotatef( Math.Utilities.RadiansToDegrees( angle ), 0.0f, 0.0f, -1.0f );

Gl.glColor4ub( fillR, fillG, fillB, fillA );
Gl.glBegin( Gl.GL_TRIANGLE_FAN );

for( int i = 0; i < numVertices; ++i )
{
Gl.glVertex2f( vertices.x, vertices.y );
}
Gl.glVertex2f( vertices[0].x, vertices[0].y );
Gl.glEnd();


Gl.glColor4ub( lineR, lineG, lineB, lineA );

Gl.glBegin( Gl.GL_LINE_LOOP );

for( int i = 0; i < numVertices; ++i )
{
Gl.glVertex2f( vertices.x, vertices.y );
}
Gl.glVertex2f( vertices[0].x, vertices[0].y );
Gl.glEnd();

Gl.glPopMatrix();
}

#endregion RenderPolygon( Polygon2<float, FloatCalc> poly, Vector2<float, FloatCalc> position, ..






And I call the functions like this:


m1.Rotate( 0.001f );
renderer.RenderPolygon( poly1, pos1, m1.Angle, 0, 30, 200, 10, 10, 80, 100, 189 );






Hope you guys can help me.

Thank you very much!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!