-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAEObject.cpp
268 lines (222 loc) · 6.21 KB
/
AEObject.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include "AEObject.h"
using namespace std;
using namespace boost;
/*
*--------------------------------*
|-------- Namespace AE ---------|
*--------------------------------*
*/
namespace AE
{
/*
_____________________________
/ \
| La classe CollisionEvents |
\______________________________/
*/
CollisionEvents::CollisionEvents() : there_is_collision(false), first_object( (Object*)NULL ), second_object( (Object*)NULL ), recul_first_object( DVector2D() ), recul_second_object( DVector2D() )
{
}
CollisionEvents::CollisionEvents(bool f_there_is_collision, ObjectPtr f_first_object, ObjectPtr f_second_object, DVector2D f_recul_first_object, DVector2D f_recul_second_object)
{
there_is_collision = f_there_is_collision;
first_object = f_first_object;
second_object = f_second_object;
recul_first_object = f_recul_first_object;
recul_second_object = f_recul_second_object;
}
CollisionEvents::~CollisionEvents()
{
}
/*
___________________
/ \
| La classe Object |
\____________________/
*/
Type Object::AnyObject = 0;
Type Object::Point = 1;
Type Object::AABB = 2;
Type Object::Triangle = 3;
Type Object::Circle = 4;
Object::Object(bool is_static) : connected_with( shared_ptr<Spr>( (Spr *) NULL ) ), m_static(is_static), m_boundingBox()
{
m_type.push_back(Object::AnyObject);
calculateBoundingBox();
}
Object::~Object()
{
}
DRect &Object::getBoundingBox()
{
return m_boundingBox;
}
void Object::calculateBoundingBox()
{
}
DVector2D &Object::getPos()
{
return m_boundingBox;
}
void Object::setPos(DVector2D &new_pos)
{
m_vitesse = DRect(new_pos.x - m_boundingBox.x, new_pos.y - m_boundingBox.y);
//m_position = new_pos;
//m_boundingBox += m_vitesse;
avancer(m_vitesse);
}
void Object::avancer(DVector2D &to_add)
{
m_vitesse = to_add;
m_boundingBox += to_add;
// m_position.x += to_add.x;
// m_position.y += to_add.y;
}
DVector2D &Object::getVitesse()
{
return m_vitesse;
}
void Object::setStatic(bool is_static)
{
m_static = is_static;
}
bool Object::isStatic()
{
return m_static;
}
CollisionEvents Object::collisionWith(ObjectPtr &object)
{
return CollisionEvents(); // Par défaut, il n'y a aucune collision :p
}
/*
___________________
/ \
| La classe OPoint |
\____________________/
*/
OPoint::OPoint(DVector2D _position_point, bool is_static) : position_point(_position_point), Object::Object(is_static)
{
m_type.push_back(Object::Point);
}
OPoint::~OPoint()
{
}
void OPoint::avancer(DVector2D &v)
{
Object::avancer(v);
position_point += v;
}
void OPoint::calculateBoundingBox()
{
m_boundingBox = DRect(position_point);
m_boundingBox.w = 0;
m_boundingBox.h = 0;
}
CollisionEvents OPoint::collisionWith(ObjectPtr &object)
{
/*CollisionEvents result(false, ObjectPtr(this), object);
if( object->isType(Object::Point) )
{
DRect pos_point_1(m_position.x + pos_relative.x, m_position.y + pos_relative.y);
DRect pos_point_2(object->getPos().x, object->getPos().y);
if(pos_point_1 == pos_point_2)
{
result.there_is_collision = true;
if(m_static)
{
if( !object->isStatic() )
{
result.recul_second_object = pos_point_2 - pos_point_1;
}
}
else
{
if( object->isStatic() )
{
result.recul_first_object = DRect(-1, -1);
}
else
{
result.recul_first_object = DRect(-1, -1);
result.recul_second_object = DRect(1, 1);
}
}
}
}
else if(object->isType(Object::AABB) )
{
DRect pos_point(m_position.x + pos_relative.x, m_position.y + pos_relative.y);
DRect aabb_rect(object->getPos().x + ( (OAABB*)( object.get() ) )->rectangle.x, object->getPos().y +
((OAABB*)object.get())->rectangle.y, ((OAABB*)object.get())->rectangle.w, ((OAABB*)object.get())->rectangle.h);
result.there_is_collision = true;
if(m_static)
{
if(!object->isStatic() )
{
result.recul_second_object -= result.second_object->getVitesse();
}
}
else
{
if(object->isStatic() )
{
result.recul_first_object -= result.first_object->getVitesse();
}
else
{
result.recul_first_object -= result.first_object->getVitesse();
result.recul_second_object -= result.second_object->getVitesse();
}
}
}
return result;*/
}
/*
___________________
/ \
| La classe OAABB |
\____________________/
*/
OAABB::OAABB(DRect _rectangle, bool is_static) : rectangle(_rectangle), Object::Object(is_static)
{
m_type.push_back(Object::AABB);
}
OAABB::~OAABB()
{
}
void OAABB::avancer(DVector2D &v)
{
Object::avancer(v);
rectangle += v;
}
void OAABB::calculateBoundingBox()
{
m_boundingBox = rectangle;
}
void OAABB::operator=(OAABB &to_copy)
{
m_boundingBox = to_copy.m_boundingBox;
rectangle = to_copy.rectangle;
}
CollisionEvents OAABB::collisionWith(ObjectPtr &object)
{
/*CollisionEvents collision_info;
if(object->isType(Object::AABB) ) // Si on teste la collision avec une boîte AABB
{
shared_ptr<OAABB> aabb_object( (OAABB*)object.get() );
DRect this_aabb = DRect(m_position.x + rectangle.x, m_position.y + rectangle.y, rectangle.w, rectangle.h);
DRect other_aabb = DRect(aabb_object->getPos().x + aabb_object->rectangle.x, aabb_object->getPos().y + aabb_object->rectangle.y
, aabb_object->rectangle.w, aabb_object->rectangle.h);
if( !(other_aabb.x >= this_aabb.x + this_aabb.w || other_aabb.x + other_aabb.w <= this_aabb.x
|| other_aabb.y >= this_aabb.y + this_aabb.h || other_aabb.y + other_aabb.h <= this_aabb.y) ) // Donc il y a collision
{
collision_info.there_is_collision = true;
// Passons maitenant au repositionnement des objets pour qu'ils ne soient plus en collision
}
}
else if(object->isType(Object::Point) ) // On teste la collision avec un point
{
}
return collision_info;*/
}
}