我正在使用openTk做我的第一个项目。我正在为3D模型旋转创建虚拟的arcball。它工作得很好,但我需要添加不会随模型旋转的圆。这个圆应该是arcball的可视化图形。我实现旋转的代码是:
private void SetCamera()
{
GL.MatrixMode(MatrixMode.Modelview);
Matrix4 scale = Matrix4.Scale(magnification / diameter);
Matrix4 translation1 = Matrix4.CreateTranslation(-center);
Matrix4 rotation = Matrix4.CreateFromAxisAngle(axisOfRotation, angleOfRotation*(float)numericSensitivity.Value);
Matrix4 translation2 = Matrix4.CreateTranslation(0.0f, 0.0f, -1.5f);
if (rotationChanged)
{
oldRotation *= rotation;
rotationChanged = false;
}
modelview = translation1 * scale * oldRotation * translation2;
GL.LoadMatrix(ref modelview);
}所以我想问一下,有没有什么方法可以画出不受旋转影响的圆(在屏幕上的相同位置)。
发布于 2012-03-04 15:34:19
如果我没理解错你的问题,那么你所需要做的就是在画圆之前将模型视图矩阵重新设置为身份。您可以使用PushMatrix()和PopMatrix()函数轻松完成此操作。如下所示:
//Draw normal things
GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();
//Draw un-rotated circle
GL.PopMatrix();PushMatrix()将当前矩阵保存到堆栈中,PopMatrix()从该堆栈中弹出顶部矩阵。这意味着PopMatrix()将把你带回你的正常旋转的参考系,在你完成了圆。
https://stackoverflow.com/questions/8568674
复制相似问题