diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/api/Camera.h | 13 | ||||
-rw-r--r-- | src/crepe/api/Vector2.h | 11 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 20 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 16 | ||||
-rw-r--r-- | src/crepe/system/RenderSystem.h | 8 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 5 |
6 files changed, 31 insertions, 42 deletions
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<T> & other); - //! Multiplies a scalar value to both components of this vector and updates this vector. - Vector2 & operator*=(const Vector2<T> & other); - - //! Divides this vector by another vector element-wise and updates this vector. - Vector2 operator/(const Vector2<T> & 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<T> & 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<T> & 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 <cmath> #include <cstddef> #include <functional> -#include <iostream> #include <memory> #include <stdexcept> @@ -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 <functional> -#include <vector> +#include <cmath> -#include "api/Vector2.h" #include "facade/SDLContext.h" #include "System.h" -#include <cmath> +#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 <SDL2/SDL_timer.h> #include <crepe/ComponentManager.h> @@ -14,7 +13,7 @@ #include <crepe/api/Sprite.h> #include <crepe/api/Texture.h> #include <crepe/api/Transform.h> -#include <crepe/api/Vector2.h> +#include <crepe/types.h> #include <crepe/system/RenderSystem.h> #include <chrono> @@ -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}; |