0
我用下面的代码来绘制我的圈子:OpenGL的圆圈旋转
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();
的问题是,当将scaleX从不同的scaleY圈,然后在除旋转以正确的方式转化。 在我的代码序列如下:
circle.Scale(tmp_p.scaleX, tmp_p.scaleY);
circle.Rotate(tmp_p.rotateAngle);
我的问题是什么其他的计算,我应该为圆正常转动时执行的scaleX和scaleY不相等?
alt text http://www.freeimagehosting.net/uploads/c0cfc89146.gif
被streched为红线的圆圈显示,当acctually我希望它用绿线进行streched。
旋转功能:
double cosFi = Math.Cos(angle*Math.PI/180.0);
double sinFi = Math.Sin(angle * Math.PI/180.0);
double x, y;
double newX = 0, newY = 0;
DVector center = objectSize.CenterPoint;
y = ((MCircleCmd)cmdList[i]).m_Y;
x = ((MCircleCmd)cmdList[i]).m_X;
newX = (x - center.shiftX) * cosFi - (y - center.shiftY) * sinFi + center.shiftX;
newY = (x - center.shiftX) * sinFi + (y - center.shiftY) * cosFi + center.shiftY;
((MCircleCmd)cmdList[i]).m_X = newX;
((MCircleCmd)cmdList[i]).m_Y = newY;
UpdateSize(ref firstMove, newX, newY);
量表功能:
public void Scale(double scale) // scale > 1 - increase; scale < 1 decrease
{
if (!isPrepared) return;
objectSize.x1 *= scale;
objectSize.x2 *= scale;
objectSize.y1 *= scale;
objectSize.y2 *= scale;
((MCircleCmd)cmdList[i]).m_X *= scale;
((MCircleCmd)cmdList[i]).m_Y *= scale;
((MCircleCmd)cmdList[i]).m_R *= scale;
((MCircleCmd)cmdList[i]).scaleX = scale;
((MCircleCmd)cmdList[i]).scaleY = scale;
}
您没有向我们展示比例和旋转功能。我猜Scale函数设置scaleX/Y,但是Rotate做什么? – Skizz 2010-06-10 13:58:44
这个问题并不清楚。 “除了旋转之外,”圈子以正确的方式转化“。那是什么错误?该问题的绘制将是有用的。 – tafa 2010-06-10 14:00:21
你能发表问题的图片吗? – 2010-06-10 19:24:03