#include "AudioDevice.hpp" #include "Color.hpp" #include "Keyboard.hpp" #include "Matrix.hpp" #include "Mesh.hpp" #include "Model.hpp" #include "raylib.h" #include #include #define SKYBOX_IMPLEMENTATION #include "skybox.hpp" void DrawBoundedModel(raylib::Model &model, auto transformer) { // store the original transform to apply a different transform to the // model without affecting the next time we draw raylib::Matrix oldTransform = model.GetTransform(); // apply the transform that we get from whatever the transformer callback // gives us raylib::Matrix transform = transformer(model.GetTransform()); // apply the transform that we got from the transformer to the model model.SetTransform(transform); // draw the model, passing the origin and default scale as arguments since // the transform is already applied to the model model.Draw({ 0, 0, 0 }, 1.0f, raylib::Color::White()); // get the bounding box of the model after applying the transform auto box = model.GetTransformedBoundingBox(); // draw the bounding box of the model using raylib's built in function DrawBoundingBox(box, raylib::Color::White()); // restore the model's transform to its original state so that the next time we // draw the model, it doesn't have the previous transform applied to it model.SetTransform(oldTransform); } int main() { raylib::Window window(800, 600, "CS381 - Assignment 3"); window.SetState(FLAG_WINDOW_RESIZABLE); raylib::AudioDevice audio; raylib::Model penguin("models/penguin.glb"); raylib::Model eagle("models/eagle.glb"); raylib::Camera3D camera( { 0, 120, 500 }, { 0, 0, -1 }, { 0, 1, 0 }, 45.0f); raylib::Model ground = raylib::Mesh::Plane(10000, 10000, 50, 50, 25); cs381::SkyBox skybox("textures/skybox.png"); raylib::Vector3 position = { 0, 0, 0 }; raylib::Vector3 velocity = { 5, 0, 0 }; window.SetTargetFPS(60); // save cpu cycles while (!window.ShouldClose()) { window.BeginDrawing(); window.ClearBackground(raylib::Color::Gray()); float dt = window.GetFrameTime(); position += velocity * dt; camera.BeginMode(); skybox.Draw(); // in addition to the required transforms, the models will rotate 10 // degrees per second (extra credit), and the penguin is scaled by 30 // eagle scaled by 10 // Draw one eagle located at (0, 0, 0), default scale, and with default // orientation (10 points). DrawBoundedModel(penguin, [&position](raylib::Matrix transform) { return transform .Translate(position); }); camera.EndMode(); window.EndDrawing(); } return 0; }