main.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "../headers/rasteriver.h"
  2. int main(){
  3. // get RasterIver context
  4. RasterIver *ri = RI_get_ri();
  5. ri->debug_memory = 0;
  6. RI_init(1000, 1000, "This is RasterIver 2.0!!");
  7. int running = 1;
  8. // data for loading files
  9. char *filenames[] = {"objects/unit_cube.obj", "objects/cow-nonormals.obj", "objects/test_guy.obj", "objects/unit_plane.obj"};
  10. RI_texture_creation_data texture_creation_info[4] = {{"textures/bill_mcdinner.png", {0, 0}}, {"textures/this is the floor.png", {0, 0}}, {"textures/test_guy_texture.png", {0, 0}}, {"textures/THIS IS THE WALL.png", {0, 0}}};
  11. // requesting assets
  12. RI_mesh* meshes = RI_request_meshes(4, filenames, 0);
  13. RI_texture* textures = RI_request_textures(4, texture_creation_info);
  14. RI_material* materials = RI_request_materials(4);
  15. RI_actor* actors = RI_request_actors(4);
  16. RI_scene* scenes = RI_request_scenes(1);
  17. RI_scene* scene = &scenes[0];
  18. // meshes
  19. RI_mesh* unit_plane_mesh = &meshes[3];
  20. RI_mesh* test_object_mesh = &meshes[0];
  21. // textures
  22. RI_texture* test_object_texture = &textures[0];
  23. RI_texture* floor_texture = &textures[1];
  24. RI_texture* wall_texture = &textures[3];
  25. // materials
  26. RI_material* floor_material = &materials[0];
  27. floor_material->flags = RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED | RI_MATERIAL_USE_UV_LOOP_MULTIPLIER;
  28. floor_material->texture_reference = floor_texture;
  29. floor_material->albedo = 0xFFFFFFFF;
  30. floor_material->uv_loop_multiplier = (RI_vector_2f){25, 25};
  31. RI_material* wall_material = &materials[1];
  32. wall_material->flags = RI_MATERIAL_DOUBLE_SIDED | RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_USE_UV_RENDER_RESOLUTION;
  33. wall_material->albedo = 0xFF7777FF;
  34. wall_material->texture_reference = wall_texture;
  35. wall_material->texture_render_size = (RI_vector_2f){25, 50};
  36. RI_material* test_object_material = &materials[2];
  37. test_object_material->flags = RI_MATERIAL_HAS_TEXTURE;
  38. test_object_material->texture_reference = test_object_texture;
  39. test_object_material->albedo = 0xFFFFFFF;
  40. test_object_material->wireframe_width = 0.1;
  41. RI_material* screen_material = &materials[3];
  42. screen_material->flags = RI_MATERIAL_HAS_TEXTURE | RI_MATERIAL_DOUBLE_SIDED;
  43. screen_material->texture_reference = ri->frame_buffer;
  44. screen_material->albedo = 0xFFFFFFFF;
  45. // actors
  46. RI_actor* floor = &actors[0];
  47. floor->material_reference = floor_material;
  48. floor->mesh_reference = unit_plane_mesh;
  49. floor->transform.scale = (RI_vector_3f){1000, 100, 1000};
  50. floor->transform.position = (RI_vector_3f){0, -100, 200};
  51. floor->transform.rotation = (RI_vector_4f){0, 1, 0, 0};
  52. RI_actor* wall = &actors[1];
  53. wall->material_reference = wall_material;
  54. wall->mesh_reference = unit_plane_mesh;
  55. wall->transform.scale = (RI_vector_3f){100, 100, 100};
  56. wall->transform.position = (RI_vector_3f){0, 0, 300};
  57. wall->transform.rotation = (RI_vector_4f){0.70710678, 0.70710678, 0, 0};
  58. RI_actor* test_object = &actors[2];
  59. test_object->material_reference = test_object_material;
  60. test_object->mesh_reference = test_object_mesh;
  61. test_object->transform.scale = (RI_vector_3f){50, 50, 50};
  62. test_object->transform.position = (RI_vector_3f){-50, 100, 100};
  63. test_object->transform.rotation = (RI_vector_4f){0, 1, 0, 0};
  64. RI_actor* screen = &actors[3];
  65. screen->material_reference = screen_material;
  66. screen->mesh_reference = unit_plane_mesh;
  67. screen->transform.scale = (RI_vector_3f){50, 50, 50};
  68. screen->transform.position = (RI_vector_3f){0, 0, 250};
  69. screen->transform.rotation = (RI_vector_4f){0, 1, 0, 0};
  70. RI_add_actors_to_scene(4, actors, scene);
  71. scene->FOV = 1.5; // 90 degrees in radians
  72. scene->minimum_clip_distance = 0.1;
  73. RI_euler_rotation_to_quaternion(&scene->camera_rotation, (RI_vector_3f){0, 0, 0});
  74. double y_rotation = 0;
  75. scene->antialiasing_subsample_resolution = 8;
  76. scene->flags = RI_SCENE_DONT_USE_AA;
  77. while (running){
  78. test_object->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};
  79. RI_euler_rotation_to_quaternion(&screen->transform.rotation, (RI_vector_3f){-3.14159 / 2, 0, ri->frame * 0.03});
  80. // scene->camera_position = (RI_vector_3f){cos(ri->frame * 0.07) * 10 * sin(ri->frame * 0.2), sin(ri->frame * 0.07) * 10 * sin(ri->frame * 0.2), -300};
  81. scene->camera_position = (RI_vector_3f){0, 0, -300};
  82. wall->transform.scale.x = fabs(sin(y_rotation)) * 100 + 70;
  83. // RI_euler_rotation_to_quaternion(&scene->camera_rotation, (RI_vector_3f){0, y_rotation * .01 + 1.5, 0});
  84. // RI_euler_rotation_to_quaternion(&floor->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
  85. RI_euler_rotation_to_quaternion(&test_object->transform.rotation, (RI_vector_3f){y_rotation, y_rotation, y_rotation});
  86. // RI_euler_rotation_to_quaternion(&test_object->transform.rotation, (RI_vector_3f){0, y_rotation, 0});
  87. y_rotation += 0.1;
  88. RI_render(scene, ri->frame_buffer);
  89. RI_tick();
  90. }
  91. }