在 OpenGL 中绘制一个广告牌四边形

发布于 2024-09-16 19:12:45 字数 60 浏览 2 评论 0原文

我正在开发一个游戏引擎,我希望能够绘制一个广告牌(即屏幕上的矩形)四边形,该四边形的中心底部由一个点确定。

I'm working on a game engine, and I want to be able to draw a billboarded (i.e. rectangular to the screen) quad with the center-bottom of the quad being determined by a single point.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-09-23 19:12:46

在OpenGL中,有变换矩阵的概念。它们控制屏幕上对​​象的位置。从它们中,可以读取指向“向上”和“向右”的向量(方向)。这些通常称为上矢量和右矢量(第三个可能称为外观矢量)。 此处描述了如何获取它们

一旦你拥有了它们,制作一个广告牌四边形就非常简单了。

P - right * .5 + up
+-------------+ P + right * .5 + up
|             |
|             |
|             |
|      P      |
+------+------+ P + right * .5
P - right * .5

这些是坐标(P 是控制位置,位于 BB 的底部中心)。您可以像绘制任何其他四边形一样绘制这样的四边形。

In OpenGL, there is the concept of transformation matrices. These govern the positioning of the objects on the screen. From them, it is possible to read vectors (directions) that point "up" and "right". These are commonly called up-vector and right-vector (and the third may be called look-vector). How to get them is described here.

Once you have them, making a billboarded quad is very simple.

P - right * .5 + up
+-------------+ P + right * .5 + up
|             |
|             |
|             |
|      P      |
+------+------+ P + right * .5
P - right * .5

These are the coordinates (P is the governing position, at the bottom center of your BB). You can draw such quad the same way as any other quad.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文