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

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

## 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 on other sites
Yeah, gotta see more about what you're doing to say what's happening here.

##### Share on other sites

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!

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632961
• Total Posts
3009494
• ### Who's Online (See full list)

There are no registered users currently online

×