OpenTK 圆旋转

发布于 2024-12-21 21:56:14 字数 766 浏览 3 评论 0原文

我正在使用 openTk 开发我的第一个项目。我正在创建用于 3D 模型旋转的虚拟轨迹球。它工作正常,但我需要添加不会随模型旋转的圆圈。这个圆圈应该可视化轨迹球。 我实现旋转的代码是:

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);
}

所以我想问是否有某种方法如何绘制圆圈,它不会受到这种旋转的影响(将在屏幕上的相同位置)。

I'm working on my first project using openTk. I'm creating virtual arcball for 3D model rotation. It works fine, but I need to add circle which won't rotate with model. This circle should visualize arcball.
My code to achieve rotation is:

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);
}

So I would like to ask if there is some way how to draw circle, which wil be unaffected by this rotattion (will be on same position on a screen).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹梦 2024-12-28 21:56:14

如果我正确理解你的问题,那么你需要做的就是在绘制圆圈之前将模型视图矩阵设置回恒等式。您可以使用 PushMatrix() 和 PopMatrix() 函数轻松地做到这一点。像这样:

//Draw normal things

GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();

//Draw un-rotated circle

GL.PopMatrix();

PushMatrix() 将当前矩阵保存到堆栈中,PopMatrix() 将顶部矩阵从堆栈中弹出。这意味着在完成圆之后,PopMatrix() 将带您回到正常的旋转参考系。

If I understand your question correctly, then all you need to do is set the modelview matrix back to the identity before you draw your circle. You can easily do that using the PushMatrix() and PopMatrix() functions. Something like this:

//Draw normal things

GL.MatrixMode(MatrixMode.Modelview);
GL.PushMatrix();
GL.LoadIdentity();

//Draw un-rotated circle

GL.PopMatrix();

PushMatrix() saves the current matrix onto a stack, and PopMatrix() pops the top matrix off of that stack. This means PopMatrix() will take you back to your normal rotated frame of reference after you're done with the circle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文