-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicAABB.cpp
48 lines (36 loc) · 1.48 KB
/
DynamicAABB.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "DynamicAABB.hpp"
#include <algorithm>
DynamicAABB::DynamicAABB() : AABB(), m_velocity(), m_acceleration()
{
//ctor
}
DynamicAABB::DynamicAABB(const DynamicAABB& other) : AABB(other), m_velocity(other.m_velocity), m_acceleration(other.m_acceleration)
{
}
DynamicAABB::DynamicAABB(sf::Vector2f position, sf::Vector2f dimension, sf::Vector2f velocity, sf::Vector2f acceleration, CollisionFlags flags) : AABB(position, dimension, flags), m_velocity(velocity), m_acceleration(acceleration)
{
}
DynamicAABB::DynamicAABB(float x, float y, float width, float height, float xVelocity, float yVelocity, float xAcceleration, float yAcceleration, CollisionFlags flags) : AABB(x, y, width, height, flags), m_velocity(xVelocity, yVelocity), m_acceleration(xAcceleration, yAcceleration)
{
}
DynamicAABB::~DynamicAABB()
{
//dtor
}
void DynamicAABB::moveOut(AABB& other)
{
sf::Vector2f minimumDisplacement;
if(m_velocity.x<0.f)
minimumDisplacement.x=m_position.x-(other.m_position.x+other.m_dimension.x);
else
minimumDisplacement.x=-(other.m_position.x-(m_position.x+m_dimension.x));
if(m_velocity.y<0.f)
minimumDisplacement.y=m_position.y-(other.m_position.y+other.m_dimension.y);
else
minimumDisplacement.y=-(other.m_position.y-(m_position.y+m_dimension.y));
if(std::abs(minimumDisplacement.y)<=std::abs(minimumDisplacement.x))
minimumDisplacement.x=0.f;
else
minimumDisplacement.y=0.f;
m_position-=minimumDisplacement;
}