Browse Source

Lesson 25.3

Godzil 3 years ago
parent
commit
b66d4d7ad7
4 changed files with 8 additions and 10 deletions
  1. 1 1
      source/include/light.h
  2. 0 5
      source/include/triangle.h
  3. 6 0
      source/light.c
  4. 1 4
      source/main.c

+ 1 - 1
source/include/light.h

@@ -19,12 +19,12 @@
 typedef struct light_t
 {
     vec3_t direction;
-
 } light_t;
 
 /***********************************************************************************************************************
  * Prototypes
  **********************************************************************************************************************/
+void createLight(light_t *light, vec3_t direction);
 colour_t applyLight(colour_t c, double lightLevel);
 
 

+ 0 - 5
source/include/triangle.h

@@ -39,11 +39,6 @@ typedef struct triangle_t
     texture_t *texture;
 } triangle_t;
 
-/***********************************************************************************************************************
- * Global variables
- **********************************************************************************************************************/
-extern bool doPerspectiveCorrection;
-
 /***********************************************************************************************************************
  * Prototypes
  **********************************************************************************************************************/

+ 6 - 0
source/light.c

@@ -11,6 +11,12 @@
 #include <vector.h>
 #include <light.h>
 
+void createLight(light_t *light, vec3_t direction)
+{
+    light->direction = direction;
+    vec3Normalize(&light->direction);
+}
+
 colour_t applyLight(colour_t c, double lightLevel)
 {
     if (lightLevel < 0) { lightLevel = 0; }

+ 1 - 4
source/main.c

@@ -72,10 +72,7 @@ void setup()
 
     initFrustumPlanes(FOV, aspectRatioX, zNear, zFar);
 
-    globalLight.direction.x = 0;
-    globalLight.direction.y = 0;
-    globalLight.direction.z = 1;
-    vec3Normalize(&globalLight.direction);
+    createLight(&globalLight, vec3(0, 0, 1));
 
     /* Load object */
     loadOBJFile(&mesh,"assets/dragon.obj");