Herramientas de usuario

Herramientas del sitio


wiki2:oglmaths

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
wiki2:oglmaths [2015/11/22 18:22]
alfred [Tipos de matrices]
wiki2:oglmaths [2020/05/09 09:25] (actual)
Línea 18: Línea 18:
 La w es el valor de perspectiva,​ se utilizará para divir X, Y, y Z entre este. The Advantages of Dividing by W You might be wondering why we don’t simply divide by z instead. After all, if we interpret z as the distance and had two coordinates,​ (1, 1, 1) and (1, 1, 2) , we could then divide by z to get two normalized coordinates of (1, 1) and (0.5, 0.5). While this can work, there are additional advantages to adding w as a fourth component. We can decouple the perspective effect from the actual z coordinate, so we can switch between an orthographic and a perspective projection. There’s also a benefit to preserving the z component as a depth buffer. La w es el valor de perspectiva,​ se utilizará para divir X, Y, y Z entre este. The Advantages of Dividing by W You might be wondering why we don’t simply divide by z instead. After all, if we interpret z as the distance and had two coordinates,​ (1, 1, 1) and (1, 1, 2) , we could then divide by z to get two normalized coordinates of (1, 1) and (0.5, 0.5). While this can work, there are additional advantages to adding w as a fourth component. We can decouple the perspective effect from the actual z coordinate, so we can switch between an orthographic and a perspective projection. There’s also a benefit to preserving the z component as a depth buffer.
  
-:!: Recuerda, es importante el orden de operaciones. Al multiplicar una matriz por un vector el primer operando siempre será el vector:+==== Orden de operaciones ==== 
 + 
 +Recuerda, es importante el orden de operaciones. Al multiplicar una matriz por un vector el primer operando siempre será el vector:
 <​code>​ <​code>​
 transformedVector = myMatrix * myVector; transformedVector = myMatrix * myVector;
 </​code>​ </​code>​
  
 +El orden para acumular (multiplicar) matrices de transformación:​
 +<​code>​
 + ​TransformedVector = TranslationMatrix * RotationMatrix * ScaleMatrix * OriginalVector;​
 +</​code>​
 ==== Tipos de matrices ==== ==== Tipos de matrices ====
  
Línea 32: Línea 38:
 <code cpp> <code cpp>
 glm::mat4 myIdentityMatrix = glm::​mat4(1.0f);​ glm::mat4 myIdentityMatrix = glm::​mat4(1.0f);​
 +</​code>​
 +
 +=== Matriz de traslación ===
 +{{:​wiki2:​ogl:​translationmatrix.png?​nolink|}} \\ 
 +{{:​wiki2:​ogl:​translationexampleposition1.png?​nolink|}}
 +=== Matriz de escalado ===
 +{{:​wiki2:​ogl:​scalingmatrix.png?​nolink|}} \\ 
 +{{:​wiki2:​ogl:​scalingexample.png?​nolink|}}
 +
 +=== Matrices de rotación ===
 +
 +=== Model matrix ===
 +
 +Es la matriz que surge de aplicar todas las transformaciones. Al multiplicarla a un punto este pasa a tener las coordenadas del mundo.
 +
 +The model matrix transforms a position in a model to the position in the world. This position is affected by the position, scale and rotation of the model that is being drawn. It is generally a combination of the simple transformations you've seen before. If you are already specifying your vertices in world coordinates (common when drawing a simple test scene), then this matrix can simply be set to the identity matrix.
 +
 +=== View matrix ===
 +
 +Es la que mueve el mundo para colocarlo en la posición de la cámara (porque en ogl no es la cámara la que se mueve sino el mundo). Una vez es multiplicada a un punto, este pasa a tener las coordenadas de cámara.
 +
 +So initially your camera is at the origin of the World Space. In order to move the world, you simply introduce another matrix. Let’s say you want to move your camera of 3 units to the right (+X). This is equivalent to moving your whole world (meshes included) 3 units to the LEFT ! (-X). 
 +<code cpp>
 +glm::mat4 CameraMatrix = glm::​lookAt(
 +    cameraPosition,​ // the position of your camera, in world space
 +    cameraTarget, ​  // where you want to look at, in world space
 +    upVector ​       // probably glm::​vec3(0,​1,​0),​ but (0,-1,0) would make you looking upside-down,​ which can be great too
 +);
 +</​code>​
 +
 +=== Projection matrix ===
 +
 +Es la matriz que deforma los puntos para colocarlos en la proyección deseada.
 +
 +<code cpp>
 +glm::mat4 projectionMatrix = glm::​perspective(
 +    FoV,         // The horizontal Field of View, in degrees : the amount of "​zoom"​. Think "​camera lens". Usually between 90° (extra wide) and 30° (quite zoomed in)
 +    4.0f / 3.0f, // Aspect Ratio. Depends on the size of your window. Notice that 4/3 == 800/600 == 1280/960, sounds familiar ?
 +    0.1f,        // Near clipping plane. Keep as big as possible, or you'll get precision issues.
 +    100.0f ​      // Far clipping plane. Keep as little as possible.
 +7 );
 +</​code>​
 +
 +=== ModelViewProjection matrix ===
 +{{:​wiki2:​ogl:​mvp.png?​nolink|}}
 +
 +Cumulating transformations appears the ModelViewProjection matrix.
 +
 +<​code>​
 +// C++ : compute the matrix
 +glm::mat4 MVPmatrix = projection * view * model; // Remember : inverted !
 +// GLSL : apply it
 +transformed_vertex = MVP * in_vertex;
 </​code>​ </​code>​
 ===== Coordenadas ===== ===== Coordenadas =====
wiki2/oglmaths.1448216537.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)