OpenGl:围绕端点旋转线 [英] OpenGl : Rotate line about endpoint

查看:677
本文介绍了OpenGl:围绕端点旋转线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenGL的新手,并尝试了一些实验代码。我使用Open GL 4+。我可以用这样绘制一行:

I'm new to OpenGL , and trying out some experimental code. I'm using Open GL 4+ . I was able to draw a line using this :

    glBegin(GL_LINES);
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(1.0,1.0,0.0);
    glEnd();

现在我想绕着它的一个端点旋转这条线,就像时钟的手。我该怎么做呢?我在线搜索,但没有什么实际演示简单的线旋转。我尝试使用 glRotatef 但我想我错过了一些关键的事情,因为 glRotatef 没有影响绘制的线。所有教程似乎都以三角形(而不是点和线)开头

Now I want to rotate this line about one of it's endpoints, like the hand of a clock. How do I go about doing this? I've searched online, but there's nothing that actually demonstrates simple line rotation. I tried using glRotatef but I think I'm missing out on some key thing, because the glRotatef had no effect on the line drawn. All tutorials seem to start with Triangles (not points and lines)

什么是OpenGL工作流程做这些事情?我不断地遇到使用矩阵的示例代码,但是我没有完全达到目的。我的意思是,我必须明确跟踪我的最新矩阵,或者被OpenGL抽象化,并在内部照顾?

What is the OpenGL workflow for doing these things? I keep coming across sample code where matrices are being used, but I don't exactly get the purpose.. I mean, do I have to explicitly keep track of my latest matrices, or is abstracted away by OpenGL and internally taken care of?

我理解了转换矩阵的数学和作用,但我对于矩阵在编写OpenGL代码中的作用感到困惑。如果有像 glRotatef 这样的函数,为什么要明确指定矩阵?

I understand the math and the role of transformation matrices, but I'm getting confused about the matrices' role in writing OpenGL code. If there are functions like glRotatef , why explicitly specify matrices?

有一些资源可以解释一切从基本的点,线,然后多边形等

It'd be really helpful to have some resources that explain everything from the very basic - points, lines then polygons etc

推荐答案

标准免责声明:不要使用glBegine / glEnd系列函数,而是迁移到基于着色器的设置。

standard disclaimer: don't use glBegine/glEnd family of functions instead migrate to the shader based setup.

但这里是旋转的方法(省略参数)

but here is the way to rotate (left out the parameters)

glPushMatrix();
glTranslate();//tranlate by -p where p is the point you want to rotate about
glRotate();//rotate by some degrees
glTranslate();//tranlate back by p

glBegin(GL_LINES);
glVertex3f(0.0,0.0,0.0);
glVertex3f(1.0,1.0,0.0);
glEnd();

glPopMatrix();

这篇关于OpenGl:围绕端点旋转线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆