42 |
|
|
43 |
namespace world |
namespace world |
44 |
{ |
{ |
45 |
/* |
|
46 |
* This class contains the information the physics engine |
/* |
47 |
* maintains about dynamic objects ("actors"). |
** ActorInfo |
48 |
*/ |
** |
49 |
|
** This class contains the information the physics engine maintains |
50 |
|
** about dynamic objects ("actors"). |
51 |
|
*/ |
52 |
class ActorInfo { |
class ActorInfo { |
53 |
public: |
public: |
54 |
ActorInfo(V2 p, V2 v) |
ActorInfo(V2 p, V2 v) |
55 |
: pos(p), vel(v), forceacc(), |
: pos(p), vel(v), forceacc(), |
56 |
charge(0), mass(1), radius(1), |
charge(0), mass(1), radius(1), |
57 |
grabbed(false), |
grabbed(false), |
58 |
last_pos(), oldpos(), oldvel(v), force() |
last_pos(), oldpos(), force() |
59 |
{} |
{} |
60 |
|
|
61 |
// |
// |
72 |
// |
// |
73 |
// Variables used internally by the physics engine |
// Variables used internally by the physics engine |
74 |
// |
// |
75 |
V2 last_pos; // Position befure current tick |
V2 last_pos; // Position before current tick |
76 |
V2 oldpos; // Backup position for adaptive stepsize control |
V2 oldpos; // Backup position for enter/leave notification |
|
V2 oldvel; // Backup velocity (see oldpos) |
|
77 |
V2 force; // Force used during tick |
V2 force; // Force used during tick |
78 |
}; |
}; |
79 |
|
|
80 |
/* |
/* |
81 |
* Impulse is used to transfer force from one Object to another Object |
** Impulse is used to transfer force from one Object to another Object |
82 |
* (currently only Stones can be the destination of Impulse's) |
** (currently only Stones can be the destination of Impulses). |
83 |
*/ |
*/ |
84 |
struct Impulse { |
struct Impulse { |
85 |
Object *sender; |
Object *sender; |
86 |
GridPos dest; |
GridPos dest; |
91 |
{} |
{} |
92 |
}; |
}; |
93 |
|
|
94 |
|
/* |
95 |
/* |
** Things that may happen when an actor hits a stone. |
96 |
* Things that may happen when an actor hits a stone. |
*/ |
|
*/ |
|
97 |
enum StoneResponse { |
enum StoneResponse { |
98 |
STONE_PASS, // let the actor pass |
STONE_PASS, // Actor passes stone |
99 |
STONE_REBOUND // rebound the actor |
STONE_REBOUND // Actor bounces off the stone |
100 |
}; |
}; |
101 |
|
|
102 |
/* |
/* |
103 |
* All the information that is necessary to handle collisions |
** StoneContact |
104 |
* between stones and actors. |
** |
105 |
*/ |
** All the information that is necessary to handle collisions between |
106 |
|
** stones and actors. |
107 |
|
*/ |
108 |
struct StoneContact |
struct StoneContact |
109 |
{ |
{ |
110 |
// Constructor. |
// Constructor. |
111 |
StoneContact(Actor *a, GridPos p, |
StoneContact (Actor *a, |
112 |
const V2 &cp, const V2 &n); |
GridPos stonepos, |
113 |
|
const V2 & contact_point, |
114 |
|
const V2 & surface_normal); |
115 |
StoneContact(); |
StoneContact(); |
116 |
|
|
117 |
// Variables. |
// Variables. |
119 |
GridPos stonepos; |
GridPos stonepos; |
120 |
StoneResponse response; |
StoneResponse response; |
121 |
|
|
122 |
V2 contact_point; // Where do the shapes meet? (world coords) |
V2 contact_point; // Where do the shapes meet? (world coordinates) |
123 |
V2 normal; // The surface normal at the contact point |
V2 normal; // The surface normal at the contact point |
124 |
bool is_collision; // Actor moves towards the stone, not away |
bool is_collision; // Actor moves towards the stone, not away |
125 |
bool fake_collision; |
bool fake_collision; |
188 |
void UnnameObject (Object *obj); |
void UnnameObject (Object *obj); |
189 |
void TransferObjectName(Object *source, Object *target); |
void TransferObjectName(Object *source, Object *target); |
190 |
Object *GetNamedObject (const string &name); |
Object *GetNamedObject (const string &name); |
191 |
|
Object *GetObject (const GridLoc &l); |
192 |
|
|
193 |
bool world::IsLevelBorder(GridPos p); |
bool world::IsLevelBorder(GridPos p); |
194 |
|
|
258 |
/* Find all actors at most RANGE units away from CENTER. Returns |
/* Find all actors at most RANGE units away from CENTER. Returns |
259 |
false if none were found. */ |
false if none were found. */ |
260 |
bool GetActorsInRange (px::V2 center, double range, |
bool GetActorsInRange (px::V2 center, double range, |
261 |
std::vector<Actor*>& actors); |
std::vector<Actor*> &actors); |
262 |
|
|
263 |
//---------------------------------------- |
//---------------------------------------- |
264 |
// Stones |
// Stones |