opengl斜投影 [英] opengl oblique projection

查看:215
本文介绍了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 < a href =http://www.cs.unm.edu/~angel/CS433/lectURES/CS433_17.pdf> http://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: http://en.wikipedia.org/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 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.

这篇关于opengl斜投影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆