1 | |
---|
2 | |
---|
3 | /* |
---|
4 | orxonox - the future of 3D-vertical-scrollers |
---|
5 | |
---|
6 | Copyright (C) 2004 orx |
---|
7 | |
---|
8 | This program is free software; you can redistribute it and/or modify |
---|
9 | it under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2, or (at your option) |
---|
11 | any later version. |
---|
12 | |
---|
13 | ### File Specific: |
---|
14 | main-programmer: Patrick Boenzli |
---|
15 | co-programmer: ... |
---|
16 | */ |
---|
17 | |
---|
18 | |
---|
19 | #include "p_node.h" |
---|
20 | |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | |
---|
25 | /** |
---|
26 | \brief standard constructor |
---|
27 | |
---|
28 | \todo this constructor is not jet implemented - do it |
---|
29 | */ |
---|
30 | PNode::PNode () |
---|
31 | { |
---|
32 | this->children = new tList<PNode>(); |
---|
33 | this->bCoorChanged = true; |
---|
34 | this->bDirChanged = true; |
---|
35 | } |
---|
36 | |
---|
37 | |
---|
38 | /** |
---|
39 | \brief standard deconstructor |
---|
40 | |
---|
41 | \todo this deconstructor is not jet implemented - do it |
---|
42 | */ |
---|
43 | PNode::~PNode () |
---|
44 | { |
---|
45 | this->children->destroy(); |
---|
46 | delete this->children; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | \brief get relative coordinates |
---|
52 | \returns relative coordinates to its parent |
---|
53 | */ |
---|
54 | Vector PNode::getRelCoor () |
---|
55 | { |
---|
56 | Vector r = this->relCoordinate; /* return a copy, so it can't be modified */ |
---|
57 | return r; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /** |
---|
62 | \brief set relative coordinates |
---|
63 | \param relative coordinates to its parent |
---|
64 | |
---|
65 | it is very importand, that you use this function, if you want to update the |
---|
66 | relCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
67 | has changed and won't update the children Nodes. |
---|
68 | */ |
---|
69 | void PNode::setRelCoor (Vector relCoord) |
---|
70 | {} |
---|
71 | |
---|
72 | |
---|
73 | /** |
---|
74 | \brief get absolute coordinates |
---|
75 | \returns absolute coordinates from (0,0,0) |
---|
76 | */ |
---|
77 | Vector PNode::getAbsCoor () |
---|
78 | {} |
---|
79 | |
---|
80 | |
---|
81 | /** |
---|
82 | \brief get relative coordinates |
---|
83 | \returns relative coordinates to its parent |
---|
84 | |
---|
85 | it is very importand, that you use this function, if you want to update the |
---|
86 | absCoordinates. If you don't use this, the PNode won't recognize, that something |
---|
87 | has changed and won't update the children Nodes. |
---|
88 | */ |
---|
89 | void PNode::setAbsCoor (Vector absCoord) |
---|
90 | {} |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | \brief shift coordinate (abs and rel) |
---|
95 | \param shift vector |
---|
96 | |
---|
97 | this function shifts the current coordinates about the vector shift. this is |
---|
98 | usefull because from some place else you can: |
---|
99 | PNode* someNode = ...; |
---|
100 | Vector objectMovement = calculateShift(); |
---|
101 | someNode->shiftCoor(objectMovement); |
---|
102 | |
---|
103 | elsewhere you would have to: |
---|
104 | PNode* someNode = ...; |
---|
105 | Vector objectMovement = calculateShift(); |
---|
106 | Vector currentCoor = someNode->getRelCoor(); |
---|
107 | Vector newCoor = currentCoor + objectMovement; |
---|
108 | someNode->setRelCoor(newCoor); |
---|
109 | |
---|
110 | yea right... shorter... |
---|
111 | |
---|
112 | */ |
---|
113 | void PNode::shiftCoor (Vector shift) |
---|
114 | {} |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | /** |
---|
119 | \brief get relative direction |
---|
120 | \returns relative direction to its parent |
---|
121 | */ |
---|
122 | Quaternion PNode::getRelDir () |
---|
123 | {} |
---|
124 | |
---|
125 | |
---|
126 | /** |
---|
127 | \brief set relative direction |
---|
128 | \param relative direction to its parent |
---|
129 | |
---|
130 | it is very importand, that you use this function, if you want to update the |
---|
131 | relDirection. If you don't use this, the PNode won't recognize, that something |
---|
132 | has changed and won't update the children Nodes. |
---|
133 | */ |
---|
134 | void PNode::setRelDir (Quaternion relDir) |
---|
135 | {} |
---|
136 | |
---|
137 | |
---|
138 | /** |
---|
139 | \brief gets the absolute direction (0,0,1) |
---|
140 | \returns absolute coordinates |
---|
141 | */ |
---|
142 | Quaternion PNode::getAbsDir () |
---|
143 | {} |
---|
144 | |
---|
145 | |
---|
146 | /** |
---|
147 | \brief sets the absolute direction (0,0,1) |
---|
148 | \param absolute coordinates |
---|
149 | |
---|
150 | it is very importand, that you use this function, if you want to update the |
---|
151 | absDirection. If you don't use this, the PNode won't recognize, that something |
---|
152 | has changed and won't update the children Nodes. |
---|
153 | */ |
---|
154 | void PNode::setAbsDir (Quaternion absDir) |
---|
155 | {} |
---|
156 | |
---|
157 | |
---|
158 | /** |
---|
159 | \brief shift coordinate (abs and rel) |
---|
160 | \param shift vector |
---|
161 | |
---|
162 | this function shifts the current coordinates about the vector shift. this is |
---|
163 | usefull because from some place else you can: |
---|
164 | PNode* someNode = ...; |
---|
165 | Quaternion objectMovement = calculateShift(); |
---|
166 | someNode->shiftCoor(objectMovement); |
---|
167 | |
---|
168 | elsewhere you would have to: |
---|
169 | PNode* someNode = ...; |
---|
170 | Quaternion objectMovement = calculateShift(); |
---|
171 | Quaternion currentCoor = someNode->getRelCoor(); |
---|
172 | Quaternion newCoor = currentCoor + objectMovement; |
---|
173 | someNode->setRelCoor(newCoor); |
---|
174 | |
---|
175 | yea right... shorter... |
---|
176 | |
---|
177 | */ |
---|
178 | void PNode::shiftDir (Quaternion shift) |
---|
179 | {} |
---|
180 | |
---|
181 | |
---|
182 | |
---|
183 | /** |
---|
184 | \brief adds a child and makes this node to a parent |
---|
185 | \param child reference |
---|
186 | |
---|
187 | use this to add a child to this node. |
---|
188 | */ |
---|
189 | void PNode::addChild (PNode* pNode) |
---|
190 | { |
---|
191 | this->addChild(pNode, DEFAULT_MODE); |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | /** |
---|
196 | \brief adds a child and makes this node to a parent |
---|
197 | \param child reference |
---|
198 | \param on which changes the child should also change ist state |
---|
199 | |
---|
200 | use this to add a child to this node. |
---|
201 | */ |
---|
202 | void PNode::addChild (PNode* pNode, parentingMode mode) |
---|
203 | { |
---|
204 | pNode->mode = mode; |
---|
205 | this->children->add (pNode); |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | /** |
---|
210 | /brief removes a child from the node |
---|
211 | */ |
---|
212 | void PNode::removeChild (PNode* pNode) |
---|
213 | { |
---|
214 | this->children->remove (pNode); |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | /** |
---|
219 | \brief sets the parent of this PNode |
---|
220 | */ |
---|
221 | void PNode::setParent (PNode* parent) |
---|
222 | { |
---|
223 | this->parent = parent; |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | /** |
---|
228 | \brief updates the absCoordinate/absDirection |
---|
229 | |
---|
230 | this is used to go through the parent-tree to update all the absolute coordinates |
---|
231 | and directions. this update should be done by the engine, so you don't have to |
---|
232 | worry, normaly... |
---|
233 | */ |
---|
234 | void PNode::update(long timeStamp) |
---|
235 | { |
---|
236 | if(this->parent == NULL) |
---|
237 | printf("PNode::upate(long timeStamp) - parent is NULL..."); |
---|
238 | if( this->bCoorChanged && this->timeStamp != DataTank::timeStamp) |
---|
239 | { |
---|
240 | /* update the current absCoordinate */ |
---|
241 | this->absCoordinate = parent->getAbsCoor () + this->relCoordinate; |
---|
242 | } |
---|
243 | if( this->bDirChanged && this->timeStamp != DataTank::timeStamp) |
---|
244 | { |
---|
245 | /* update the current absDirection - remember * means rotation around sth.*/ |
---|
246 | this->absDirection = parent->getAbsDir () * this->relDirection; |
---|
247 | } |
---|
248 | |
---|
249 | PNode* pn = this->children->enumerate(); |
---|
250 | while( pn != NULL) |
---|
251 | { |
---|
252 | pn->update(timeStamp); |
---|
253 | pn = this->children->nextElement(); |
---|
254 | } |
---|
255 | |
---|
256 | this->timeStamp = timeStamp; |
---|
257 | this->bCoorChanged = false; |
---|
258 | this->bDirChanged = false; |
---|
259 | |
---|
260 | } |
---|
261 | |
---|