opengl斜投影

发布于 2024-11-08 20:46:54 字数 101 浏览 0 评论 0原文

我想在 OpenGL 中创建一个倾斜(骑士)投影。我知道默认不支持此操作,而是我需要一个剪切矩阵,然后进行正交投影。

你能告诉我我必须执行哪些 OpenGL 步骤/功能吗?

I want to create a oblique (cavalier) projection in OpenGL. I know this operation is not default supported and instead I need a Shear Matrix and then make an Orthogonal Projection.

Can you tell me what are the OpenGl steps / functions that I have to make?

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

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

发布评论

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

评论(3

心作怪 2024-11-15 20:46:54

我之前没有使用过倾斜/骑士投影,但以下内容应该可以让您了解如何继续:

创建一个 4x4 剪切矩阵,

H(θ, Φ) = | 1, 0, -cot(θ), 0 |
          | 0, 1, -cot(Φ), 0 |
          | 0, 0,    1,    0 |
          | 0, 0,    0,    1 |

θ 是 X 中的剪切,Φ 是 Y 中的剪切,Z 单独保留。

参考:http://www.cs.unm 的幻灯片 11。 edu/~angel/CS433/LECTURES/CS433_17.pdf

将其乘以正交投影

| 2/(r-l),     0,       0,    -(r+l)/(r-l) |
|    0,    2/(t-b),     0,    -(t+b)/(t-b) |
|    0,        0,    2/(f-n), -(f+n)/(f-n) |
|    0,        0,       0,          1      |

(由左、右、下、上、近和远描述)

(参考:http://en.wikipedia.org/wiki/Orthographic_projection_%28geometry%29)

OpenGL 然后允许您上传通过函数 glLoadMatrixf() 直接(作为 16 个浮点数的数组)该矩阵

GLfloat proj[16] = { ... };
glMatrixMode(GL_PROJECTION);  // Make sure we're modifying the *projection* matrix
glLoadMatrixf(proj);          // Load the projection

要更深入地了解 OpenGL 中的查看和转换如何工作,我建议您参考 OpenGL“红皮书”第3章。他们使用 glOrtho() 来创建和应用正交投影。

编辑:

正如 datenwolf 指出的那样,请记住 OpenGL 中的矩阵元素是按列主要顺序指定的。

I've not used a oblique/cavalier projection before, but the following should give you an idea of how to proceed:

Create a 4x4 shear matrix,

H(θ, Φ) = | 1, 0, -cot(θ), 0 |
          | 0, 1, -cot(Φ), 0 |
          | 0, 0,    1,    0 |
          | 0, 0,    0,    1 |

θ being the shear in X, Φ being the shear in Y, and Z being left alone.

(ref: slide 11 of http://www.cs.unm.edu/~angel/CS433/LECTURES/CS433_17.pdf)

Multiply that by your orthographic projection,

| 2/(r-l),     0,       0,    -(r+l)/(r-l) |
|    0,    2/(t-b),     0,    -(t+b)/(t-b) |
|    0,        0,    2/(f-n), -(f+n)/(f-n) |
|    0,        0,       0,          1      |

(described by, left, right, bottom, top, near and far)

(ref: http://en.wikipedia.org/wiki/Orthographic_projection_%28geometry%29)

OpenGL then allows you to upload this matrix directly (as an array of 16 floats) via the function glLoadMatrixf():

GLfloat proj[16] = { ... };
glMatrixMode(GL_PROJECTION);  // Make sure we're modifying the *projection* matrix
glLoadMatrixf(proj);          // Load the projection

For a more in depth look at how viewing and transformations work in OpenGL, I'd refer you to Chapter 3 of the OpenGL "Red Book". There they use glOrtho() to create and apply an orthographic projection.

Edit:

As datenwolf points out, bear in mind that the matrix elements in OpenGL are specified in column major order.

二手情话 2024-11-15 20:46:54

OpenGL 允许您指定任意投影矩阵。自己构造所需的投影矩阵,将传入的顶点映射到每个维度的 -1 到 1 范围内,然后使用

GLfloat custrom_projection[16] = {
     ...
};
glMatrixMode(GL_PROJECTION);
glLoadMatrix(custom_projection);

OpenGL 按列主顺序索引矩阵元素来加载它,即

0   4   8   12
1   5   9   13
2   6  10   14
3   7  11   15

OpenGL allows you to specify arbitrary projection matrices. Construct the desired projection matrix yourself to map the incoming vertices into the range -1 to 1 in each dimension, then load it using

GLfloat custrom_projection[16] = {
     ...
};
glMatrixMode(GL_PROJECTION);
glLoadMatrix(custom_projection);

OpenGL indexes the matrix elements in colum major order, i.e.

0   4   8   12
1   5   9   13
2   6  10   14
3   7  11   15
不及他 2024-11-15 20:46:54

由于所谓的倾斜投影是通过将投影平面从右侧旋转一定角度来获得的,这只会产生沿旋转轴的拉长图像,因此我认为只需沿该轴缩放法线正交投影就足够了,乘以\csc\theta。这个说法可以通过三角等式来证明,例如,\sin\theta+\cos\theta \cot\theta=\csc\theta。如果您的倾斜投影是由 \theta\phi 指定的,就像卢克的答案一样,则可以根据这两个角度将轴角度计算为三角函数练习,例如, \arctan(\tan\theta\sqrt(1+\cot^2\phi))

Since the so-called oblique projection is obtained by rotating the projection plain by a certain angle away from the right one, which produces nothing but a lengthened image along the rotation axis, I think it suffices to just scale the normal orthogonal projection along that axis, by a factor of \csc\theta. This claim can be proven by trigonometry equalities, e.g., \sin\theta+\cos\theta \cot\theta=\csc\theta. If your oblique projection is specified by the \theta and \phi like in luke's answer, the axis angle can be computed as a trigonometry exercise based on this two angles, say, \arctan(\tan\theta\sqrt(1+\cot^2\phi)).

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