问题描述
我需要在我创建的两个网格之间画一条线。每个网格与不同的模型矩阵相关联。我一直在想如何做到这一点,我想到了这一点:
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:在两个元素之间画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!