Browse Source

updated bill's texture, added floor texture, changed mesh array geometry, changed example scene, moved FOV to scene

IverMartinson 5 months ago
parent
commit
50fb6b39a1

BIN
build/librasteriver.so


BIN
build/main.bin


+ 1 - 1
objects/unit_cube.obj

@@ -1,6 +1,6 @@
 # Blender 4.4.3
 # Blender 4.4.3
 # www.blender.org
 # www.blender.org
-mtllib cube.mtl
+mtllib unit_cube.mtl
 o Cube
 o Cube
 v 1.000000 1.000000 -1.000000
 v 1.000000 1.000000 -1.000000
 v 1.000000 -1.000000 -1.000000
 v 1.000000 -1.000000 -1.000000

+ 4 - 1
readme.md

@@ -1,2 +1,5 @@
 ### How to Run?
 ### How to Run?
-To run the binary, it needs to be in the same folder as librasteriver.so (if you just cloned the repo then they both should be in the build folder). You also need SDL2 installed (libsdl2-dev)
+To run the binary, it needs to be in the same folder as librasteriver.so (if you just cloned the repo then they both should be in the build folder). You also need SDL2 installed (libsdl2-dev)
+
+### Notes
+- When using the window's texture as a texture reference on an object that is being rendered to the window's texture, some parts of it won't be filled in becuase when those texels are accessed to draw the object, that part of the screen hasn't been rendered yet. 

+ 17 - 10
src/headers/custom_types.h

@@ -4,21 +4,26 @@
 #include "math.h"
 #include "math.h"
 
 
 // ----- Meshes -----
 // ----- Meshes -----
-typedef struct {
-    RI_vector_3f position;
-    RI_vector_3f normal;
-    RI_vector_2f uv;
-} RI_vertex;
 
 
 typedef struct {
 typedef struct {
-    int vertex_0_index;
-    int vertex_1_index;
-    int vertex_2_index;
+    int position_0_index;
+    int position_1_index;
+    int position_2_index;
+
+    int normal_0_index;
+    int normal_1_index;
+    int normal_2_index;
+
+    int uv_0_index;
+    int uv_1_index;
+    int uv_2_index;
 } RI_face;
 } RI_face;
 
 
 typedef struct { // A loaded mesh file (NOT an actor; doesn't store transformations or textures, ONLY mesh file data)
 typedef struct { // A loaded mesh file (NOT an actor; doesn't store transformations or textures, ONLY mesh file data)
     RI_face *faces;
     RI_face *faces;
-    RI_vertex *vertecies;
+    RI_vector_3f *vertex_positions;
+    RI_vector_3f *normals;
+    RI_vector_2f *uvs;
     int face_count;
     int face_count;
     int vertex_count;
     int vertex_count;
     int normal_count;
     int normal_count;
@@ -69,7 +74,8 @@ typedef struct {
 typedef struct { // An entity that has an mesh, transform, materials, etc
 typedef struct { // An entity that has an mesh, transform, materials, etc
     RI_mesh *mesh_reference;
     RI_mesh *mesh_reference;
     RI_material *material_reference;
     RI_material *material_reference;
-    RI_vertex *transformed_verticies;
+    RI_vector_3f *transformed_vertex_positions;
+    RI_vector_3f *transformed_normals;
     RI_transform transform;
     RI_transform transform;
 } RI_actor;
 } RI_actor;
 
 
@@ -82,6 +88,7 @@ typedef struct {
 typedef struct {
 typedef struct {
     RI_actor **actors;
     RI_actor **actors;
     int actor_count;
     int actor_count;
+    float FOV;
     RI_vector_3f camera_position;
     RI_vector_3f camera_position;
     RI_vector_4f camera_rotation;
     RI_vector_4f camera_rotation;
 } RI_scene;
 } RI_scene;

+ 0 - 4
src/headers/rasteriver.h

@@ -16,8 +16,6 @@ typedef struct {
     int window_height;
     int window_height;
     char *window_title;
     char *window_title;
 
 
-    float FOV;
-
     // SDL specific
     // SDL specific
     SDL_Window *window;
     SDL_Window *window;
     SDL_Renderer *renderer;
     SDL_Renderer *renderer;
@@ -25,8 +23,6 @@ typedef struct {
     SDL_Event event;
     SDL_Event event;
     
     
     // RasterIver
     // RasterIver
-    RI_vertex *verticies; //data type that holds info about a vertex (positon, normal, UV coord)
-
     RI_vector_3f *loaded_mesh_vetex_positions; // original vertex positions from a loaded mesh
     RI_vector_3f *loaded_mesh_vetex_positions; // original vertex positions from a loaded mesh
     RI_vector_3f *normals; // original normal vectors from a loaded mesh
     RI_vector_3f *normals; // original normal vectors from a loaded mesh
     RI_vector_2f *uvs; // UV coords from a loaded mesh
     RI_vector_2f *uvs; // UV coords from a loaded mesh

+ 9 - 5
src/launch_program/main.c

@@ -10,7 +10,7 @@ int main(){
 
 
     // data for loading files
     // data for loading files
     char *filenames[] = {"objects/unit_cube.obj", "objects/test_guy.obj", "objects/unit_plane.obj"};
     char *filenames[] = {"objects/unit_cube.obj", "objects/test_guy.obj", "objects/unit_plane.obj"};
-    RI_texture_creation_data texture_creation_info[2] = {{"textures/bill_mcdinner.png", {0, 0}}, {"textures/test_guy_texture.png", {0, 0}}};
+    RI_texture_creation_data texture_creation_info[2] = {{"textures/bill_mcdinner.png", {0, 0}}, {"textures/this is the floor.png", {0, 0}}};
     
     
     // requesting assets
     // requesting assets
     RI_mesh* meshes = RI_request_meshes(3, filenames, 0);
     RI_mesh* meshes = RI_request_meshes(3, filenames, 0);
@@ -25,11 +25,12 @@ int main(){
 
 
     // textures
     // textures
     RI_texture* bill_cube_texture = &textures[0];
     RI_texture* bill_cube_texture = &textures[0];
+    RI_texture* floor_texture = &textures[1];
 
 
     // materials
     // materials
     RI_material* floor_material = &materials[0];
     RI_material* floor_material = &materials[0];
-    floor_material->flags = 0;
-    floor_material->albedo = 0xFF77FF77;
+    floor_material->flags = RI_MATERIAL_HAS_TEXTURE;
+    floor_material->texture_reference = floor_texture;
     
     
     RI_material* wall_material = &materials[1];
     RI_material* wall_material = &materials[1];
     wall_material->flags = 0;
     wall_material->flags = 0;
@@ -70,11 +71,13 @@ int main(){
     screen->mesh_reference = unit_plane_mesh;
     screen->mesh_reference = unit_plane_mesh;
     screen->transform.scale = (RI_vector_3f){50, 50, 50};
     screen->transform.scale = (RI_vector_3f){50, 50, 50};
     screen->transform.position = (RI_vector_3f){0, 0, 250};
     screen->transform.position = (RI_vector_3f){0, 0, 250};
-    screen->transform.rotation = (RI_vector_4f){0.70710678, 0.70710678, 0, 0};
+    screen->transform.rotation = (RI_vector_4f){0, 1, 0, 0};
+
+    RI_euler_rotation_to_quaternion(&screen->transform.rotation, (RI_vector_3f){-3.14159 / 2, 0, 0});
 
 
     RI_add_actors_to_scene(4, actors, scene);
     RI_add_actors_to_scene(4, actors, scene);
 
 
-    ri->FOV = 1.5; // 90 degrees in radians
+    scene->FOV = 1.5; // 90 degrees in radians
 
 
     float y_rotation = 0;
     float y_rotation = 0;
 
 
@@ -82,6 +85,7 @@ int main(){
         bill_cube->transform.position = (RI_vector_3f){sin(ri->frame * 0.1) * 50 - 100, sin(ri->frame * 0.2 + 0.4) * 50, sin(ri->frame * 0.1) * 10 + 200};
         bill_cube->transform.position = (RI_vector_3f){sin(ri->frame * 0.1) * 50 - 100, sin(ri->frame * 0.2 + 0.4) * 50, sin(ri->frame * 0.1) * 10 + 200};
         
         
         scene->camera_position = (RI_vector_3f){cos(ri->frame * 0.07) * 50 * sin(ri->frame * 0.2), sin(ri->frame * 0.07) * 50 * sin(ri->frame * 0.2), -150};
         scene->camera_position = (RI_vector_3f){cos(ri->frame * 0.07) * 50 * sin(ri->frame * 0.2), sin(ri->frame * 0.07) * 50 * sin(ri->frame * 0.2), -150};
+        scene->camera_rotation = (RI_vector_4f){0, 1, 0, 0};
 
 
         RI_euler_rotation_to_quaternion(&floor->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
         RI_euler_rotation_to_quaternion(&floor->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
         
         

+ 88 - 81
src/library/rasteriver.c

@@ -160,10 +160,9 @@ RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames,
         fclose(file);
         fclose(file);
         
         
         new_mesh_data_struct.faces = malloc(sizeof(RI_face) * new_mesh_data_struct.face_count);
         new_mesh_data_struct.faces = malloc(sizeof(RI_face) * new_mesh_data_struct.face_count);
-        new_mesh_data_struct.vertecies = malloc(sizeof(RI_vertex) * new_mesh_data_struct.vertex_count);
-
-        RI_vector_3f *normals = malloc(sizeof(RI_vector_3f) * new_mesh_data_struct.normal_count);
-        RI_vector_2f *uvs = malloc(sizeof(RI_vector_2f) * new_mesh_data_struct.uv_count);
+        new_mesh_data_struct.vertex_positions = malloc(sizeof(RI_vector_3f) * new_mesh_data_struct.vertex_count);
+        new_mesh_data_struct.normals = malloc(sizeof(RI_vector_3f) * new_mesh_data_struct.normal_count);
+        new_mesh_data_struct.uvs = malloc(sizeof(RI_vector_2f) * new_mesh_data_struct.uv_count);
 
 
         FILE *file_again = fopen(filenames[i], "r");
         FILE *file_again = fopen(filenames[i], "r");
 
 
@@ -216,17 +215,17 @@ RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames,
                     has_normals = has_uvs = 1;
                     has_normals = has_uvs = 1;
                 }
                 }
 
 
-                new_mesh_data_struct.faces[current_face_index].vertex_0_index = vertex_0_index - 1;
-                new_mesh_data_struct.faces[current_face_index].vertex_1_index = vertex_1_index - 1;
-                new_mesh_data_struct.faces[current_face_index].vertex_2_index = vertex_2_index - 1;
-
-                new_mesh_data_struct.vertecies[vertex_0_index - 1].normal = normals[normal_0_index - 1];
-                new_mesh_data_struct.vertecies[vertex_1_index - 1].normal = normals[normal_1_index - 1];
-                new_mesh_data_struct.vertecies[vertex_2_index - 1].normal = normals[normal_2_index - 1];
+                new_mesh_data_struct.faces[current_face_index].position_0_index = vertex_0_index - 1;
+                new_mesh_data_struct.faces[current_face_index].position_1_index = vertex_1_index - 1;
+                new_mesh_data_struct.faces[current_face_index].position_2_index = vertex_2_index - 1;
 
 
-                new_mesh_data_struct.vertecies[vertex_0_index - 1].uv = uvs[uv_0_index - 1];
-                new_mesh_data_struct.vertecies[vertex_1_index - 1].uv = uvs[uv_1_index - 1];
-                new_mesh_data_struct.vertecies[vertex_2_index - 1].uv = uvs[uv_2_index - 1];
+                new_mesh_data_struct.faces[current_face_index].normal_0_index = normal_0_index - 1;
+                new_mesh_data_struct.faces[current_face_index].normal_1_index = normal_1_index - 1;
+                new_mesh_data_struct.faces[current_face_index].normal_2_index = normal_2_index - 1;
+                
+                new_mesh_data_struct.faces[current_face_index].uv_0_index = uv_0_index - 1;
+                new_mesh_data_struct.faces[current_face_index].uv_1_index = uv_1_index - 1;
+                new_mesh_data_struct.faces[current_face_index].uv_2_index = uv_2_index - 1;
 
 
                 ++current_face_index;
                 ++current_face_index;
             }
             }
@@ -235,9 +234,9 @@ RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames,
                 
                 
                 sscanf(line, "v %f %f %f", &x, &y, &z);
                 sscanf(line, "v %f %f %f", &x, &y, &z);
 
 
-                new_mesh_data_struct.vertecies[current_vertex_index].position.x = x;
-                new_mesh_data_struct.vertecies[current_vertex_index].position.y = y;
-                new_mesh_data_struct.vertecies[current_vertex_index].position.z = z;
+                new_mesh_data_struct.vertex_positions[current_vertex_index].x = x;
+                new_mesh_data_struct.vertex_positions[current_vertex_index].y = y;
+                new_mesh_data_struct.vertex_positions[current_vertex_index].z = z;
 
 
                 ++current_vertex_index;
                 ++current_vertex_index;
             } 
             } 
@@ -246,9 +245,9 @@ RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames,
                 
                 
                 sscanf(line, "vn %f %f %f", &x, &y, &z);
                 sscanf(line, "vn %f %f %f", &x, &y, &z);
 
 
-                normals[current_normal_index].x = x;
-                normals[current_normal_index].y = y;
-                normals[current_normal_index].z = z;
+                new_mesh_data_struct.normals[current_normal_index].x = x;
+                new_mesh_data_struct.normals[current_normal_index].y = y;
+                new_mesh_data_struct.normals[current_normal_index].z = z;
 
 
                 ++current_normal_index;
                 ++current_normal_index;
             }
             }
@@ -257,17 +256,14 @@ RI_mesh* RI_request_meshes(int RI_number_of_requested_meshes, char **filenames,
 
 
                 sscanf(line, "vt %f %f %f", &x, &y, &z);
                 sscanf(line, "vt %f %f %f", &x, &y, &z);
 
 
-                uvs[current_uv_index].x = x;
-                uvs[current_uv_index].y = y;
+                new_mesh_data_struct.uvs[current_uv_index].x = x;
+                new_mesh_data_struct.uvs[current_uv_index].y = y;
                 // UVS are almost always 2D so we don't need Z (the type itself is a vector 2f, not 3f) 
                 // UVS are almost always 2D so we don't need Z (the type itself is a vector 2f, not 3f) 
 
 
                 ++current_uv_index;
                 ++current_uv_index;
             } 
             } 
         }
         }
 
 
-        free(normals);
-        free(uvs);
-
         char* loading_mesh_notice_string;
         char* loading_mesh_notice_string;
 
 
         if (has_normals && !has_uvs) loading_mesh_notice_string = "normals";
         if (has_normals && !has_uvs) loading_mesh_notice_string = "normals";
@@ -322,54 +318,9 @@ void RI_euler_rotation_to_quaternion(RI_vector_4f *quaternion, RI_vector_3f eule
 int RI_render(RI_scene *scene, RI_texture *target_texture){
 int RI_render(RI_scene *scene, RI_texture *target_texture){
     // do rendering stuff
     // do rendering stuff
     if (ri.running){
     if (ri.running){
-        float horizontal_fov_factor = target_texture->resolution.x / tanf(0.5 * ri.FOV);
-        float vertical_fov_factor = target_texture->resolution.y / tanf(0.5 * ri.FOV);
-
-        for (int actor_index = 0; actor_index < scene->actor_count; ++actor_index){
-            RI_actor *current_actor = scene->actors[actor_index];
-
-            if (!current_actor->transformed_verticies){
-                current_actor->transformed_verticies = malloc(sizeof(RI_vertex) * current_actor->mesh_reference->vertex_count);
-            }
-
-            for (int polygon_index = 0; polygon_index < current_actor->mesh_reference->face_count; ++polygon_index){
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].uv = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].uv;
-
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].uv = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].uv;
-
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].uv = current_actor->mesh_reference->vertecies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].uv;
-
-
-                quaternion_rotate(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position, current_actor->transform.rotation);
-                quaternion_rotate(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position, current_actor->transform.rotation);
-                quaternion_rotate(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position, current_actor->transform.rotation);
-
-                vector_3f_hadamard(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position, current_actor->transform.scale);
-                vector_3f_hadamard(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position, current_actor->transform.scale);
-                vector_3f_hadamard(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position, current_actor->transform.scale);
-            
-                vector_3f_element_wise_add(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position, current_actor->transform.position);
-                vector_3f_element_wise_add(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position, current_actor->transform.position);
-                vector_3f_element_wise_add(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position, current_actor->transform.position);
-            
-                vector_3f_element_wise_subtract(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position, scene->camera_position);
-                vector_3f_element_wise_subtract(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position, scene->camera_position);
-                vector_3f_element_wise_subtract(&current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position, scene->camera_position);
-
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.x = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.x / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.z * horizontal_fov_factor;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.y = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.y / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position.z * vertical_fov_factor;
-                
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.x = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.x / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.z * horizontal_fov_factor;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.y = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.y / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position.z * vertical_fov_factor;
-
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.x = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.x / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.z * horizontal_fov_factor;
-                current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.y = current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.y / current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position.z * vertical_fov_factor;
-            }
-        }
-
+        float horizontal_fov_factor = target_texture->resolution.x / tanf(0.5 * scene->FOV);
+        float vertical_fov_factor = target_texture->resolution.y / tanf(0.5 * scene->FOV);
+        
         for (int pixel_index = 0; pixel_index < target_texture->resolution.x * target_texture->resolution.y; ++pixel_index){
         for (int pixel_index = 0; pixel_index < target_texture->resolution.x * target_texture->resolution.y; ++pixel_index){
             target_texture->image_buffer[pixel_index] = 0x0;
             target_texture->image_buffer[pixel_index] = 0x0;
             ri.z_buffer[pixel_index] = 99999;
             ri.z_buffer[pixel_index] = 99999;
@@ -380,10 +331,67 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
                 for (int actor_index = 0; actor_index < scene->actor_count; ++actor_index){
                 for (int actor_index = 0; actor_index < scene->actor_count; ++actor_index){
                     RI_actor *current_actor = scene->actors[actor_index];
                     RI_actor *current_actor = scene->actors[actor_index];
 
 
+                    if (!current_actor->transformed_vertex_positions){
+                        current_actor->transformed_vertex_positions = malloc(sizeof(RI_vector_3f) * current_actor->mesh_reference->vertex_count);
+                    }
+
                     for (int polygon_index = 0; polygon_index < current_actor->mesh_reference->face_count; ++polygon_index){
                     for (int polygon_index = 0; polygon_index < current_actor->mesh_reference->face_count; ++polygon_index){
-                        RI_vector_3f *pos_0 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].position;
-                        RI_vector_3f *pos_1 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].position;
-                        RI_vector_3f *pos_2 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].position;
+                        int vert_pos_0_index = current_actor->mesh_reference->faces[polygon_index].position_0_index;
+                        int vert_pos_1_index = current_actor->mesh_reference->faces[polygon_index].position_1_index;
+                        int vert_pos_2_index = current_actor->mesh_reference->faces[polygon_index].position_2_index;
+                        
+                        int normal_0_index = current_actor->mesh_reference->faces[polygon_index].normal_0_index;
+                        int normal_1_index = current_actor->mesh_reference->faces[polygon_index].normal_1_index;
+                        int normal_2_index = current_actor->mesh_reference->faces[polygon_index].normal_2_index;
+
+                        int uv_0_index = current_actor->mesh_reference->faces[polygon_index].uv_0_index;
+                        int uv_1_index = current_actor->mesh_reference->faces[polygon_index].uv_1_index;
+                        int uv_2_index = current_actor->mesh_reference->faces[polygon_index].uv_2_index;
+
+                        current_actor->transformed_vertex_positions[vert_pos_0_index] = current_actor->mesh_reference->vertex_positions[vert_pos_0_index];
+                        current_actor->transformed_vertex_positions[vert_pos_1_index] = current_actor->mesh_reference->vertex_positions[vert_pos_1_index];
+                        current_actor->transformed_vertex_positions[vert_pos_2_index] = current_actor->mesh_reference->vertex_positions[vert_pos_2_index];
+                        
+                        // scale
+                        vector_3f_hadamard(&current_actor->transformed_vertex_positions[vert_pos_0_index], current_actor->transform.scale);
+                        vector_3f_hadamard(&current_actor->transformed_vertex_positions[vert_pos_1_index], current_actor->transform.scale);
+                        vector_3f_hadamard(&current_actor->transformed_vertex_positions[vert_pos_2_index], current_actor->transform.scale);
+
+                        // combine camera and object rotation
+                        RI_vector_4f combined_rotation = current_actor->transform.rotation;
+                        RI_vector_4f camera_rotation = scene->camera_rotation;
+                    
+                        quaternion_conjugate(&camera_rotation);
+                        
+                        quaternion_multiply(&combined_rotation, camera_rotation);
+
+                        // rotate
+                        quaternion_rotate(&current_actor->transformed_vertex_positions[vert_pos_0_index], combined_rotation);
+                        quaternion_rotate(&current_actor->transformed_vertex_positions[vert_pos_1_index], combined_rotation);
+                        quaternion_rotate(&current_actor->transformed_vertex_positions[vert_pos_2_index], combined_rotation);
+                        
+                        // object position
+                        vector_3f_element_wise_add(&current_actor->transformed_vertex_positions[vert_pos_0_index], current_actor->transform.position);
+                        vector_3f_element_wise_add(&current_actor->transformed_vertex_positions[vert_pos_1_index], current_actor->transform.position);
+                        vector_3f_element_wise_add(&current_actor->transformed_vertex_positions[vert_pos_2_index], current_actor->transform.position);
+                    
+                        // camera position
+                        vector_3f_element_wise_subtract(&current_actor->transformed_vertex_positions[vert_pos_0_index], scene->camera_position);
+                        vector_3f_element_wise_subtract(&current_actor->transformed_vertex_positions[vert_pos_1_index], scene->camera_position);
+                        vector_3f_element_wise_subtract(&current_actor->transformed_vertex_positions[vert_pos_2_index], scene->camera_position);
+
+                        current_actor->transformed_vertex_positions[vert_pos_0_index].x = current_actor->transformed_vertex_positions[vert_pos_0_index].x / current_actor->transformed_vertex_positions[vert_pos_0_index].z * horizontal_fov_factor;
+                        current_actor->transformed_vertex_positions[vert_pos_0_index].y = current_actor->transformed_vertex_positions[vert_pos_0_index].y / current_actor->transformed_vertex_positions[vert_pos_0_index].z * vertical_fov_factor;
+                        
+                        current_actor->transformed_vertex_positions[vert_pos_1_index].x = current_actor->transformed_vertex_positions[vert_pos_1_index].x / current_actor->transformed_vertex_positions[vert_pos_1_index].z * horizontal_fov_factor;
+                        current_actor->transformed_vertex_positions[vert_pos_1_index].y = current_actor->transformed_vertex_positions[vert_pos_1_index].y / current_actor->transformed_vertex_positions[vert_pos_1_index].z * vertical_fov_factor;
+
+                        current_actor->transformed_vertex_positions[vert_pos_2_index].x = current_actor->transformed_vertex_positions[vert_pos_2_index].x / current_actor->transformed_vertex_positions[vert_pos_2_index].z * horizontal_fov_factor;
+                        current_actor->transformed_vertex_positions[vert_pos_2_index].y = current_actor->transformed_vertex_positions[vert_pos_2_index].y / current_actor->transformed_vertex_positions[vert_pos_2_index].z * vertical_fov_factor;
+
+                        RI_vector_3f *pos_0 = &current_actor->transformed_vertex_positions[vert_pos_0_index];
+                        RI_vector_3f *pos_1 = &current_actor->transformed_vertex_positions[vert_pos_1_index];
+                        RI_vector_3f *pos_2 = &current_actor->transformed_vertex_positions[vert_pos_2_index];
                         
                         
                         RI_material *mat = current_actor->material_reference;
                         RI_material *mat = current_actor->material_reference;
 
 
@@ -414,7 +422,7 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
                         if (vertex_0_out_of_bounds && vertex_1_out_of_bounds && vertex_2_out_of_bounds){
                         if (vertex_0_out_of_bounds && vertex_1_out_of_bounds && vertex_2_out_of_bounds){
                             // continue;
                             // continue;
                         }
                         }
-                        
+                                                    
                         float denominator, w0, w1, w2;
                         float denominator, w0, w1, w2;
 
 
                         denominator = (pos_1->y - pos_2->y) * (pos_0->x - pos_2->x) + (pos_2->x - pos_1->x) * (pos_0->y - pos_2->y);
                         denominator = (pos_1->y - pos_2->y) * (pos_0->x - pos_2->x) + (pos_2->x - pos_1->x) * (pos_0->y - pos_2->y);
@@ -440,9 +448,9 @@ int RI_render(RI_scene *scene, RI_texture *target_texture){
                         uint32_t pixel_color = 0xFF000000;
                         uint32_t pixel_color = 0xFF000000;
                         
                         
                         if (mat->flags & RI_MATERIAL_HAS_TEXTURE){
                         if (mat->flags & RI_MATERIAL_HAS_TEXTURE){
-                            uv_0 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_0_index].uv;
-                            uv_1 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_1_index].uv;
-                            uv_2 = &current_actor->transformed_verticies[current_actor->mesh_reference->faces[polygon_index].vertex_2_index].uv;
+                            uv_0 = &current_actor->mesh_reference->uvs[uv_0_index];
+                            uv_1 = &current_actor->mesh_reference->uvs[uv_1_index];
+                            uv_2 = &current_actor->mesh_reference->uvs[uv_2_index];
 
 
                             double ux = (w0 * (uv_0->x / pos_0->z) + w1 * (uv_1->x / pos_1->z) + w2 * (uv_2->x / pos_2->z)) / w_over_z;
                             double ux = (w0 * (uv_0->x / pos_0->z) + w1 * (uv_1->x / pos_1->z) + w2 * (uv_2->x / pos_2->z)) / w_over_z;
                             double uy = (w0 * (uv_0->y / pos_0->z) + w1 * (uv_1->y / pos_1->z) + w2 * (uv_2->y / pos_2->z)) / w_over_z;                
                             double uy = (w0 * (uv_0->y / pos_0->z) + w1 * (uv_1->y / pos_1->z) + w2 * (uv_2->y / pos_2->z)) / w_over_z;                
@@ -564,7 +572,6 @@ int RI_stop(int result){
     
     
     for (int mesh_index = 0; mesh_index < ri.loaded_mesh_count; ++mesh_index){
     for (int mesh_index = 0; mesh_index < ri.loaded_mesh_count; ++mesh_index){
         free(ri.loaded_meshes[mesh_index].faces); // free face array
         free(ri.loaded_meshes[mesh_index].faces); // free face array
-        free(ri.loaded_meshes[mesh_index].vertecies); // free vertex array
     }
     }
 
 
     for (int texture_index = 0; texture_index < ri.loaded_texture_count; ++texture_index){
     for (int texture_index = 0; texture_index < ri.loaded_texture_count; ++texture_index){

BIN
textures/bill_mcdinner.png


BIN
textures/this is the floor.png