Convert modelMatrix

It is easy to install ViewMatrix with glm:

glm::lookAt(Position, Direction, UpVector);

but if I try to use funktion with modelMatrix, I get the comfusing values ​​(the model is not in the right position, and the rotation also looks wrong). I just want to set the object in the same way as installing the camera. Can I use the lookAt function and make some changes after that? Or do I need to program my own function for this? And if so, how?

I fixed the position as follows:

m_Orientation = glm::lookAtLH(Position, Direction, UpVector);
m_Orientation[3][0] = -m_Orientation[3][0];
m_Orientation[3][1] = -m_Orientation[3][1];
m_Orientation[3][2] = -m_Orientation[3][2];

also inside vertexshader I use this:

gl_Position = CameraMatrix * ModelMatrix * Pos;

where CameraMatrix is ​​viewProjectionMatrix, ModelMatrix (my problem), and Pos is the position of my vertex in the model space

0
source share
1 answer

, . : .

( )

- , . .

:.

model coordinates

- . () .

, (, ) . . , () wolrd.

:

( X-axis.x, X-axis.y, X-axis.z, 0 )
( Y-axis.x, Y-axis.y, Y-axis.z, 0 )
( Z-axis.x, Z-axis.y, Z-axis.z, 0 )
( trans.x,  trans.y,  trans.z,  1 )

:.

(  0.0, -0.5,  0.0,  0.0 )
(  2.0,  0.0,  0.0,  0.0 )
(  0.0,  0.0,  1.0,  0.0 )
(  0.4,  0.0,  0.0,  1.0 )

model to world

sapce ( )

- , . , . , "" . view.

, . wolrd ().

- Right-hand, X , Y Z ( Z-Axis X- Y).

view coordinates

. .
, x, y z , w w :

-w <=  x, y, z  <= w.

, . . (NDC) (-1, -1, -1) (1, 1, 1) w .

:.

: (2,5, -1,5, 3,5), (2, 0, 0), (0, 1, 0)

: (y) 100 °, 0,1, 20,0

perspective projection

- , w .

normalized device coordinates

( )

- . , , .

( ) . glViewport. glDepthRange [0, 1].

+1

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


All Articles