The Game Engine
1
Main Page
Related Pages
Classes
Files
File List
File Members
WorldObject.cpp
Go to the documentation of this file.
1
#include "
WorldObject.h
"
2
#include "
fns.h
"
3
#include <limits>
4
5
WorldObject::WorldObject
(std::string name,
Point2D
pos,
int
z ):
6
mName(name),
7
mPos(pos),
8
mAcceleration(),
9
mVelocity(),
10
mMaxVelocity(),
11
mMaxSpeed(0),
12
ZOrder(z),
13
mVisible(true),
14
mTransparency(1),
15
mAngle(0),
16
mScale(1),
17
mLastUpdate(0),
18
mLastDraw(0),
19
mUnused(true),
20
mBehavior(NULL)
21
{
22
setVelocity
(0,0);
23
}
24
25
void
WorldObject::drawCollisions
() {}
26
27
void
WorldObject::update
(){
28
if
(
mUnused
)
return
;
29
//is speed != 0
30
if
(
getMaxSpeedSquared
()){
31
//do acceleration
32
mVelocity
+=
mAcceleration
;
33
if
(abs(
mMaxSpeed
) >= numeric_limits<double>::epsilon()){
//to handle when the max velocity is 0 but max speed is > 0 to minimize ops per loop
34
setMaxVelocity
(
mMaxSpeed
,
mVelocity
);
35
mMaxSpeed
=0;
36
}
37
mVelocity
= min(
mMaxVelocity
,
mVelocity
);
38
//do velocity
39
mPos
+=
mVelocity
;
40
}
41
}
42
43
void
WorldObject::runBehavior
(){
44
if
(
mBehavior
)
45
mBehavior
();
46
}
47
48
void
WorldObject::drawCollisions
(vector<CollisionObject*> &vec,
const
Point2D
& pos) {
49
for
(
unsigned
int
i=0; i < vec.size(); i++) {
50
vec[i]->draw(pos);
51
}
52
}
53
54
double
WorldObject::getMaxSpeed
() {
55
return
abs(
mMaxSpeed
) < numeric_limits<double>::epsilon() ?
mMaxSpeed
:
mMaxVelocity
.
length
();
56
}
57
58
double
WorldObject::getMaxSpeedSquared
() {
60
return
abs(
mMaxSpeed
) < numeric_limits<double>::epsilon() ?
mMaxVelocity
.
lengthSquared
() :
mMaxSpeed
*
mMaxSpeed
;
61
}
62
63
void
WorldObject::moveTowards
(
Point2D
direction){
66
68
}
69
WorldObject.cpp
Generated on Tue Apr 16 2013 02:32:41 for The Game Engine by
1.8.3.1