<tfoot id='ZcGBE'></tfoot>
  1. <legend id='ZcGBE'><style id='ZcGBE'><dir id='ZcGBE'><q id='ZcGBE'></q></dir></style></legend>

    <i id='ZcGBE'><tr id='ZcGBE'><dt id='ZcGBE'><q id='ZcGBE'><span id='ZcGBE'><b id='ZcGBE'><form id='ZcGBE'><ins id='ZcGBE'></ins><ul id='ZcGBE'></ul><sub id='ZcGBE'></sub></form><legend id='ZcGBE'></legend><bdo id='ZcGBE'><pre id='ZcGBE'><center id='ZcGBE'></center></pre></bdo></b><th id='ZcGBE'></th></span></q></dt></tr></i><div id='ZcGBE'><tfoot id='ZcGBE'></tfoot><dl id='ZcGBE'><fieldset id='ZcGBE'></fieldset></dl></div>

    <small id='ZcGBE'></small><noframes id='ZcGBE'>

        <bdo id='ZcGBE'></bdo><ul id='ZcGBE'></ul>

      变换模型矩阵

      时间:2023-09-18
    1. <i id='vF6ae'><tr id='vF6ae'><dt id='vF6ae'><q id='vF6ae'><span id='vF6ae'><b id='vF6ae'><form id='vF6ae'><ins id='vF6ae'></ins><ul id='vF6ae'></ul><sub id='vF6ae'></sub></form><legend id='vF6ae'></legend><bdo id='vF6ae'><pre id='vF6ae'><center id='vF6ae'></center></pre></bdo></b><th id='vF6ae'></th></span></q></dt></tr></i><div id='vF6ae'><tfoot id='vF6ae'></tfoot><dl id='vF6ae'><fieldset id='vF6ae'></fieldset></dl></div>

      <small id='vF6ae'></small><noframes id='vF6ae'>

        <bdo id='vF6ae'></bdo><ul id='vF6ae'></ul>

              <tbody id='vF6ae'></tbody>
          1. <legend id='vF6ae'><style id='vF6ae'><dir id='vF6ae'><q id='vF6ae'></q></dir></style></legend>

              <tfoot id='vF6ae'></tfoot>
                本文介绍了变换模型矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                使用 glm 设置 ViewMatrix 很容易:

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

                但是如果我尝试将 funktion 与 modelMatrix 一起使用,我会得到令人困惑的值(模型的位置不正确,而且旋转看起来也不正确).我只想以与设置相机相同的方式设置对象.我可以使用 lookAt 功能并在之后进行一些更改吗?还是我必须为此编写自己的功能?如果是这样,如何?

                我用这个固定了位置:

                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];

                也在我使用的顶点着色器中:

                gl_Position = CameraMatrix * ModelMatrix * Pos;

                其中 CameraMatrix 是一个 viewProjectionMatrix,ModelMatrix(我的问题)和 Pos 是我的顶点在模型空间中的位置

                解决方案

                在渲染中,场景的每个网格通常由模型矩阵、视图矩阵和投影矩阵进行变换.最后将投影场景映射到视口.

                模型坐标(物体坐标)

                模型空间是局部空间,其中定义了网格.顶点坐标在模型空间中定义.

                例如:

                世界坐标

                世界空间是场景的坐标系.不同的模型(对象)可以在世界空间中多次放置以形成一个场景.

                模型矩阵

                模型矩阵定义了场景中模型(对象、网格)的位置、方向和相对大小.模型矩阵将单个网格的顶点位置转换到世界空间以进行单个特定定位.有不同的模型矩阵,一个用于模型(对象)和对象在世界空间中的位置的每种组合.

                模型矩阵如下所示:

                ( 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 )

                视图空间(眼坐标)

                视点空间是局部系统,由场景中的视点定义.视图的位置、视线和视图的向上方向,定义了一个相对于世界坐标系的坐标系.场景的对象必须相对于视图坐标系进行绘制,以便被看到".从观看位置.视图坐标系的逆矩阵称为视图矩阵.
                一般来说,世界坐标和视图坐标是

                剪辑坐标

                剪辑空间坐标是

                标准化设备坐标

                归一化设备坐标是剪辑空间坐标除以剪辑坐标的w 分量.这称为

                窗口坐标(屏幕坐标)

                窗口坐标是视口矩形的坐标.最后将窗口坐标传递给评级过程.

                视口和深度范围

                标准化的设备坐标线性映射到窗口坐标(屏幕坐标)和深度缓冲区的深度.视口由 glViewport<定义/a>.深度范围由 glDepthRange<设置/a> 并且默认为 [0, 1].

                It is easy to set the ViewMatrix with glm:

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

                but if I try to use the funktion with the modelMatrix, I'll get comfusing values (the Model is not in the correct position and also the rotation looks wrong). I just want to set an object the same way than setting the camera. Can I use the lookAt funktion and make some changes afterwards? Or does I have to program an own funtion for that? And if so, how?

                I fixed the position with this:

                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 the vertexshader I use this:

                gl_Position = CameraMatrix * ModelMatrix * Pos;
                

                where CameraMatrix is a viewProjectionMatrix, ModelMatrix (my problem) and Pos is the position of my vertex in modelspace

                解决方案

                In a rendering, each mesh of the scene usually is transformed by the model matrix, the view matrix and the projection matrix. Finally the projected scene is mapped to the viewport.

                Model coordinates (Object coordinates)

                The model space is the local space, where within a mesh is defined. The vertex coordinates are defined in model space.

                e.g.:

                World coordinates

                The world space is the coordinate system of the scene. Different models (objects) can be placed multiple times in the world space to form a scene, in together.

                Model matrix

                The model matrix defines the location, orientation and the relative size of a model (object, mesh) in the scene. The model matrix transforms the vertex positions of a single mesh to world space for a single specific positioning. There are different model matrices, one for each combination of a model (object) and a location of the object in the world space.

                The model matrix looks like this:

                ( 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 )
                

                e.g.:

                (  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 )
                

                View space (Eye coordinates)

                The view space is the local system which is defined by the point of view onto the scene. The position of the view, the line of sight and the upwards direction of the view, define a coordinate system relative to the world coordinate system. The objects of a scene have to be drawn in relation to the view coordinate system, to be "seen" from the viewing position. The inverse matrix of the view coordinate system is named the view matrix.
                In general world coordinates and view coordinates are Cartesian coordinates

                View matrix

                The view coordinates system describes the direction and position from which the scene is looked at. The view matrix transforms from the world space to the view (eye) space.

                If the coordiante system of the view space is a Right-handed system, then the X-axis points to the left, the Y-axis up and the Z-axis out of the view (Note in a right hand system the Z-Axis is the cross product of the X-Axis and the Y-Axis).

                Clip coordinates

                Clip space coordinates are Homogeneous coordinates. In clip space the clipping of the scene is performed.
                A point is in clip space if the x, y and z components are in the range defined by the inverted w component and the w component of the homogeneous coordinates of the point:

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

                Projection matrix

                The projection matrix describes the mapping from 3D points of a scene, to 2D points of the viewport. The projection matrix transforms from view space to the clip space. The coordinates in the clip space are transformed to the normalized device coordinates (NDC) in the range (-1, -1, -1) to (1, 1, 1) by dividing with the w component of the clip coordinates.

                e.g.:

                look at: eye position (2.5, -1.5, 3.5), center (2, 0, 0), up vector (0, 1, 0)

                perspective projection: field of view (y) of 100°, near plane at 0.1, far plane at 20.0

                Normalized device coordinates

                The normalized device coordinates are the clip space coordinates divide by the w component of the clip coordinates. This is called Perspective divide

                Window coordinates (Screen coordinates)

                The window coordinates are the coordinates of the viewport rectangle. The window coordinates finally are passed to the raterization process.

                Viewport and depthrange

                The normalized device coordinates are linearly mapped to the Window Coordinates (Screen Coordinates) and to the depth for the depth buffer. The viewport is defined by glViewport. The depthrange is set by glDepthRange and is by default [0, 1].

                这篇关于变换模型矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用 Visual C++ 在 Opengl 中创建 3D 球体 下一篇:OpenGL 缩放单像素线

                相关文章

                最新文章

              1. <legend id='aOBB1'><style id='aOBB1'><dir id='aOBB1'><q id='aOBB1'></q></dir></style></legend>

                  <i id='aOBB1'><tr id='aOBB1'><dt id='aOBB1'><q id='aOBB1'><span id='aOBB1'><b id='aOBB1'><form id='aOBB1'><ins id='aOBB1'></ins><ul id='aOBB1'></ul><sub id='aOBB1'></sub></form><legend id='aOBB1'></legend><bdo id='aOBB1'><pre id='aOBB1'><center id='aOBB1'></center></pre></bdo></b><th id='aOBB1'></th></span></q></dt></tr></i><div id='aOBB1'><tfoot id='aOBB1'></tfoot><dl id='aOBB1'><fieldset id='aOBB1'></fieldset></dl></div>

                  <small id='aOBB1'></small><noframes id='aOBB1'>

                  <tfoot id='aOBB1'></tfoot>
                  • <bdo id='aOBB1'></bdo><ul id='aOBB1'></ul>