diff --git a/src/GUI/MainWindow.cpp b/src/GUI/MainWindow.cpp index 9798312..034cfa5 100644 --- a/src/GUI/MainWindow.cpp +++ b/src/GUI/MainWindow.cpp @@ -164,7 +164,12 @@ void MainWindow::draw_frame(){ //Resources::Texture tutel(Resources::getResource("tutel.png"), sdl_renderer); static Resources::CacheStorage textures; Resources::Texture& tutel = textures.getOrCreate("tutel.png", sdl_renderer); - tutel.render(SDL_FRectConstruct(100, 100, 400, 400)); + Resources::SDL_RenderCopyExF_Params rp; + rp.target_section = SDL_FRectConstruct(100, 100, 400, 400); + static int si = 1; + rp.rotation_angle = M_PI_4 * (si++ / fps_max); + tutel.render(rp); + ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), sdl_renderer); // Swap buffers @@ -193,7 +198,6 @@ void MainWindow::startUpdateLoop(){ nsec_t after_update_time_ns = getMonotonicTimeNsec(); nsec_t frame_delay_ns = (nsec_t)1e9 / fps_max - (after_update_time_ns - update_time_ns); if(frame_delay_ns > 0){ - std::cout<<"frameDelay: "< + +class GameObject { +public: + Vec2 scale = { 1, 1 }; + Vec2 position; + angle_t rotation; + +private: + // std::set components; +}; + diff --git a/src/Game/Scene.hpp b/src/Game/Scene.hpp new file mode 100644 index 0000000..0a7c399 --- /dev/null +++ b/src/Game/Scene.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "GameObject.hpp" + +class Scene { + +}; diff --git a/src/Resources/textures.cpp b/src/Resources/textures.cpp index f400471..321c125 100644 --- a/src/Resources/textures.cpp +++ b/src/Resources/textures.cpp @@ -41,7 +41,7 @@ void Texture::render(const SDL_RenderCopyExF_Params& p){ SDL_RenderCopyExF(renderer, texture.get(), optional_value_ptr_or_null(p.texture_section), optional_value_ptr_or_null(p.target_section), - p.rotation_angle, + -1.0f * angleToDegree(normalizeAngle(p.rotation_angle)), optional_value_ptr_or_null(p.rotation_center), p.flip ) diff --git a/src/Resources/textures.hpp b/src/Resources/textures.hpp index 4c8a5fb..9c422d4 100644 --- a/src/Resources/textures.hpp +++ b/src/Resources/textures.hpp @@ -6,6 +6,7 @@ #include #include #include "Resources.hpp" +#include "../math.hpp" namespace ougge::Resources { @@ -22,7 +23,7 @@ struct SDL_RenderCopyExF_Params { std::optional texture_section; std::optional target_section; std::optional rotation_center; - double rotation_angle; + angle_t rotation_angle; SDL_RendererFlip flip; SDL_RenderCopyExF_Params(); diff --git a/src/main.cpp b/src/main.cpp index 1e862dd..c0393ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,15 +1,15 @@ #define SDL_MAIN_HANDLED #include -#include "std.hpp" #include "GUI/MainWindow.hpp" #include "Resources/Resources.hpp" +#include "Game/Scene.hpp" #include "format.hpp" #include "exceptions.hpp" using namespace ougge; void update(f64 deltaTime){ - std::cout<<"deltaTime: "< + +struct Vec2 { + f32 x = 0, y = 0; +}; + +struct Vec3 { + f32 x = 0, y = 0, z = 0; +}; + +struct Vec4 { + f32 x = 0, y = 0, z = 0, w = 0; +}; + +/// radians +typedef f32 angle_t; + +static inline angle_t normalizeAngle(angle_t a){ + return std::fmodf(a + M_PI, 2*M_PI) - M_PI; +} + +static inline f32 angleToDegree(angle_t a){ + return (a / M_PI) * 180; +} + +static inline angle_t degreeToRadian(f32 d){ + return (d / 180) * M_PI; +} \ No newline at end of file