OpenGL:在两个元素之间画线 [英] OpenGL: draw line between two elements

查看:135
本文介绍了OpenGL:在两个元素之间画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我创建的两个网格之间画一条线。每个网格与不同的模型矩阵相关联。我一直在想如何做到这一点,我想到了这一点:

I need to draw a line between two meshes I've created. Each mesh is associated with a different model matrix. I've been thinking on how to do this and I thought of this:

glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(first_object_model_matrix);
glBegin(GL_LINES);
glVertex3f(0, 0, 0); // object coord
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(first_object_model_matrix);
glVertex3f(0, 0, 0); // ending point of the line
glEnd( );

但问题是我无法调用 glMatrixMode glBegin glEnd 之间的$ c>和 glLoadMatrixf 。我也在使用着色器和可编程管道,所以我的场景转回到固定管道的想法并不令人兴奋。

But the problem is that I can't call glMatrixMode and glLoadMatrixf between glBegin and glEnd. I'm also using shaders and the programmable pipeline, so the idea of turning back to the fixed pipeline with my scene rendered isn't exciting.

你可以:


  • 建议我精确地描述如何在两个网格(我有它们的模型矩阵)和着色器之间绘制一条线。


  • 建议我如何编写类似上面的代码来绘制一行有两个网格模型矩阵。

推荐答案

通过乘以每一行来计算行的两个点与你的模型矩阵之一。以下是伪代码。由于您使用的是Qt,因此您可以使用其内置的数学库来实现此效果。

Calculate the line's two points by multiplying each one with one of your model matrices. The following is pseudo-code. Since you're using Qt, you could use its built-in maths libraries to accomplish this effect.

vec3 line_point_1 = model_matrix_object1 * vec4(0, 0, 0, 1);
vec3 line_point_2 = model_matrix_object2 * vec4(0, 0, 0, 1);
// Draw Lines

这篇关于OpenGL:在两个元素之间画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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