简体   繁体   English

不论相机位置如何,均以相同大小渲染3D模型

[英]Render a 3D model with the same size regardless of camera position

I've got a particular model that acts as controls in the viewer. 我有一个在查看器中充当控件的特定模型。 The user can click on different parts of it to perform transformations on another model in the viewer (like controls/handles in applications like Unity or Blender). 用户可以单击它的不同部分以对查看器中的另一个模型(例如Unity或Blender等应用程序中的控件/句柄)执行转换。

We'd like the controls to remain the same size regardless how zoomed in/out the camera is. 我们希望控件保持相同的大小,而不管相机的放大/缩小程度如何。 I've tried scaling the size of it based on the distance between the object and the camera but it isn't quite right. 我试过根据物体和相机之间的距离缩放它的大小,但这并不完全正确。 Is there a standard way of accomplishing something like this? 是否有完成这种事情的标准方法?

The controls are rendered using the fixed pipeline, but we've got other components using the programmable pipeline. 控件是使用固定管线呈现的,但是我们还有其他组件使用可编程管线。

With the fixed pipeline, the easiest way to do this is to simply not apply any transformations when you render the controls: 使用固定管道,最简单的方法是在呈现控件时不应用任何转换:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

// draw controls

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

The glPushMatrix() / glPopMatrix() calls will make sure that the previous matrices are restored at the end of this code fragment. glPushMatrix() / glPopMatrix()调用将确保在此代码片段的末尾恢复以前的矩阵。

With no transformation at all, the range of coordinates mapped to the window will be [-1.0 .. 1.0] in both coordinate directions. 完全不进行任何变换,在两个坐标方向上映射到窗口的坐标范围将为[-1.0 .. 1.0]。 If you need anything else, you can apply the necessary transformations before you start drawing the controls. 如果您还有其他需要,可以在开始绘制控件之前应用必要的转换。

The easy answer is "use the programmable pipeline" because it's not that difficult to write 简单的答案是“使用可编程管道”,因为编写起来并不难

if(normalObject) {
    gl_Position = projection * view * model * vertex;
} else {
    gl_Position = specialMVPMatrix * vertex;
}

Whereas you'll spend a lot more code trying to get this to work in the Fixed-Function-Pipeline and plenty more CPU cycles rendering it. 而您将花费更多的代码来尝试使其在“固定功能管道”中运行,并且需要更多的CPU周期来呈现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM