Browse Source

Lesson 16.6

Godzil 3 years ago
parent
commit
a59da1ff59
2 changed files with 10 additions and 6 deletions
  1. 2 0
      source/include/matrix.h
  2. 8 6
      source/main.c

+ 2 - 0
source/include/matrix.h

@@ -35,7 +35,9 @@ static const struct matrix4_t mat4Identity =
  * Prototypes
  **********************************************************************************************************************/
 #define FastGet4(_m, _x, _y) ((_m).v[4 * (_x) + (_y)])
+
 matrix4_t mat4Scale(double scaleX, double scaleY, double scaleZ);
+matrix4_t mat4Translate(double tX, double tY, double tZ);
 
 vec4_t mat4ProdVec4(matrix4_t mat, vec4_t v);
 

+ 8 - 6
source/main.c

@@ -150,7 +150,7 @@ void update()
     uint32_t i, j;
     uint32_t faceCount;
     uint32_t timeToWait = FRAME_TARGET_TIME - (SDL_GetTicks() - previousFrameTime);
-    matrix4_t scaleMatrix;
+    matrix4_t scaleMatrix, translateMatrix;
     if (timeToWait <= FRAME_TARGET_TIME)
     {
         SDL_Delay(timeToWait);
@@ -161,11 +161,14 @@ void update()
     mesh.rotation.y += 0.01;
     mesh.rotation.z += 0.02;
 
-    mesh.scale.x += 0.002;
-    mesh.scale.x += 0.001;
+    //mesh.scale.x += 0.002;
+    //mesh.scale.x += 0.001;
 
-    scaleMatrix = mat4Scale(mesh.scale.x, mesh.scale.y, mesh.scale.z);
+    mesh.translation.x += 0.01;
+    mesh.translation.z = 5;
 
+    scaleMatrix = mat4Scale(mesh.scale.x, mesh.scale.y, mesh.scale.z);
+    translateMatrix = mat4Translate(mesh.translation.x, mesh.translation.y, mesh.translation.z);
     arrayEmpty(projectedTriangles);
 
     faceCount = arrayGetSize(mesh.faces);
@@ -186,8 +189,7 @@ void update()
             transformedVertices[j] = vec4FromVec3(vertices[j]);
 
             transformedVertices[j] = mat4ProdVec4(scaleMatrix, transformedVertices[j]);
-
-            transformedVertices[j].z += 5;
+            transformedVertices[j] = mat4ProdVec4(translateMatrix, transformedVertices[j]);
         }
 
         if (!doNotCull)