aboutsummaryrefslogtreecommitdiff
path: root/mwe/events/include/customTypes.h
blob: 5a7851b65987eda316a14eb46cf0e9e0da7fe3a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#pragma once
#include <cmath>
struct Vector2 {
	float x; // X component of the vector
	float y; // Y component of the vector

	// Vector subtraction
	Vector2 operator-(const Vector2 & other) const { return {x - other.x, y - other.y}; }

	// Vector addition
	Vector2 operator+(const Vector2 & other) const { return {x + other.x, y + other.y}; }

	// Scalar multiplication
	Vector2 operator*(float scalar) const { return {x * scalar, y * scalar}; }

	// Normalize the vector
	Vector2 normalize() const {
		float length = std::sqrt(x * x + y * y);
		if (length == 0) return {0, 0}; // Prevent division by zero
		return {x / length, y / length};
	}
};
struct Collision {
	int objectIdA; // ID of the first object
	int objectIdB; // ID of the second object
	Vector2 contactPoint; // Point of contact
	Vector2 contactNormal; // Normal vector at the contact point

	// Constructor to initialize a Collision
	Collision(int idA, int idB, const Vector2 & point, const Vector2 & normal, float depth)
		: objectIdA(idA),
		  objectIdB(idB),
		  contactPoint(point),
		  contactNormal(normal) {}
};