diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Camera.h | 30 | ||||
-rw-r--r-- | src/crepe/api/Texture.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Vector2.cpp | 12 | ||||
-rw-r--r-- | src/crepe/api/Vector2.h | 7 |
4 files changed, 43 insertions, 8 deletions
diff --git a/src/crepe/api/Camera.h b/src/crepe/api/Camera.h index e0cda34..73d4ef4 100644 --- a/src/crepe/api/Camera.h +++ b/src/crepe/api/Camera.h @@ -2,6 +2,7 @@ #include "Color.h" #include "Component.h" +#include "api/Vector2.h" namespace crepe { @@ -27,20 +28,35 @@ public: //! Background color of the camera view. Color bg_color; - //! Aspect ratio height for the camera. - double aspect_height = 480; + Vector2 pos = {0,0}; - //! Aspect ratio width for the camera. - double aspect_width = 640; + Vector2 screen = {640,480}; - //! X-coordinate of the camera position. + Vector2 viewport = {500,500}; + + /* + //! screen width in pixel coordinates + double screen_w = 480; + + //! screen height in pixel coordinates + double screen_h = 640; + + //! screen widht in world units + double viewport_w = 500.0f; + + //! screen height in world units + double viewport_h = 500.0f; + + //! X-coordinate of the camera position. in world space double x = 0.0; - //! Y-coordinate of the camera position. + //! Y-coordinate of the camera position. in world space double y = 0.0; + */ + //! Zoom level of the camera view. - double zoom = 1.0; + double zoom = 1.0f; public: /** diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index de0d0ea..734a5bb 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -35,5 +35,5 @@ int Texture::get_width() const { } int Texture::get_height() const { if (this->texture == nullptr) return 0; - return SDLContext::get_instance().get_width(*this); + return SDLContext::get_instance().get_height(*this); } diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp index 30b968e..c3a49b7 100644 --- a/src/crepe/api/Vector2.cpp +++ b/src/crepe/api/Vector2.cpp @@ -8,11 +8,19 @@ Vector2 Vector2::operator+(const Vector2 & other) const { return {x + other.x, y Vector2 Vector2::operator*(double scalar) const { return {x * scalar, y * scalar}; } +Vector2 Vector2::operator*(const Vector2 & other) const{ + return {this->x * other.x, this->y * other.y}; +} Vector2 & Vector2::operator*=(const Vector2 & other) { x *= other.x; y *= other.y; return *this; } +Vector2 & Vector2::operator*=(const double & other) { + x *= other; + y *= other; + return *this; +} Vector2 & Vector2::operator+=(const Vector2 & other) { x += other.x; @@ -26,6 +34,10 @@ Vector2 & Vector2::operator+=(double other) { return *this; } +Vector2 Vector2::operator/(const Vector2 & other) const { + return {this->x / other.x, this->y / other.y}; +} + Vector2 Vector2::operator-() const { return {-x, -y}; } bool Vector2::operator==(const Vector2 & other) const { return x == other.x && y == other.y; } diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h index 2fb6136..2a5db1d 100644 --- a/src/crepe/api/Vector2.h +++ b/src/crepe/api/Vector2.h @@ -18,9 +18,16 @@ struct Vector2 { //! Multiplies this vector by a scalar and returns the result. Vector2 operator*(double scalar) const; + Vector2 operator*(const Vector2 & other) const; + //! 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 double & other); + + Vector2 operator/(const Vector2 & other) const; + //! Adds another vector to this vector and updates this vector. Vector2 & operator+=(const Vector2 & other); |