Angled projection

I want to create an inclined (cavalier) projection in OpenGL. I know that this operation is not supported by default, and instead I need a shift matrix, and then do an orthogonal projection.

Can you tell me what steps / functions of OpenGl should I perform?

+6
source share
3 answers

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

Create a 4x4 shift matrix,

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

θ is the shift in X, Φ is the shift in Y, and Z is one.

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

Multiply this by your spelling projection,

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

(described left, right, bottom, top, closer and far)

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

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

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

For a deeper understanding of how viewing and transformations work in OpenGL, I would call you OpenGL Chapter 3 Red Book . There they use glOrtho () to create and apply spelling projection.

Edit:

As datenwolf points out, keep in mind that matrix elements in OpenGL are listed in the main column order.

+13
source

OpenGL allows you to define arbitrary projection matrices. Build the desired projection matrix yourself to display the incoming vertices in the range from -1 to 1 in each dimension, then load it with

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

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

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

Since the so-called oblique projection is obtained by rotating the projection plain to a certain angle from the right, which produces nothing but an elongated image along the axis of rotation, I think it’s enough to simply scale the normal orthogonal projector along this axis, in the coefficient \csc\theta . This statement can be confirmed by the trigonometry equalities, for example, \sin\theta+\cos\theta \cot\theta=\csc\theta . If your oblique forecast is given by \theta and \phi , as in luke's answer, the axis angle can be calculated as a trigonometry exercise based on these two angles, for example \arctan(\tan\theta\sqrt(1+\cot^2\phi))

0
source

Source: https://habr.com/ru/post/888838/


All Articles