OpenGL circle rotation

Posted by user350632 on Stack Overflow See other posts from Stack Overflow or by user350632
Published on 2010-06-10T13:43:25Z Indexed on 2010/06/10 14:52 UTC
Read the original article Hit count: 225

Filed under:
|

I'm using following code to draw my circles:

double theta = 2 * 3.1415926 / num_segments; 
double c = Math.Cos(theta);//precalculate the sine and cosine
double s = Math.Sin(theta);
double t;
double x = r;//we start at angle = 0 
double y = 0;

GL.glBegin(GL.GL_LINE_LOOP); 
for(int ii = 0; ii < num_segments; ii++) 
{
    float first = (float)(x * scaleX + cx) / xyFactor;
    float second = (float)(y * scaleY + cy) / xyFactor;

    GL.glVertex2f(first, second); // output Vertex 

    //apply the rotation matrix
t = x;
x = c * x - s * y;
y = s * t + c * y;
} 
GL.glEnd();

The problem is that when scaleX is different from scaleY then circles are transformed in the right way except for the rotation. In my code sequence looks like this:

circle.Scale(tmp_p.scaleX, tmp_p.scaleY);
circle.Rotate(tmp_p.rotateAngle);

My question is what other calculations should i perform for circle to rotate properly when scaleX and scaleY are not equal?

© Stack Overflow or respective owner

Related posts about c#

Related posts about opengl