]> git.seodisparate.com - RockPaperScissorsDuel/commitdiff
Begin work on Renderer3D
authorStephen Seo <seo.disparate@gmail.com>
Thu, 12 Jan 2023 03:34:43 +0000 (12:34 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 12 Jan 2023 03:34:43 +0000 (12:34 +0900)
src/3d_renderer.cc
src/3d_renderer.h
src/main.cc

index f09fcbb3ac67ba697851e7772908c9a11e719795..3e8fc267fd42ef0b56183c09ee35bf6bb64d2348 100644 (file)
@@ -1,8 +1,63 @@
 #include "3d_renderer.h"
 
-Renderer3D::Renderer3D() {}
+#include <raylib.h>
 
-Renderer3D::~Renderer3D() {}
+Renderer3D::Renderer3D() {
+  camera.position.x = 0.0F;
+  camera.position.y = 5.0F;
+  camera.position.z = 10.0F;
+
+  camera.up.x = 0.0F;
+  camera.up.y = 1.0F;
+  camera.up.z = 0.0F;
+
+  camera.target.x = 0.0F;
+  camera.target.y = 0.0F;
+  camera.target.z = 0.0F;
+
+  camera.fovy = 45.0F;
+
+  camera.projection = CAMERA_PERSPECTIVE;
+
+  skybox_texture = LoadTexture("resources/skybox.gif");
+  platform_texture = LoadTexture("resources/platform_texture.png");
+  qm_texture = LoadTexture("resources/question_mark_texture.png");
+  rock_texture = LoadTexture("resources/rock_texture.png");
+  paper_texture = LoadTexture("resources/paper_texture.png");
+  scissors_texture = LoadTexture("resources/scissors_texture.png");
+
+  skybox_model = LoadModel("resources/skybox.obj");
+  platform_model = LoadModel("resources/platform.obj");
+  qm_model = LoadModel("resources/question_mark.obj");
+  rock_model = LoadModel("resources/rock.obj");
+  paper_model = LoadModel("resources/paper.obj");
+  scissors_model = LoadModel("resources/scissors.obj");
+
+  skybox_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = skybox_texture;
+  platform_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
+      platform_texture;
+  qm_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = qm_texture;
+  rock_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = rock_texture;
+  paper_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = paper_texture;
+  scissors_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
+      scissors_texture;
+}
+
+Renderer3D::~Renderer3D() {
+  UnloadTexture(skybox_texture);
+  UnloadTexture(platform_texture);
+  UnloadTexture(qm_texture);
+  UnloadTexture(rock_texture);
+  UnloadTexture(paper_texture);
+  UnloadTexture(scissors_texture);
+
+  UnloadModel(skybox_model);
+  UnloadModel(platform_model);
+  UnloadModel(qm_model);
+  UnloadModel(rock_model);
+  UnloadModel(paper_model);
+  UnloadModel(scissors_model);
+}
 
 void Renderer3D::update_state(const char *playerOne, const char *playerTwo,
                               const char *currentPlayer, char first_first,
@@ -19,6 +74,14 @@ void Renderer3D::do_update() {
 
 void Renderer3D::screen_size_changed() {}
 
-void Renderer3D::update_impl() {}
+void Renderer3D::update_impl() { UpdateCamera(&camera); }
 
-void Renderer3D::draw_impl() {}
+void Renderer3D::draw_impl() {
+  BeginDrawing();
+  BeginMode3D(camera);
+  DrawModel(skybox_model, root_pos, 1.0F, WHITE);
+  DrawModel(platform_model, root_pos, 1.0F, WHITE);
+  DrawModel(qm_model, {0.0F, 1.0F, 0.0F}, 1.0F, WHITE);
+  EndMode3D();
+  EndDrawing();
+}
index a6adcd2849a5060d97b8b26b0461b1049de54520..96098fd9c95c96427735866b0643a5bdc3ee4db8 100644 (file)
@@ -1,8 +1,12 @@
 #ifndef ROCK_PAPER_SCISSORS_3D_RENDERER_H_
 #define ROCK_PAPER_SCISSORS_3D_RENDERER_H_
 
+// required dependency include
 #include "game_renderer.h"
 
+// third party includes
+#include <raylib.h>
+
 class Renderer3D : public GameRenderer {
  public:
   Renderer3D();
@@ -22,6 +26,24 @@ class Renderer3D : public GameRenderer {
  private:
   void update_impl();
   void draw_impl();
+
+  Camera camera;
+
+  Texture2D skybox_texture;
+  Texture2D platform_texture;
+  Texture2D qm_texture;
+  Texture2D rock_texture;
+  Texture2D paper_texture;
+  Texture2D scissors_texture;
+
+  Model skybox_model;
+  Model platform_model;
+  Model qm_model;
+  Model rock_model;
+  Model paper_model;
+  Model scissors_model;
+
+  Vector3 root_pos;
 };
 
 #endif
index b8b229c9cc6db8e5a23613ff823bf2d414e29d35..10ebcda717eead5c8bb72313d7deadba36d8f3de 100644 (file)
@@ -15,6 +15,7 @@
 #include <raylib.h>
 
 // local includes
+#include "3d_renderer.h"
 #include "basic_renderer.h"
 #include "constants.h"
 #include "game_renderer.h"
@@ -60,7 +61,7 @@ int main() {
   InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "RPSDuel_Native");
 #endif
 
-  std::unique_ptr<GameRenderer> renderer = std::make_unique<BasicRenderer>();
+  std::unique_ptr<GameRenderer> renderer = std::make_unique<Renderer3D>();
 
 #ifdef __EMSCRIPTEN__
   global_game_ptr = renderer.get();