|
@@ -34,6 +34,7 @@ typedef enum displayMode_t
|
|
|
bool displayVertex = false;
|
|
|
bool doNotCull = false;
|
|
|
enum displayMode_t currentDisplayMode = DISPLAY_MODE_SOLID;
|
|
|
+matrix4_t projectionMatrix;
|
|
|
|
|
|
vec3_t cameraPosition =
|
|
|
{
|
|
@@ -44,8 +45,6 @@ vec3_t cameraPosition =
|
|
|
|
|
|
triangle_t *projectedTriangles = NULL;
|
|
|
|
|
|
-double fovFactor = 640;
|
|
|
-
|
|
|
void setup()
|
|
|
{
|
|
|
frameBuffer = (uint32_t *)calloc(windowWidth * windowHeight, sizeof(uint32_t));
|
|
@@ -63,6 +62,8 @@ void setup()
|
|
|
goto exit;
|
|
|
}
|
|
|
|
|
|
+ projectionMatrix = mat4Perspective((double)windowHeight / windowWidth, 90, 0.1, 100);
|
|
|
+
|
|
|
//loadOBJFile("assets/cube.obj");
|
|
|
loadCubeMeshData();
|
|
|
|
|
@@ -123,28 +124,6 @@ void processInput()
|
|
|
|
|
|
}
|
|
|
|
|
|
-vec2_t orthographicPointProjection(vec3_t point)
|
|
|
-{
|
|
|
- vec2_t ret;
|
|
|
-
|
|
|
- ret.x = point.x * fovFactor;
|
|
|
- ret.y = point.y * fovFactor;
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-vec2_t perspectivePointProjection(vec3_t point)
|
|
|
-{
|
|
|
- vec2_t ret;
|
|
|
- double divisor = point.z;
|
|
|
- if (divisor == 0) { divisor += 0.00001; }
|
|
|
-
|
|
|
- ret.x = (point.x / divisor) * (fovFactor/2.);
|
|
|
- ret.y = (point.y / divisor) * (fovFactor/2.);
|
|
|
-
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
void update()
|
|
|
{
|
|
|
uint32_t i, j;
|
|
@@ -158,13 +137,6 @@ void update()
|
|
|
previousFrameTime = SDL_GetTicks();
|
|
|
|
|
|
mesh.rotation.x += 0.01;
|
|
|
- mesh.rotation.y += 0.01;
|
|
|
- mesh.rotation.z += 0.02;
|
|
|
-
|
|
|
- //mesh.scale.x += 0.002;
|
|
|
- //mesh.scale.x += 0.001;
|
|
|
-
|
|
|
- mesh.translation.x += 0.01;
|
|
|
mesh.translation.z = 5;
|
|
|
|
|
|
worldMatrix = mat4Identity;
|
|
@@ -220,12 +192,17 @@ void update()
|
|
|
|
|
|
for (j = 0 ; j < 3 ; j++)
|
|
|
{
|
|
|
- vec2_t projected = perspectivePointProjection(vec3FromVec4(transformedVertices[j]));
|
|
|
+ vec4_t projected = mat4ProdVec4Project(projectionMatrix, transformedVertices[j]);
|
|
|
+
|
|
|
+
|
|
|
+ projected.x *= windowWidth / 2.;
|
|
|
+ projected.y *= windowHeight / 2.;
|
|
|
|
|
|
- projected.x += (windowWidth / 2);
|
|
|
- projected.y += (windowHeight / 2);
|
|
|
+ projected.x += (windowWidth / 2.);
|
|
|
+ projected.y += (windowHeight / 2.);
|
|
|
|
|
|
- currentTriangle.points[j] = projected;
|
|
|
+ currentTriangle.points[j].x = projected.x;
|
|
|
+ currentTriangle.points[j].y = projected.y;
|
|
|
}
|
|
|
|
|
|
currentTriangle.colour = mesh.faces[i].colour;
|