opengl斜投影

编程入门 行业动态 更新时间:2024-10-08 18:40:03
本文介绍了opengl斜投影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

你能告诉我什么是OpenGl步骤/功能,我

解决方案

我以前没有使用倾斜/骑士投影,但下面应该给你一个想法如何处理:

创建4x4剪切矩阵,

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

θ是X中的剪切,Φ是Y中的剪切, / p>

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

乘以正交投影乘以

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

(由left,right,bottom,top,near和far描述)

b $ b

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

然后,OpenGL允许你通过函数 glLoadMatrixf():

GLfloat proj [16] = {...}; glMatrixMode(GL_PROJECTION); //确保我们修改* projection * matrix glLoadMatrixf(proj); //加载投影

要深入了解OpenGL中的查看和转换如何工作,请参阅 OpenGL红皮书第3章。他们使用 glOrtho()创建和应用正投影。

编辑:

正如datenwolf指出的,记住OpenGL中的矩阵元素是以列为主的顺序指定的。 / p>

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?

解决方案

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 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: en.wikipedia/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.

更多推荐

opengl斜投影

本文发布于:2023-05-28 00:46:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/308213.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:opengl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!