1 | /*! |
---|
2 | * @file collision_event.h |
---|
3 | * Definition of a collision event |
---|
4 | * |
---|
5 | * A collision event represents a collision of two bouning boxes. Every CollisionEvent belongs to a Collision object that |
---|
6 | * represents the collision of two WorldEntities. |
---|
7 | * |
---|
8 | * There are different types of collisions: obb collisions and bsp collisions. Both collision types use different techniques |
---|
9 | * to represent collisions. This is why this class saves bounding boxes from the OBB as well as the planes from BSP. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifndef _COLLISION_EVENT_H |
---|
13 | #define _COLLISION_EVENT_H |
---|
14 | |
---|
15 | #include "vector.h" |
---|
16 | #include "cr_engine.h" |
---|
17 | |
---|
18 | #include "cr_defs.h" |
---|
19 | |
---|
20 | |
---|
21 | class WorldEntity; |
---|
22 | class BoundingVolume; |
---|
23 | class Plane; |
---|
24 | |
---|
25 | namespace CoRe |
---|
26 | { |
---|
27 | |
---|
28 | //! A class representing a simple collision |
---|
29 | class CollisionEvent |
---|
30 | { |
---|
31 | public: |
---|
32 | CollisionEvent(); |
---|
33 | virtual ~CollisionEvent(); |
---|
34 | |
---|
35 | /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ |
---|
36 | inline void collide(CREngine::CollisionType type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) |
---|
37 | { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } |
---|
38 | /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ |
---|
39 | inline void collide(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) |
---|
40 | { |
---|
41 | this->collisionType = type; |
---|
42 | this->entityA = entity; |
---|
43 | this->entityB = groundEntity; |
---|
44 | this->groundNormal = normal; |
---|
45 | this->position = position; |
---|
46 | this->bInWall = bInWall; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** @return CollisionEvent WorldEntity A */ |
---|
51 | inline WorldEntity* getEntityA() const |
---|
52 | { |
---|
53 | return this->entityA; |
---|
54 | } |
---|
55 | /** @return CollisionEvent WorldEntity B */ |
---|
56 | inline WorldEntity* getEntityB() const |
---|
57 | { |
---|
58 | return this->entityB; |
---|
59 | } |
---|
60 | /** @return Bounding Volume from EntityA */ |
---|
61 | inline BoundingVolume* getBVA() const |
---|
62 | { |
---|
63 | return this->bvA; |
---|
64 | } |
---|
65 | /** @return Bounding Volume from EntityB */ |
---|
66 | inline BoundingVolume* getBVB() const |
---|
67 | { |
---|
68 | return this->bvB; |
---|
69 | } |
---|
70 | |
---|
71 | /** @return ground plane if collided with bsp model */ |
---|
72 | inline Vector getGroundNormal() |
---|
73 | { |
---|
74 | return this->groundNormal; |
---|
75 | } |
---|
76 | |
---|
77 | /** @return position of the position, only accurate if this is a collision with the ground!!! */ |
---|
78 | inline Vector getCollisionPosition() |
---|
79 | { |
---|
80 | return this->position; |
---|
81 | } |
---|
82 | |
---|
83 | /** @return the type of the collision */ |
---|
84 | inline int getType() |
---|
85 | { |
---|
86 | return this->collisionType; |
---|
87 | } |
---|
88 | |
---|
89 | /** @return true if the entity is in the wall */ |
---|
90 | inline bool isInWall() |
---|
91 | { |
---|
92 | return this->bInWall; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | private: |
---|
97 | WorldEntity* entityA; //!< the collision body A |
---|
98 | WorldEntity* entityB; //!< the collision body B |
---|
99 | |
---|
100 | BoundingVolume* bvA; //!< reference to the bounding volume A |
---|
101 | BoundingVolume* bvB; //!< reference to the bounding volume B |
---|
102 | |
---|
103 | Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions |
---|
104 | Vector position; //!< position of the collision on the ground plane |
---|
105 | |
---|
106 | bool bInWall; //!< true if is in wall |
---|
107 | int collisionType; //!< collision type |
---|
108 | }; |
---|
109 | |
---|
110 | } |
---|
111 | #endif /* _COLLISION_EVENT_H */ |
---|