-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobject.cpp
More file actions
103 lines (80 loc) · 2.95 KB
/
Copy pathobject.cpp
File metadata and controls
103 lines (80 loc) · 2.95 KB
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
#include "object.h"
/****************************************************************************/
/** \file object.cpp
\brief The CObject class implementation */
/****************************************************************************/
/** draw object
*****************************************************************************/
void CObject::Draw(CCamera *camera)
{
// push modelview matrix on stack
glPushMatrix();
OnDraw(camera); // draw this object
if (HasChild()) // draw children
((CObject*)childNode)->Draw(camera);
glPopMatrix();
// draw siblings
if (HasParent() && !IsLastChild())
((CObject*)nextNode)->Draw(camera);
}
/****************************************************************************/
/** animate object
*****************************************************************************/
void CObject::Animate(scalar_t deltaTime)
{
OnAnimate(deltaTime); // animate this object
// animate children
if (HasChild())
((CObject*)childNode)->Animate(deltaTime);
// animate siblings
if (HasParent() && !IsLastChild())
((CObject*)nextNode)->Animate(deltaTime);
if (isDead)
delete this;
}
/****************************************************************************/
/** perform collision detection
*****************************************************************************/
void CObject::ProcessCollisions(CObject *obj)
{
// if this object's bounding sphere collides with obj's sphere
// and obj is not this object
if (((obj->position - position).Length() <= (obj->size + size)) &&
(obj != ((CObject*)this)))
{
OnCollision(obj); // perform this object's collision with obj
// test child collisions with obj
if (HasChild())
((CObject*)childNode)->ProcessCollisions(obj);
// test sibling collisions with obj
if (HasParent() && !IsLastChild())
((CObject*)nextNode)->ProcessCollisions(obj);
}
// if obj has children, check collisions with these children
if (obj->HasChild())
ProcessCollisions((CObject*)(obj->childNode));
// if obj has siblings, check collisions with these siblings
if (obj->HasParent() && !obj->IsLastChild())
ProcessCollisions((CObject*)(obj->nextNode));
}
/****************************************************************************/
/** prepare object
*****************************************************************************/
void CObject::Prepare()
{
OnPrepare(); // prepare this object
if (HasChild()) // prepare children
((CObject*)childNode)->Prepare();
if (HasParent() && !IsLastChild()) // prepare siblings
((CObject*)nextNode)->Prepare();
}
/****************************************************************************/
/** find root object of cyclic linked list tree
*****************************************************************************/
CObject * CObject::FindRoot()
{
// if this object has a parent node, return the root of the parent node
if (parentNode)
return ((CObject*)parentNode)->FindRoot();
return this;
}