OpenGL study notes, "six" coordinate system

  In the previous article, we have learned that vertex coordinates opengl required is between the NDC (normalized device coordinates) between -1.0 and 1.0. But we use every day to coordinate may have a variety of different coordinate systems, such as a set of coordinate system for the object itself, describing the relationship between the various components of the coordinates of the internal object. Set between the object and the object coordinate system, the coordinates describe relationships between objects and the like. opengl provide different coordinate systems for different situations, and based on certain coordinates conversion converts the coordinate system into different normalized device coordinates (NDC).

  

 

 

   This picture above, describes the transformation process in opengl coordinate system we mainly will be used, and coordinate system.

LOCAL SPACE,MODEL MATRIX

  Local space, the inside of the object is described in the coordinate system. For example, a picture, we default to the lower left corner is the origin of coordinates (0, 0), if the picture length 1, we will express the upper right corner with a (1,1). Local space to world space coordinates of the coordinate conversion by the model matrix (MODEL MATRIX), a displacement converting matrix model comprising objects, rotation, scaling operation.

WORDL SPACE,VIEW MATRIX

  World Space, describes the relationship between the object and the coordinates of an object, such as object A coordinate (0,0,0), the object B coordinates (2,0,0), when rendering the object B will be on the left side of the object A, across the two units. The default for each object in the world coordinates (0,0,0), if not set the world coordinates of the object, then the effect is to render all objects are stacked together. World space coordinates can be converted by the view matrix (VIEW MATRIX) to view space coordinates, the view matrix mainly through a series of rotating displacement calculation, the object descriptions into view space, equivalent to the object to be placed before our eyes, cameras proper position before.

  Will be mentioned later in view of the space camera concept, we different camera operations, such as move, rotate, but also to generate a different view matrix (VIEW MATRIX)

VIEW SPACE,PROJECTION MATRIX

  View of the space, the space can also be called a camera or visual space, is described based on the angular relationship between the coordinates generated by the user's eye. That is, from our eyes, to describe the object is in front of us, left, right? View space (VIEW SPACE) is also equivalent to the space cameras. View of the space coordinates can be converted by a projection matrix (PROJECTION MATRIX) to clip space coordinates, projection coordinates into the view matrix standard device coordinates of -1 to 1 (the NDC), further orthographic projection can be divided according to the different embodiment of the projection ( orthographic projection) and a perspective projection (perspective projection). On the visual performance, perspective projection described in our eyes to see the world: from our recent look bigger, far away from us look smaller; and orthographic projection is no difference in the distance, directly coordinate mapping object to it on the screen.

CLIP SPACE

  Clip space, a coordinate system is described -1 to 1, the object in this range will be rendered, it is not filtered out. Also in this space, the coordinates of the object is finally converted into normalized device coordinates (NDC). Cutting through the view space coordinate conversion, clipping spatial coordinates (NDC) installed for the screen space coordinates.

SCREEN SPACE

  Screen space, i.e. the width and height of the screen by glViewport we define the corresponding coordinate system.

  opengl offers a variety of coordinate systems, but also to help us have the appropriate coordinate system under different scenarios, there is a convenient way to convert under different scenarios. And we often MVP of the conversion, that is, from object space to clip space installed for a combination. In addition, we also find out about before, the vertex shader mainly addressed the vertex coordinates of the object, so our MVP conversion is processed in a vertex shader.

  In conventional perspective projection as an example, we describe our eyes in front of a 3 units, the MVP matrix conversion units to the right of a subject

// model matrix
glm::mat4 model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(1.0f, 0.0f, 0.0f);
// view matrix
glm::mat4 view = glm::mat4(1.0f);
view = glm::translate(view, glm::vec3(0.0f, 0.0f, -3.0f);
// projection matrix
glm::mat4 projection = glm::perspective(glm::radians(45.0f), 800.0f / 600.0f, 0.1f, 100.0f);
// 传递给shader
// u_model = model; u_view = view; u_projection = projection;
...
... vertex shader
uniform mat4 u_model;
uniform mat4 u_view;
uniform mat4 u_projection;
void main(){
    gl_Position = u_projection * u_view * u_model * vec4(aPos, 1.0f);  
}

  We model matrix mentioned object translation, rotation, scaling conversion operation; camera view matrix we can introduce the concept of a more complex effect expression; matrix relatively fixed projection, which projection is set, width and height of the screen, the distance parameter the settings.

  

 

Guess you like

Origin www.cnblogs.com/zhong-dev/p/11672551.html