|
@@ -29,12 +29,6 @@ vec3_t cameraPosition =
|
|
|
.y = 0,
|
|
|
.z = -5,
|
|
|
};
|
|
|
-vec3_t cubeRotation =
|
|
|
-{
|
|
|
- .x = 0,
|
|
|
- .y = 0,
|
|
|
- .z = 0,
|
|
|
-};
|
|
|
|
|
|
triangle_t *projectedTriangles = NULL;
|
|
|
|
|
@@ -57,6 +51,8 @@ void setup()
|
|
|
goto exit;
|
|
|
}
|
|
|
|
|
|
+ loadCubeMeshData();
|
|
|
+
|
|
|
exit:
|
|
|
return;
|
|
|
}
|
|
@@ -106,8 +102,8 @@ vec2_t perspectivePointProjection(vec3_t point)
|
|
|
|
|
|
void update()
|
|
|
{
|
|
|
- int i, j;
|
|
|
-
|
|
|
+ uint32_t i, j;
|
|
|
+ uint32_t faceCount;
|
|
|
uint32_t timeToWait = FRAME_TARGET_TIME - (SDL_GetTicks() - previousFrameTime);
|
|
|
if (timeToWait <= FRAME_TARGET_TIME)
|
|
|
{
|
|
@@ -115,29 +111,31 @@ void update()
|
|
|
}
|
|
|
previousFrameTime = SDL_GetTicks();
|
|
|
|
|
|
- cubeRotation.x += 0.01;
|
|
|
- cubeRotation.y += 0.01;
|
|
|
- cubeRotation.z += 0.01;
|
|
|
+ mesh.rotation.x += 0.01;
|
|
|
+ mesh.rotation.y += 0.01;
|
|
|
+ mesh.rotation.z += 0.01;
|
|
|
|
|
|
arrayEmpty(projectedTriangles);
|
|
|
|
|
|
- for(i = 0; i < N_MESH_FACES; i++)
|
|
|
+ faceCount = arrayGetSize(mesh.faces);
|
|
|
+
|
|
|
+ for(i = 0; i < faceCount; i++)
|
|
|
{
|
|
|
triangle_t currentTriangle;
|
|
|
vec3_t vertices[3] =
|
|
|
{
|
|
|
- meshVertices[meshFaces[i].a - 1],
|
|
|
- meshVertices[meshFaces[i].b - 1],
|
|
|
- meshVertices[meshFaces[i].c - 1],
|
|
|
+ mesh.vertices[mesh.faces[i].a - 1],
|
|
|
+ mesh.vertices[mesh.faces[i].b - 1],
|
|
|
+ mesh.vertices[mesh.faces[i].c - 1],
|
|
|
};
|
|
|
|
|
|
for(j = 0; j < 3; j++)
|
|
|
{
|
|
|
vec3_t transformed = vertices[j];
|
|
|
|
|
|
- transformed = vec3RotateX(transformed, cubeRotation.x);
|
|
|
- transformed = vec3RotateY(transformed, cubeRotation.y);
|
|
|
- transformed = vec3RotateZ(transformed, cubeRotation.z);
|
|
|
+ transformed = vec3RotateX(transformed, mesh.rotation.x);
|
|
|
+ transformed = vec3RotateY(transformed, mesh.rotation.y);
|
|
|
+ transformed = vec3RotateZ(transformed, mesh.rotation.z);
|
|
|
|
|
|
transformed.z -= cameraPosition.z;
|
|
|
|
|
@@ -146,8 +144,6 @@ void update()
|
|
|
projected.x += (windowWidth / 2);
|
|
|
projected.y += (windowHeight / 2);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
currentTriangle.points[j] = projected;
|
|
|
}
|
|
|
|
|
@@ -213,8 +209,8 @@ no_more_params:
|
|
|
}
|
|
|
|
|
|
arrayFree(projectedTriangles);
|
|
|
-
|
|
|
- destroy_window();
|
|
|
+ meshFree();
|
|
|
+ destroyWindow();
|
|
|
|
|
|
return 0;
|
|
|
}
|