From 8cfb59093ce7b18c2b81cc8429a7568a3ba21a73 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Tue, 26 Nov 2024 10:03:06 +0100 Subject: adjusted vector2 to vec2 --- src/crepe/api/Camera.h | 13 +++++++------ src/crepe/api/Vector2.h | 11 ++--------- src/crepe/facade/SDLContext.cpp | 20 +++++++++----------- src/crepe/facade/SDLContext.h | 16 ++++++++-------- src/crepe/system/RenderSystem.h | 8 +++----- src/example/rendering_particle.cpp | 5 ++--- 6 files changed, 31 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index 137c8ed..eea1b28 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -2,7 +2,8 @@ #include "Color.h" #include "Component.h" -#include "api/Vector2.h" + +#include "types.h" namespace crepe { @@ -29,15 +30,15 @@ public: Color bg_color; //! pos The position of the camera in world units - Vector2 pos = {0, 0}; + vec2 pos = {0, 0}; //! screen the display size in pixels ( output resolution ) - //Vector2 screen = {720, 480}; - Vector2 screen = {1080, 720}; + //vec2 screen = {720, 480}; + vec2 screen = {1080, 720}; //! viewport is the area of the world visible through the camera (in world units) - //Vector2 viewport = {720, 480}; - Vector2 viewport = {2000, 1000}; + //vec2 viewport = {720, 480}; + vec2 viewport = {2000, 1000}; //! scale scaling factor from world units to pixel coordinates //! Zoom level of the camera view. diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h index 019d849..0688fac 100644 --- a/src/crepe/api/Vector2.h +++ b/src/crepe/api/Vector2.h @@ -34,15 +34,11 @@ struct Vector2 { //! Multiplies this vector by another vector element-wise and updates this vector. Vector2 & operator*=(const Vector2 & other); - //! Multiplies a scalar value to both components of this vector and updates this vector. - Vector2 & operator*=(const Vector2 & other); - - //! Divides this vector by another vector element-wise and updates this vector. - Vector2 operator/(const Vector2 & other) const; - //! Divides a scalar value to both components of this vector and updates this vector. Vector2 operator/(const T & other) const; + Vector2 operator/(T other) const; + //! Adds another vector to this vector and updates this vector. Vector2 & operator+=(const Vector2 & other); @@ -55,9 +51,6 @@ struct Vector2 { //! Subtracts a scalar value from both components of this vector and updates this vector. Vector2 & operator-=(T other); - //! Multiplies this vector by another vector element-wise and updates this vector. - Vector2 & operator*=(const Vector2 & other); - //! Multiplies this vector by a scalar and updates this vector. Vector2 & operator*=(T other); diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index de7d08f..fc59d84 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -16,10 +15,9 @@ #include "../api/Sprite.h" #include "../api/Texture.h" #include "../api/Transform.h" -#include "../api/Vector2.h" #include "../util/Log.h" -#include "api/Vector2.h" +#include "types.h" #include "SDLContext.h" using namespace crepe; @@ -108,9 +106,9 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const { .h = sprite.sprite_rect.h, }; } -SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos, - const Vector2 & cam_pos, const double & img_scale, - const Vector2 & cam_scale) const { +SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, + const vec2 & cam_pos, const double & img_scale, + const vec2 & cam_scale) const { int pixel_width, pixel_height; @@ -136,9 +134,9 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const Vector2 & pos, }; } -void SDLContext::draw_particle(const Sprite & sprite, const Vector2 & pos, - const double & angle, const Vector2 & cam_pos, - const double & img_scale, const Vector2 & cam_scale) { +void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, + const double & angle, const vec2 & cam_pos, + const double & img_scale, const vec2 & cam_scale) { SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -152,7 +150,7 @@ void SDLContext::draw_particle(const Sprite & sprite, const Vector2 & pos, } void SDLContext::draw(const Sprite & sprite, const Transform & transform, - const Vector2 & cam_pos, const Vector2 & cam_scale) { + const vec2 & cam_pos, const vec2 & cam_scale) { SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -166,7 +164,7 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, &dstrect, transform.rotation, NULL, render_flip); } -void SDLContext::set_camera(const Camera & cam, Vector2 & scale) { +void SDLContext::set_camera(const Camera & cam, vec2 & scale) { // resize window if (this->viewport.w != (int) cam.screen.x || this->viewport.h != (int) cam.screen.y) { diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index aed5797..c9f3299 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -120,8 +120,8 @@ private: * \param cam_pos position of the current camera in the scene * \param cam_scale multiplier for the world to screen */ - void draw(const Sprite & sprite, const Transform & transform, const Vector2 & cam_pos, - const Vector2 & cam_scale); + void draw(const Sprite & sprite, const Transform & transform, const vec2 & cam_pos, + const vec2 & cam_scale); /** * \brief Draws a particle to the screen using the specified parameters @@ -133,9 +133,9 @@ private: * \param img_scale scalar multiplier to increase image size * \param cam_scale camera scalar for world to screen */ - void draw_particle(const Sprite & sprite, const Vector2 & pos, const double & angle, - const Vector2 & cam_pos, const double & img_scale, - const Vector2 & cam_scale); + void draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle, + const vec2 & cam_pos, const double & img_scale, + const vec2 & cam_scale); //! Clears the screen, preparing for a new frame. void clear_screen(); @@ -147,7 +147,7 @@ private: * \brief sets the background of the camera (will be adjusted in future PR) * \param camera Reference to the Camera object. */ - void set_camera(const Camera & camera, Vector2 & scale); + void set_camera(const Camera & camera, vec2 & scale); private: /** @@ -168,8 +168,8 @@ private: * \param scale the multiplier for world to screen * \return sdl rectangle to draw a dst image to draw on the screen */ - SDL_Rect get_dst_rect(const Sprite & sprite, const Vector2 & pos, const Vector2 & cam_pos, - const double & img_scale, const Vector2 & scale) const; + SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const vec2 & cam_pos, + const double & img_scale, const vec2 & scale) const; private: //! sdl Window diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index f010a83..97222f3 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -1,13 +1,11 @@ #pragma once -#include -#include +#include -#include "api/Vector2.h" #include "facade/SDLContext.h" #include "System.h" -#include +#include "types.h" namespace crepe { @@ -82,7 +80,7 @@ private: Camera * curr_cam_ref = nullptr; // TODO: needs a better solution - Vector2 scale; + vec2 scale; SDLContext & context = SDLContext::get_instance(); }; diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 49e8e9d..80726bc 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -2,7 +2,6 @@ #include "api/Camera.h" #include "system/AnimatorSystem.h" #include "system/ParticleSystem.h" -#include "types.h" #include #include @@ -14,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -25,7 +24,7 @@ using namespace std; int main(int argc, char * argv[]) { ComponentManager mgr; - GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 1); + GameObject game_object = mgr.new_object("", "", vec2{0, 0}, 0, 1); RenderSystem sys{mgr}; ParticleSystem psys{mgr}; AnimatorSystem asys{mgr}; -- cgit v1.2.3