aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/Vector2.cpp10
-rw-r--r--src/crepe/api/Vector2.h13
-rw-r--r--src/example/collision.cpp12
3 files changed, 21 insertions, 14 deletions
diff --git a/src/crepe/api/Vector2.cpp b/src/crepe/api/Vector2.cpp
index 09bb59b..947c49e 100644
--- a/src/crepe/api/Vector2.cpp
+++ b/src/crepe/api/Vector2.cpp
@@ -3,7 +3,7 @@
namespace crepe {
// Constructor with initial values
-Vector2::Vector2(float x, float y) : x(x), y(y) {}
+Vector2::Vector2(double x, double y) : x(x), y(y) {}
// Subtracts another vector from this vector and returns the result.
Vector2 Vector2::operator-(const Vector2 & other) const {
@@ -16,7 +16,7 @@ Vector2 Vector2::operator+(const Vector2 & other) const {
}
// Multiplies this vector by a scalar and returns the result.
-Vector2 Vector2::operator*(float scalar) const {
+Vector2 Vector2::operator*(double scalar) const {
return {x * scalar, y * scalar};
}
@@ -35,7 +35,7 @@ Vector2 & Vector2::operator+=(const Vector2 & other) {
}
// Adds a scalar value to both components of this vector and updates this vector.
-Vector2 & Vector2::operator+=(float other) {
+Vector2 & Vector2::operator+=(double other) {
x += other;
y += other;
return *this;
@@ -54,4 +54,8 @@ bool Vector2::operator!=(const Vector2 & other) const {
return !(*this == other);
}
+double Vector2::dot(const Vector2& other) const {
+ return this->x * other.x + this->y * other.y;
+}
+
} // namespace crepe
diff --git a/src/crepe/api/Vector2.h b/src/crepe/api/Vector2.h
index 741951b..90d9d57 100644
--- a/src/crepe/api/Vector2.h
+++ b/src/crepe/api/Vector2.h
@@ -6,15 +6,15 @@ namespace crepe {
class Vector2 {
public:
//! X component of the vector
- float x;
+ double x;
//! Y component of the vector
- float y;
+ double y;
//! Default constructor
Vector2() = default;
//! Constructor with initial values
- Vector2(float x, float y);
+ Vector2(double x, double y);
//! Subtracts another vector from this vector and returns the result.
Vector2 operator-(const Vector2 & other) const;
@@ -23,7 +23,7 @@ public:
Vector2 operator+(const Vector2 & other) const;
//! Multiplies this vector by a scalar and returns the result.
- Vector2 operator*(float scalar) const;
+ Vector2 operator*(double scalar) const;
//! Multiplies this vector by another vector element-wise and updates this vector.
Vector2 & operator*=(const Vector2 & other);
@@ -32,7 +32,7 @@ public:
Vector2 & operator+=(const Vector2 & other);
//! Adds a scalar value to both components of this vector and updates this vector.
- Vector2 & operator+=(float other);
+ Vector2 & operator+=(double other);
//! Returns the negation of this vector.
Vector2 operator-() const;
@@ -42,6 +42,9 @@ public:
//! Checks if this vector is not equal to another vector.
bool operator!=(const Vector2 & other) const;
+
+ //!
+ double dot(const Vector2& other) const;
};
} // namespace crepe
diff --git a/src/example/collision.cpp b/src/example/collision.cpp
index 9faac69..dc97c81 100644
--- a/src/example/collision.cpp
+++ b/src/example/collision.cpp
@@ -13,7 +13,7 @@ using namespace std;
int main(int argc, char * argv[]) {
- GameObject game_object1(0, "Name", "Tag", Vector2{1, 1}, 90, 1);
+ GameObject game_object1(0, "Name", "Tag", Vector2{10, 10}, 0, 1);
game_object1.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
.gravity_scale = 1,
@@ -21,11 +21,11 @@ int main(int argc, char * argv[]) {
.constraints = {0, 0, 0},
.use_gravity = true,
.bounce = false,
- .offset = {3,3}
+ .offset = {0,0}
});
- game_object1.add_component<BoxCollider>(Vector2{5, 5}, 100, 50);
+ game_object1.add_component<BoxCollider>(Vector2{5, 5}, 5, 5);
- GameObject game_object2(1, "Name", "Tag", Vector2{20, 2}, 90, 1);
+ GameObject game_object2(1, "Name", "Tag", Vector2{20, 0}, 90, 1);
game_object2.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
.gravity_scale = 1,
@@ -33,9 +33,9 @@ int main(int argc, char * argv[]) {
.constraints = {0, 0, 0},
.use_gravity = true,
.bounce = false,
- .offset = {4,4}
+ .offset = {0,0}
});
- game_object2.add_component<BoxCollider>(Vector2{6, 6}, 100, 50);
+ game_object2.add_component<BoxCollider>(Vector2{5, 5}, 5, 5);
CollisionSystem coltest;
coltest.update();
return 0;