Browse Source

added fov

iver 7 months ago
parent
commit
f3c78b4061

BIN
builds/final binaries/librasteriver.so


BIN
builds/final binaries/main.bin


+ 13 - 8
src/RasterIver/source code/rasteriver.c

@@ -61,6 +61,8 @@ SDL_Texture *texture;
 
 
 int *texture_info;
 int *texture_info;
 
 
+float fov = 90 * RI_PI / 180;
+
 RI_uint *frame_buffer;
 RI_uint *frame_buffer;
 
 
 char *font_file = "src/fonts/OxygenMono.ttf";
 char *font_file = "src/fonts/OxygenMono.ttf";
@@ -1045,7 +1047,10 @@ RI_result RI_Tick(){
         } 
         } 
 
 
         if (use_cpu){
         if (use_cpu){
-for (int id_y = -height / 2; id_y < height / 2; id_y++){
+            float vertical_fov_factor = height / tanf(0.5 * fov);
+            float horizontal_fov_factor = width / tanf(0.5 * fov);
+
+            for (int id_y = -height / 2; id_y < height / 2; id_y++){
 for (int id_x = -width / 2; id_x < width / 2; id_x++){
 for (int id_x = -width / 2; id_x < width / 2; id_x++){
             float z_pixel = INFINITY; 
             float z_pixel = INFINITY; 
     unsigned int frame_pixel = 0x22222222; 
     unsigned int frame_pixel = 0x22222222; 
@@ -1119,16 +1124,16 @@ for (int id_x = -width / 2; id_x < width / 2; id_x++){
                 rotate_euler(&x1, &y1, &z1, object_r_x, object_r_y, object_r_z);
                 rotate_euler(&x1, &y1, &z1, object_r_x, object_r_y, object_r_z);
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);
                 rotate_euler(&x2, &y2, &z2, object_r_x, object_r_y, object_r_z);
             }
             }
-            
+
             z0 = (z0 * object_s_z + object_z);
             z0 = (z0 * object_s_z + object_z);
-            x0 = (x0 * object_s_x + object_x) / z0 * width;
-            y0 = (y0 * object_s_y + object_y) / z0 * height;
+            x0 = (x0 * object_s_x + object_x) / z0 * horizontal_fov_factor;
+            y0 = (y0 * object_s_y + object_y) / z0 * vertical_fov_factor;
             z1 = (z1 * object_s_z + object_z);
             z1 = (z1 * object_s_z + object_z);
-            x1 = (x1 * object_s_x + object_x) / z1 * width;
-            y1 = (y1 * object_s_y + object_y) / z1 * height;
+            x1 = (x1 * object_s_x + object_x) / z1 * horizontal_fov_factor;
+            y1 = (y1 * object_s_y + object_y) / z1 * vertical_fov_factor;
             z2 = (z2 * object_s_z + object_z);
             z2 = (z2 * object_s_z + object_z);
-            x2 = (x2 * object_s_x + object_x) / z2 * width;
-            y2 = (y2 * object_s_y + object_y) / z2 * height;
+            x2 = (x2 * object_s_x + object_x) / z2 * horizontal_fov_factor;
+            y2 = (y2 * object_s_y + object_y) / z2 * vertical_fov_factor;
             
             
             if (i3 < 0 || i4 < 0 || i5 < 0){
             if (i3 < 0 || i4 < 0 || i5 < 0){
                 has_normals = 0;
                 has_normals = 0;

+ 6 - 2
src/launch program/main.c

@@ -28,7 +28,7 @@ int main(){
     }
     }
 
 
     RI_newObject object_buffer[6] = {
     RI_newObject object_buffer[6] = {
-        {-300, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
+        {0, 0, 300,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
         {0, 0, 1000,         0, 0, 0, -9999999,  100, 100, 100,     "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
         {0, 0, 1000,         0, 0, 0, -9999999,  100, 100, 100,     "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
         {100, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
         {100, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
         {300, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
         {300, 0, 1000,       0, 0, 0, -9999999,          100, 100, 100,  "objects/test_guy_hd.obj", "textures/test_guy_texture.png"},
@@ -36,9 +36,13 @@ int main(){
         {0, 0, 300,      0, 0.0, 0, -9999999,          50, 50, 50,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
         {0, 0, 300,      0, 0.0, 0, -9999999,          50, 50, 50,  "objects/rotated_cube.obj", "textures/bill_mcdinner.png"},
     };
     };
 
 
-    RI_objects objects = RI_RequestObjects(object_buffer, 4);
+    RI_objects objects = RI_RequestObjects(object_buffer, 1);
 
 
     while (RI_IsRunning() == RI_RUNNING){
     while (RI_IsRunning() == RI_RUNNING){
+        objects[3] += 0.1;
+        objects[4] += 0.2;
+        objects[5] += 0.3;
+
         RI_Tick();
         RI_Tick();
     }
     }