1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * Benjamin Knecht |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "SpaceShip.h" |
---|
31 | |
---|
32 | #include <OgreCamera.h> |
---|
33 | #include <OgreRenderWindow.h> |
---|
34 | #include <OgreParticleSystem.h> |
---|
35 | #include <OgreSceneNode.h> |
---|
36 | |
---|
37 | #include "CameraHandler.h" |
---|
38 | #include "util/Convert.h" |
---|
39 | #include "util/Math.h" |
---|
40 | #include "util/Debug.h" |
---|
41 | #include "core/CoreIncludes.h" |
---|
42 | #include "core/ConfigValueIncludes.h" |
---|
43 | #include "core/Iterator.h" |
---|
44 | #include "core/input/InputManager.h" |
---|
45 | #include "core/XMLPort.h" |
---|
46 | #include "core/ConsoleCommand.h" |
---|
47 | #include "tools/ParticleInterface.h" |
---|
48 | #include "network/Client.h" |
---|
49 | #include "hud/HUD.h" |
---|
50 | #include "RotatingProjectile.h" |
---|
51 | #include "ParticleProjectile.h" |
---|
52 | #include "GraphicsEngine.h" |
---|
53 | |
---|
54 | namespace orxonox |
---|
55 | { |
---|
56 | SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).accessLevel(AccessLevel::Debug); |
---|
57 | SetConsoleCommand(SpaceShip, whereAmI, true).accessLevel(AccessLevel::User); |
---|
58 | SetConsoleCommand(SpaceShip, moveLongitudinal, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold); |
---|
59 | SetConsoleCommand(SpaceShip, moveLateral, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold); |
---|
60 | SetConsoleCommand(SpaceShip, moveYaw, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold); |
---|
61 | SetConsoleCommand(SpaceShip, movePitch, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold); |
---|
62 | SetConsoleCommand(SpaceShip, moveRoll, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold); |
---|
63 | SetConsoleCommand(SpaceShip, fire, true).accessLevel(AccessLevel::User).keybindMode(KeybindMode::OnHold); |
---|
64 | SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxSpeed", 1, false).accessLevel(AccessLevel::Debug); |
---|
65 | SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxBlubber", 2, false).accessLevel(AccessLevel::Debug); |
---|
66 | SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setRofl", 3, false).accessLevel(AccessLevel::Debug); |
---|
67 | |
---|
68 | CreateFactory(SpaceShip); |
---|
69 | |
---|
70 | SpaceShip* SpaceShip::instance_s; |
---|
71 | |
---|
72 | |
---|
73 | SpaceShip *SpaceShip::getLocalShip(){ |
---|
74 | ObjectList<SpaceShip>::iterator it; |
---|
75 | for(it = ObjectList<SpaceShip>::begin(); it; ++it){ |
---|
76 | if( (it)->myShip_ ) |
---|
77 | return *it; |
---|
78 | } |
---|
79 | return NULL; |
---|
80 | } |
---|
81 | |
---|
82 | SpaceShip::SpaceShip() |
---|
83 | { |
---|
84 | RegisterObject(SpaceShip); |
---|
85 | |
---|
86 | this->setRotationAxis(1, 0, 0); |
---|
87 | this->setStatic(false); |
---|
88 | |
---|
89 | this->zeroRadian_ = 0; |
---|
90 | this->maxSideAndBackSpeed_ = 0; |
---|
91 | this->maxSpeed_ = 0; |
---|
92 | this->maxRotation_ = 0; |
---|
93 | this->translationAcceleration_ = 0; |
---|
94 | this->rotationAcceleration_ = 0; |
---|
95 | this->translationDamping_ = 0; |
---|
96 | this->rotationDamping_ = 0; |
---|
97 | this->maxRotationRadian_ = 0; |
---|
98 | this->rotationAccelerationRadian_ = 0; |
---|
99 | this->rotationDampingRadian_ = 0; |
---|
100 | |
---|
101 | this->cam_ = 0; |
---|
102 | this->tt1_ = 0; |
---|
103 | this->tt2_ = 0; |
---|
104 | |
---|
105 | this->redNode_ = 0; |
---|
106 | this->greenNode_ = 0; |
---|
107 | this->blinkTime_ = 0; |
---|
108 | |
---|
109 | this->timeToReload_ = 0; |
---|
110 | |
---|
111 | this->setMouseEventCallback_ = false; |
---|
112 | this->bLMousePressed_ = false; |
---|
113 | this->bRMousePressed_ = false; |
---|
114 | this->mouseXRotation_ = 0; |
---|
115 | this->mouseYRotation_ = 0; |
---|
116 | this->mouseX_ = 0; |
---|
117 | this->mouseY_ = 0; |
---|
118 | this->myShip_ = false; |
---|
119 | |
---|
120 | this->registerAllVariables(); |
---|
121 | |
---|
122 | SpaceShip::instance_s = this; |
---|
123 | |
---|
124 | this->setConfigValues(); |
---|
125 | |
---|
126 | this->initialDir_ = Vector3(1.0, 0.0, 0.0); |
---|
127 | this->currentDir_ = initialDir_; |
---|
128 | this->initialOrth_ = Vector3(0.0, 0.0, 1.0); |
---|
129 | this->currentOrth_ = initialOrth_; |
---|
130 | |
---|
131 | this->camName_ = this->getName() + "CamNode"; |
---|
132 | |
---|
133 | this->teamNr_ = 0; |
---|
134 | this->health_ = 100; |
---|
135 | |
---|
136 | COUT(3) << "Info: SpaceShip was loaded" << std::endl; |
---|
137 | } |
---|
138 | |
---|
139 | SpaceShip::~SpaceShip() |
---|
140 | { |
---|
141 | if (this->isInitialized()) |
---|
142 | { |
---|
143 | if (this->tt1_) |
---|
144 | delete this->tt1_; |
---|
145 | if (this->tt2_) |
---|
146 | delete this->tt2_; |
---|
147 | |
---|
148 | if (setMouseEventCallback_) |
---|
149 | InputManager::removeMouseHandler("SpaceShip"); |
---|
150 | |
---|
151 | if (this->cam_) |
---|
152 | delete this->cam_; |
---|
153 | |
---|
154 | if (!this->myShip_) |
---|
155 | HUD::getSingleton().removeRadarObject(this); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | bool SpaceShip::create(){ |
---|
160 | if(!myShip_){ |
---|
161 | if(network::Client::getSingleton() && objectID == network::Client::getSingleton()->getShipID()) |
---|
162 | myShip_=true; |
---|
163 | else |
---|
164 | HUD::getSingleton().addRadarObject(this, this->getProjectileColour()); |
---|
165 | } |
---|
166 | if(Model::create()) |
---|
167 | this->init(); |
---|
168 | else |
---|
169 | return false; |
---|
170 | return true; |
---|
171 | } |
---|
172 | |
---|
173 | void SpaceShip::registerAllVariables(){ |
---|
174 | registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 ); |
---|
175 | registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1); |
---|
176 | registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1); |
---|
177 | registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1); |
---|
178 | registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1); |
---|
179 | registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1); |
---|
180 | registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1); |
---|
181 | registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1); |
---|
182 | registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1); |
---|
183 | registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1); |
---|
184 | |
---|
185 | } |
---|
186 | |
---|
187 | void SpaceShip::init() |
---|
188 | { |
---|
189 | // START CREATING THRUSTER |
---|
190 | this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low); |
---|
191 | this->tt1_->createNewEmitter(); |
---|
192 | this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir()); |
---|
193 | this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1)); |
---|
194 | this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1)); |
---|
195 | this->tt1_->setSpeedFactor(3.0); |
---|
196 | |
---|
197 | Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a"); |
---|
198 | node2a->setInheritScale(false); |
---|
199 | node2a->setScale(1, 1, 1); |
---|
200 | tt1_->addToSceneNode(node2a); |
---|
201 | |
---|
202 | this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal); |
---|
203 | this->tt2_->createNewEmitter(); |
---|
204 | this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0)); |
---|
205 | this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2)); |
---|
206 | this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2)); |
---|
207 | |
---|
208 | Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b"); |
---|
209 | node2b->setInheritScale(false); |
---|
210 | node2b->setScale(0.5, 0.5, 0.5); |
---|
211 | tt2_->addToSceneNode(node2b); |
---|
212 | // END CREATING THRUSTER |
---|
213 | |
---|
214 | // START CREATING BLINKING LIGHTS |
---|
215 | this->redBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1); |
---|
216 | this->greenBillboard_.setBillboardSet("Examples/Flare", ColourValue(0.0, 1.0, 0.0), 1); |
---|
217 | |
---|
218 | this->redNode_ = this->getNode()->createChildSceneNode(this->getName() + "red", Vector3(0.3, 4.0, -0.3)); |
---|
219 | this->redNode_->setInheritScale(false); |
---|
220 | this->greenNode_ = this->getNode()->createChildSceneNode(this->getName() + "green", Vector3(0.3, -4.0, -0.3)); |
---|
221 | this->greenNode_->setInheritScale(false); |
---|
222 | |
---|
223 | this->redNode_->attachObject(this->redBillboard_.getBillboardSet()); |
---|
224 | this->redNode_->setScale(0.3, 0.3, 0.3); |
---|
225 | |
---|
226 | this->greenNode_->attachObject(this->greenBillboard_.getBillboardSet()); |
---|
227 | this->greenNode_->setScale(0.3, 0.3, 0.3); |
---|
228 | // END CREATING BLINKING LIGHTS |
---|
229 | |
---|
230 | if (this->isExactlyA(Class(SpaceShip))) |
---|
231 | { |
---|
232 | // START of testing crosshair |
---|
233 | this->crosshairNear_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
234 | this->crosshairFar_.setBillboardSet("Orxonox/Crosshair", ColourValue(1.0, 1.0, 0.0), 1); |
---|
235 | |
---|
236 | this->chNearNode_ = this->getNode()->createChildSceneNode(this->getName() + "near", Vector3(50.0, 0.0, 0.0)); |
---|
237 | this->chNearNode_->setInheritScale(false); |
---|
238 | this->chFarNode_ = this->getNode()->createChildSceneNode(this->getName() + "far", Vector3(200.0, 0.0, 0.0)); |
---|
239 | this->chFarNode_->setInheritScale(false); |
---|
240 | |
---|
241 | this->chNearNode_->attachObject(this->crosshairNear_.getBillboardSet()); |
---|
242 | this->chNearNode_->setScale(0.2, 0.2, 0.2); |
---|
243 | |
---|
244 | this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet()); |
---|
245 | this->chFarNode_->setScale(0.4, 0.4, 0.4); |
---|
246 | } |
---|
247 | |
---|
248 | createCamera(); |
---|
249 | // END of testing crosshair |
---|
250 | } |
---|
251 | |
---|
252 | void SpaceShip::setConfigValues() |
---|
253 | { |
---|
254 | SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = ship down)."); |
---|
255 | SetConfigValue(reloadTime_, 0.125).description("The reload time of the weapon in seconds"); |
---|
256 | SetConfigValue(testvector_, Vector3()).description("asdfblah"); |
---|
257 | } |
---|
258 | |
---|
259 | void SpaceShip::changedVisibility() |
---|
260 | { |
---|
261 | // Model::changedVisibility(); |
---|
262 | SUPER(SpaceShip, changedVisibility); |
---|
263 | |
---|
264 | this->tt1_->setEnabled(this->isVisible()); |
---|
265 | this->tt2_->setEnabled(this->isVisible()); |
---|
266 | this->redBillboard_.setVisible(this->isVisible()); |
---|
267 | this->greenBillboard_.setVisible(this->isVisible()); |
---|
268 | this->crosshairNear_.setVisible(this->isVisible()); |
---|
269 | this->crosshairFar_.setVisible(this->isVisible()); |
---|
270 | } |
---|
271 | |
---|
272 | void SpaceShip::changedActivity() |
---|
273 | { |
---|
274 | // Model::changedActivity(); |
---|
275 | SUPER(SpaceShip, changedActivity); |
---|
276 | |
---|
277 | this->tt1_->setEnabled(this->isVisible()); |
---|
278 | this->tt2_->setEnabled(this->isVisible()); |
---|
279 | this->redBillboard_.setVisible(this->isVisible()); |
---|
280 | this->greenBillboard_.setVisible(this->isVisible()); |
---|
281 | this->crosshairNear_.setVisible(this->isVisible()); |
---|
282 | this->crosshairFar_.setVisible(this->isVisible()); |
---|
283 | } |
---|
284 | |
---|
285 | void SpaceShip::setCamera(const std::string& camera) |
---|
286 | { |
---|
287 | myShip_=true; // TODO: this is only a hack |
---|
288 | camName_=camera; |
---|
289 | // change camera attributes here, if you want to ;) |
---|
290 | } |
---|
291 | |
---|
292 | void SpaceShip::getFocus(){ |
---|
293 | COUT(4) << "requesting focus" << std::endl; |
---|
294 | if(network::Client::getSingleton()==0 || network::Client::getSingleton()->getShipID()==objectID) |
---|
295 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
296 | |
---|
297 | } |
---|
298 | |
---|
299 | Camera* SpaceShip::getCamera(){ |
---|
300 | return cam_; |
---|
301 | } |
---|
302 | |
---|
303 | void SpaceShip::createCamera(){ |
---|
304 | // COUT(4) << "begin camera creation" << std::endl; |
---|
305 | this->camNode_ = this->getNode()->createChildSceneNode(camName_); |
---|
306 | COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl; |
---|
307 | this->camNode_->setPosition(Vector3(-25,0,5)); |
---|
308 | // Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); |
---|
309 | // Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1)); |
---|
310 | // camNode_->setOrientation(q1*q2); |
---|
311 | COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl; |
---|
312 | cam_ = new Camera(this->camNode_); |
---|
313 | |
---|
314 | cam_->setTargetNode(this->getNode()); |
---|
315 | // cam->setPosition(Vector3(0,-350,0)); |
---|
316 | Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0)); |
---|
317 | Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0)); |
---|
318 | this->camNode_->setOrientation(q2*q1); |
---|
319 | if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){ |
---|
320 | this->setBacksync(true); |
---|
321 | CameraHandler::getInstance()->requestFocus(cam_); |
---|
322 | } |
---|
323 | |
---|
324 | } |
---|
325 | |
---|
326 | void SpaceShip::setMaxSpeed(float value) |
---|
327 | { this->maxSpeed_ = value; } |
---|
328 | void SpaceShip::setMaxSideAndBackSpeed(float value) |
---|
329 | { this->maxSideAndBackSpeed_ = value; } |
---|
330 | void SpaceShip::setMaxRotation(float value) |
---|
331 | { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); } |
---|
332 | void SpaceShip::setTransAcc(float value) |
---|
333 | { this->translationAcceleration_ = value; } |
---|
334 | void SpaceShip::setRotAcc(float value) |
---|
335 | { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); } |
---|
336 | void SpaceShip::setTransDamp(float value) |
---|
337 | { this->translationDamping_ = value; } |
---|
338 | void SpaceShip::setRotDamp(float value) |
---|
339 | { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); } |
---|
340 | |
---|
341 | /** |
---|
342 | @brief XML loading and saving. |
---|
343 | @param xmlelement The XML-element |
---|
344 | @param loading Loading (true) or saving (false) |
---|
345 | @return The XML-element |
---|
346 | */ |
---|
347 | void SpaceShip::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
348 | { |
---|
349 | // Model::XMLPort(xmlelement, mode); |
---|
350 | SUPER(SpaceShip, XMLPort, xmlelement, mode); |
---|
351 | |
---|
352 | XMLPortParam(SpaceShip, "camera", setCamera, getCamera, xmlelement, mode); |
---|
353 | XMLPortParam(SpaceShip, "maxSpeed", setMaxSpeed, getMaxSpeed, xmlelement, mode); |
---|
354 | XMLPortParam(SpaceShip, "maxSideAndBackSpeed", setMaxSideAndBackSpeed, getMaxSideAndBackSpeed, xmlelement, mode); |
---|
355 | XMLPortParam(SpaceShip, "maxRotation", setMaxRotation, getMaxRotation, xmlelement, mode); |
---|
356 | XMLPortParam(SpaceShip, "transAcc", setTransAcc, getTransAcc, xmlelement, mode); |
---|
357 | XMLPortParam(SpaceShip, "rotAcc", setRotAcc, getRotAcc, xmlelement, mode); |
---|
358 | XMLPortParam(SpaceShip, "transDamp", setTransDamp, getTransDamp, xmlelement, mode); |
---|
359 | XMLPortParam(SpaceShip, "rotDamp", setRotDamp, getRotDamp, xmlelement, mode); |
---|
360 | |
---|
361 | SpaceShip::create(); |
---|
362 | if (this->isExactlyA(Class(SpaceShip))) |
---|
363 | getFocus(); |
---|
364 | } |
---|
365 | |
---|
366 | int sgn(float x) |
---|
367 | { |
---|
368 | if (x >= 0) |
---|
369 | return 1; |
---|
370 | else |
---|
371 | return -1; |
---|
372 | } |
---|
373 | |
---|
374 | std::string SpaceShip::whereAmI() { |
---|
375 | return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) |
---|
376 | + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) |
---|
377 | + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); |
---|
378 | } |
---|
379 | |
---|
380 | void SpaceShip::tick(float dt) |
---|
381 | { |
---|
382 | if (!this->isActive()) |
---|
383 | return; |
---|
384 | |
---|
385 | currentDir_ = getOrientation()*initialDir_; |
---|
386 | currentOrth_ = getOrientation()*initialOrth_; |
---|
387 | |
---|
388 | if (this->cam_) |
---|
389 | this->cam_->tick(dt); |
---|
390 | |
---|
391 | if (this->redNode_ && this->greenNode_) |
---|
392 | { |
---|
393 | this->blinkTime_ += dt; |
---|
394 | float redScale = 0.15 + 0.15 * sin(this->blinkTime_ * 10.0); |
---|
395 | float greenScale = 0.15 - 0.15 * sin(this->blinkTime_ * 10.0); |
---|
396 | this->redNode_->setScale(redScale, redScale, redScale); |
---|
397 | this->greenNode_->setScale(greenScale, greenScale, greenScale); |
---|
398 | } |
---|
399 | |
---|
400 | if (this->timeToReload_ > 0) |
---|
401 | this->timeToReload_ -= dt; |
---|
402 | else |
---|
403 | this->timeToReload_ = 0; |
---|
404 | |
---|
405 | if (this->bLMousePressed_ && this->timeToReload_ <= 0) |
---|
406 | { |
---|
407 | |
---|
408 | BillboardProjectile* projectile = new ParticleProjectile(this); |
---|
409 | projectile->setColour(this->getProjectileColour()); |
---|
410 | projectile->create(); |
---|
411 | if (projectile->classID == 0) |
---|
412 | { |
---|
413 | COUT(3) << "generated projectile with classid 0" << std::endl; // TODO: remove this output |
---|
414 | } |
---|
415 | |
---|
416 | projectile->setBacksync(true); |
---|
417 | this->timeToReload_ = this->reloadTime_; |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | // ##################################### |
---|
422 | // ############# STEERING ############## |
---|
423 | // ##################################### |
---|
424 | |
---|
425 | if (this->velocity_.x > this->maxSpeed_) |
---|
426 | this->velocity_.x = this->maxSpeed_; |
---|
427 | if (this->velocity_.x < -this->maxSideAndBackSpeed_) |
---|
428 | this->velocity_.x = -this->maxSideAndBackSpeed_; |
---|
429 | if (this->velocity_.y > this->maxSideAndBackSpeed_) |
---|
430 | this->velocity_.y = this->maxSideAndBackSpeed_; |
---|
431 | if (this->velocity_.y < -this->maxSideAndBackSpeed_) |
---|
432 | this->velocity_.y = -this->maxSideAndBackSpeed_; |
---|
433 | if (this->rotationRate_ > this->maxRotationRadian_) |
---|
434 | this->rotationRate_ = this->maxRotationRadian_; |
---|
435 | if (this->rotationRate_ < -this->maxRotationRadian_) |
---|
436 | this->rotationRate_ = -this->maxRotationRadian_; |
---|
437 | |
---|
438 | if (this->acceleration_.x == 0) |
---|
439 | { |
---|
440 | if (this->velocity_.x > 0) |
---|
441 | { |
---|
442 | this->velocity_.x -= (this->translationDamping_ * dt); |
---|
443 | if (this->velocity_.x < 0) |
---|
444 | this->velocity_.x = 0; |
---|
445 | } |
---|
446 | else if (this->velocity_.x < 0) |
---|
447 | { |
---|
448 | this->velocity_.x += (this->translationDamping_ * dt); |
---|
449 | if (this->velocity_.x > 0) |
---|
450 | this->velocity_.x = 0; |
---|
451 | } |
---|
452 | } |
---|
453 | |
---|
454 | if (this->acceleration_.y == 0) |
---|
455 | { |
---|
456 | if (this->velocity_.y > 0) |
---|
457 | { |
---|
458 | this->velocity_.y -= (this->translationDamping_ * dt); |
---|
459 | if (this->velocity_.y < 0) |
---|
460 | this->velocity_.y = 0; |
---|
461 | } |
---|
462 | else if (this->velocity_.y < 0) |
---|
463 | { |
---|
464 | this->velocity_.y += (this->translationDamping_ * dt); |
---|
465 | if (this->velocity_.y > 0) |
---|
466 | this->velocity_.y = 0; |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | if (this->momentum_ == this->zeroRadian_) |
---|
471 | { |
---|
472 | if (this->rotationRate_ > this->zeroRadian_) |
---|
473 | { |
---|
474 | this->rotationRate_ -= (this->rotationDampingRadian_ * dt); |
---|
475 | if (this->rotationRate_ < this->zeroRadian_) |
---|
476 | this->rotationRate_ = 0; |
---|
477 | } |
---|
478 | else if (this->rotationRate_ < this->zeroRadian_) |
---|
479 | { |
---|
480 | this->rotationRate_ += (this->rotationDampingRadian_ * dt); |
---|
481 | if (this->rotationRate_ > this->zeroRadian_) |
---|
482 | this->rotationRate_ = 0; |
---|
483 | } |
---|
484 | } |
---|
485 | |
---|
486 | |
---|
487 | // WorldEntity::tick(dt); |
---|
488 | SUPER(SpaceShip, tick, dt); |
---|
489 | |
---|
490 | this->roll(this->mouseXRotation_ * dt); |
---|
491 | if (this->bInvertYAxis_) |
---|
492 | this->yaw(Radian(-this->mouseYRotation_ * dt)); |
---|
493 | else |
---|
494 | this->yaw(Radian(this->mouseYRotation_ * dt)); |
---|
495 | |
---|
496 | if (this->acceleration_.x > 0) |
---|
497 | { |
---|
498 | this->tt1_->setEnabled(true); |
---|
499 | this->tt2_->setEnabled(true); |
---|
500 | } |
---|
501 | else |
---|
502 | { |
---|
503 | this->tt1_->setEnabled(false); |
---|
504 | this->tt2_->setEnabled(false); |
---|
505 | } |
---|
506 | |
---|
507 | if( myShip_ ) |
---|
508 | { |
---|
509 | COUT(5) << "steering our ship: " << objectID << std::endl; |
---|
510 | this->acceleration_.x = 0; |
---|
511 | this->acceleration_.y = 0; |
---|
512 | this->momentum_ = 0; |
---|
513 | this->mouseXRotation_ = Radian(0); |
---|
514 | this->mouseYRotation_ = Radian(0); |
---|
515 | }/*else |
---|
516 | COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/ |
---|
517 | |
---|
518 | this->bLMousePressed_ = false; |
---|
519 | } |
---|
520 | |
---|
521 | void SpaceShip::movePitch(float val) |
---|
522 | { getLocalShip()->setMovePitch(val); } |
---|
523 | void SpaceShip::moveYaw(float val) |
---|
524 | { getLocalShip()->setMoveYaw(val); } |
---|
525 | void SpaceShip::moveRoll(float val) |
---|
526 | { getLocalShip()->setMoveRoll(val); } |
---|
527 | void SpaceShip::moveLongitudinal(float val) |
---|
528 | { getLocalShip()->setMoveLongitudinal(val); } |
---|
529 | void SpaceShip::moveLateral(float val) |
---|
530 | { getLocalShip()->setMoveLateral(val); } |
---|
531 | void SpaceShip::fire() |
---|
532 | { getLocalShip()->doFire(); } |
---|
533 | |
---|
534 | void SpaceShip::setMovePitch(float val) |
---|
535 | { |
---|
536 | val = -val * val * sgn(val) * this->rotationAcceleration_; |
---|
537 | if (val > this->maxRotation_) |
---|
538 | val = this->maxRotation_; |
---|
539 | if (val < -this->maxRotation_) |
---|
540 | val = -this->maxRotation_; |
---|
541 | this->mouseYRotation_ = Radian(val); |
---|
542 | } |
---|
543 | |
---|
544 | void SpaceShip::setMoveYaw(float val) |
---|
545 | { |
---|
546 | val = -val * val * sgn(val) * this->rotationAcceleration_; |
---|
547 | if (val > this->maxRotation_) |
---|
548 | val = this->maxRotation_; |
---|
549 | if (val < -this->maxRotation_) |
---|
550 | val = -this->maxRotation_; |
---|
551 | this->mouseXRotation_ = Radian(val); |
---|
552 | } |
---|
553 | |
---|
554 | void SpaceShip::setMoveRoll(float val) |
---|
555 | { |
---|
556 | this->momentum_ = Radian(-this->rotationAccelerationRadian_ * val); |
---|
557 | //COUT(3) << "rotating val: " << val << " acceleration: " << this->rotationAccelerationRadian_.valueDegrees() << std::endl; |
---|
558 | } |
---|
559 | |
---|
560 | void SpaceShip::setMoveLongitudinal(float val) |
---|
561 | { |
---|
562 | this->acceleration_.x = this->translationAcceleration_ * val; |
---|
563 | } |
---|
564 | |
---|
565 | void SpaceShip::setMoveLateral(float val) |
---|
566 | { |
---|
567 | this->acceleration_.y = -this->translationAcceleration_ * val; |
---|
568 | } |
---|
569 | |
---|
570 | void SpaceShip::doFire() |
---|
571 | { |
---|
572 | this->bLMousePressed_ = true; |
---|
573 | } |
---|
574 | } |
---|