|
@@ -23,6 +23,7 @@
|
|
|
#include <vector.h>
|
|
|
#include <mesh.h>
|
|
|
#include <light.h>
|
|
|
+#include <camera.h>
|
|
|
|
|
|
bool isRunning = true;
|
|
|
int previousFrameTime = 0;
|
|
@@ -41,18 +42,14 @@ bool doNotCull = false;
|
|
|
bool doZBuffer = true;
|
|
|
enum displayMode_t currentDisplayMode = DISPLAY_MODE_SOLID;
|
|
|
matrix4_t projectionMatrix;
|
|
|
+matrix4_t viewMatrix;
|
|
|
+
|
|
|
light_t globalLight;
|
|
|
double updateTime, renderTime, waitTime;
|
|
|
int trianglesCount, trianglesTotal;
|
|
|
-
|
|
|
-vec3_t cameraPosition =
|
|
|
-{
|
|
|
- .x = 0,
|
|
|
- .y = 0,
|
|
|
- .z = 0,
|
|
|
-};
|
|
|
-
|
|
|
triangle_t *projectedTriangles = NULL;
|
|
|
+const vec3_t origin = {0, 0, 0 };
|
|
|
+const vec3_t up = {0, 1, 0 };
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
@@ -85,10 +82,9 @@ void setup()
|
|
|
globalLight.direction.z = 1;
|
|
|
vec3Normalize(&globalLight.direction);
|
|
|
|
|
|
-
|
|
|
/* Load texture */
|
|
|
//meshTexture = (colour_t *)REDBRICK_TEXTURE;
|
|
|
- loadTextureDateFromPng("assets/cube.png");
|
|
|
+ loadTextureDateFromPng("assets/f22.png");
|
|
|
|
|
|
|
|
|
/* Load object */
|
|
@@ -195,6 +191,7 @@ void update()
|
|
|
uint32_t timeToWait = FRAME_TARGET_TIME - (SDL_GetTicks() - previousFrameTime);
|
|
|
matrix4_t worldMatrix;
|
|
|
uint32_t ticks = getMicroSecTime();
|
|
|
+ vec3_t target = { 0, 0, 4 };
|
|
|
|
|
|
if (timeToWait <= FRAME_TARGET_TIME)
|
|
|
{
|
|
@@ -205,9 +202,13 @@ void update()
|
|
|
waitTime = (waitTime + (getMicroSecTime() - ticks) / 1000.) / 2.0;
|
|
|
ticks = getMicroSecTime();
|
|
|
|
|
|
- mesh.rotation.x += 0.001;
|
|
|
- mesh.rotation.y += 0.01;
|
|
|
- mesh.translation.z = 5;
|
|
|
+ //mesh.rotation.x += 0.02;
|
|
|
+ mesh.translation.z = 4;
|
|
|
+
|
|
|
+ camera.position.x += 0.008;
|
|
|
+ camera.position.y += 0.008;
|
|
|
+
|
|
|
+ viewMatrix = mat4LookAt(camera.position, target, up);
|
|
|
|
|
|
worldMatrix = mat4Identity;
|
|
|
|
|
@@ -217,6 +218,9 @@ void update()
|
|
|
worldMatrix = mat4ProdMat4(mat4RotationX(mesh.rotation.x), worldMatrix);
|
|
|
worldMatrix = mat4ProdMat4(mat4Translate(mesh.translation.x, mesh.translation.y, mesh.translation.z), worldMatrix);
|
|
|
|
|
|
+ /* Not sure for now */
|
|
|
+ //worldMatrix = mat4ProdMat4(viewMatrix, worldMatrix);
|
|
|
+
|
|
|
arrayEmpty(projectedTriangles);
|
|
|
|
|
|
faceCount = arrayGetSize(mesh.faces);
|
|
@@ -246,6 +250,8 @@ void update()
|
|
|
transformedVertices[j] = vec4FromVec3(vertices[j]);
|
|
|
|
|
|
transformedVertices[j] = mat4ProdVec4(worldMatrix, transformedVertices[j]);
|
|
|
+
|
|
|
+ transformedVertices[j] = mat4ProdVec4(viewMatrix, transformedVertices[j]);
|
|
|
}
|
|
|
|
|
|
vec3_t vectorBA = vec3SubVectors(vec3FromVec4(transformedVertices[1]), vec3FromVec4(transformedVertices[0]));
|
|
@@ -257,7 +263,7 @@ void update()
|
|
|
|
|
|
if (!doNotCull)
|
|
|
{
|
|
|
- vec3_t cameraRay = vec3SubVectors(cameraPosition, vec3FromVec4(transformedVertices[0]));
|
|
|
+ vec3_t cameraRay = vec3SubVectors(origin, vec3FromVec4(transformedVertices[0]));
|
|
|
vec3Normalize(&cameraRay);
|
|
|
|
|
|
double cameraDotTriangle = vec3Dot(triangleNormal, cameraRay);
|