使用 OpenGL ES,如何在 3D 空间中绘制一条两端始终与观察平面平行的扁平带(四边形)?
好吧,我确信这个标题令人困惑,但我们想做的事情实际上非常简单。为了解释计算,请考虑在 3D 空间中绘制一个圆柱体,并给出其中心线和直径的两个端点。现在,在屏幕平面上绘制其轮廓,但将两端对齐,使它们彼此平行并与屏幕平面平行。这就是我们需要的“外观”。
现在我们可以简单地做到这一点...用平面照明绘制一个圆柱体以获得这种效果。然而,由于我们实际上并未显示 3D 着色,因此计算构成圆柱体表面的所有三角形将完全是多余的。
从技术上讲,我们需要的只是一个四边形,或者最多两个三角形。如果概念圆柱体与屏幕平行,那么结果将只是一个矩形。如果圆柱体朝向或远离屏幕倾斜,则所得轮廓是一个简单的梯形。这是一个示例...
- A. 与屏幕平行,近
- B. 与屏幕平行,远
- C. 远离屏幕,从左上(近)到右下(远)
- D. 朝向屏幕,从左下角(远)到右上角(近)
我们想要做的基本上就是指定中心线的端点(红色)在 3D 空间中以及功能区的“宽度”。但要做到这一切,您不仅需要考虑 3D 空间中的端点,还需要考虑相机所在的位置,以确定如何使端点平行于观看平面,以免歪斜其宽度,然后在该点,您不妨回到变形圆柱体的裁剪轮廓!
那么有人可以建议一个好的、简单的方法来做到这一点吗?
Ok, I'm sure that title was confusing, but what we're trying to do is actually pretty simple. To explain the calculation, consider a cylinder drawn in 3D space given the two endpoints of its centerline and a diameter. Now draw its silhouette against the plane of the screen, but square off the ends so they are parallel with each other and to the screen's plane. That's the 'look' we need.
Now we could simply do exactly that... draw a cylinder with flat lighting to get this effect. However, since we're not actually displaying the 3D shading, calculating all of the triangles that makes up the surface of the cylinder would be complete overkill.
Technically, all we need is a single quad, or at most, two triangles. If the conceptual cylinder is parallel to the screen, then the result would just be a rectangle. If the cylinder is angled towards or away from the screen, then the resulting silhouette is a simple trapezoid. Here's an example...
- A. Parallel to the screen, close
- B. Parallel to the screen, far
- C. Angled away from the screen, top-left (near) to bottom-right (far)
- D. Angled towards the screen, bottom-left (far) to top-right (near)
All we would like to do is basically specify the end points of the center line (red) in 3D space along with the 'width' of the ribbon. But to do all of that, you need to not only take into consideration the endpoints in 3D space, but where the camera is too to determine how to make the ends parallel to the viewing plane as not to skew their width, and at that point, you may as well just go back to a cropped silhouette of a transformed cylinder!
So can anyone suggest a nice, simple way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将从一个具有您想要的线长和宽度的矩形开始,然后执行
正交投影
但这就是我。
或者你可以从你的飞机(相机)上取任何一条线。还有你的线段。这两个可以用来组成一个新的平面。然后计算这个新平面的法线。这将垂直于您的直线和平面。我想这就是你要找的。
I would start with a rectangle with the length of the line and the width you desire and perform a
orthogonal projection
but that's me.
Or you could take any line from your plane (camera). And your line segment. These two can be used to form a new plane. Then calculate the normal of this new plane. This will be perpendicular to both your line and your plane. I think that is what you're looking for.