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:38]
alfred [Tipos de matrices]
wiki2:oglmaths [2020/05/09 09:25] (actual)
Línea 20: Línea 20:
 ==== Orden de operaciones ==== ==== Orden de operaciones ====
  
-:!: Recuerda, es importante el orden de operaciones. Al multiplicar una matriz por un vector el primer operando siempre será el vector:+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 48: Línea 51:
 === Model matrix === === Model matrix ===
  
-Es la matriz que surge de aplicar todas las transformaciones. Al aplicarla ​a un punto este pasa a tener las coordenadas del mundo.+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. 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.
Línea 54: Línea 57:
 === View 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> <code cpp>
 glm::mat4 CameraMatrix = glm::​lookAt( glm::mat4 CameraMatrix = glm::​lookAt(
Línea 60: Línea 66:
     upVector ​       // probably glm::​vec3(0,​1,​0),​ but (0,-1,0) would make you looking upside-down,​ which can be great too     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.1448217498.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)