Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/orxonox_tutorial/src/orxonox/objects/SpaceShip_backend.cc @ 1833

Last change on this file since 1833 was 1833, checked in by scheusso, 16 years ago

splitted up SpaceShip into 2 files (don't panic, this applies only to the tutorial ;) )

  • Property svn:eol-style set to native
File size: 9.6 KB
Line 
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
30#include "OrxonoxStableHeaders.h"
31
32#include <OgreCamera.h>
33#include <OgreRenderWindow.h>
34#include <OgreParticleSystem.h>
35#include <OgreSceneNode.h>
36
37#include "util/Convert.h"
38#include "util/Math.h"
39#include "util/Debug.h"
40#include "core/CoreIncludes.h"
41#include "core/ConfigValueIncludes.h"
42#include "core/Iterator.h"
43#include "core/input/InputManager.h"
44#include "core/XMLPort.h"
45#include "core/ConsoleCommand.h"
46#include "tools/ParticleInterface.h"
47#include "network/Client.h"
48#include "Backlight.h"
49#include "CameraHandler.h"
50#include "ParticleSpawner.h"
51#include "Settings.h"
52#include "RotatingProjectile.h"
53#include "ParticleProjectile.h"
54#include "GraphicsEngine.h"
55#include "SpaceShipAI.h"
56
57namespace orxonox{
58
59SetConsoleCommand(SpaceShip, setMaxSpeedTest, false).accessLevel(AccessLevel::Debug);
60    SetConsoleCommand(SpaceShip, whereAmI, true).accessLevel(AccessLevel::User);
61    SetConsoleCommand(SpaceShip, moveLongitudinal, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
62    SetConsoleCommand(SpaceShip, moveLateral, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
63    SetConsoleCommand(SpaceShip, moveYaw, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
64    SetConsoleCommand(SpaceShip, movePitch, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
65    SetConsoleCommand(SpaceShip, moveRoll, true).accessLevel(AccessLevel::User).defaultValue(0, 1.0f).axisParamIndex(0).keybindMode(KeybindMode::OnHold);
66    SetConsoleCommand(SpaceShip, fire, true).accessLevel(AccessLevel::User).keybindMode(KeybindMode::OnHold);
67    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxSpeed", 1, false).accessLevel(AccessLevel::Debug);
68    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setMaxBlubber", 2, false).accessLevel(AccessLevel::Debug);
69    SetConsoleCommandAliasMulti(SpaceShip, setMaxSpeedTest, "setRofl", 3, false).accessLevel(AccessLevel::Debug);
70
71
72
73    CreateFactory(SpaceShip);
74
75    SpaceShip* SpaceShip::instance_s;
76
77
78    SpaceShip *SpaceShip::getLocalShip(){
79      ObjectList<SpaceShip>::iterator it;
80      for(it = ObjectList<SpaceShip>::begin(); it; ++it){
81        assert(it->isA(Class(SpaceShip)));
82        if( (it)->myShip_ || (network::Host::running() && network::Host::getShipID()==(it)->objectID) ){
83//        COUT(1) << "^^^^^^^^^^ myShip_:" << *it << " classname: " << (*it)->getIdentifier()->getName() << " objectid: " << (*it)->objectID << std::endl;
84          return *it;
85        }
86      }
87      return 0;
88    }
89
90
91bool SpaceShip::create()
92    {
93        if (!myShip_)
94        {
95            if (network::Host::running())
96                //COUT(3) << "this id: " << this->objectID << " myShipID: " << network::Host::getShipID() << std::endl;
97                if (network::Host::running() && objectID == network::Host::getShipID())
98                {
99                    if (!network::Host::isServer())
100                        setObjectMode(0x3);
101                    myShip_ = true;
102                }
103        }
104        else
105            this->setRadarObjectColour(this->getProjectileColour());
106        assert(Model::create());
107        this->init();
108        return true;
109    }
110
111
112
113
114    void SpaceShip::registerAllVariables()
115    {
116        registerVar( &camName_, camName_.length()+1, network::STRING, 0x1 );
117        registerVar( &maxSpeed_, sizeof(maxSpeed_), network::DATA, 0x1);
118        registerVar( &maxSideAndBackSpeed_, sizeof(maxSideAndBackSpeed_), network::DATA, 0x1);
119        registerVar( &maxRotation_, sizeof(maxRotation_), network::DATA, 0x1);
120        registerVar( &translationAcceleration_, sizeof(translationAcceleration_), network::DATA, 0x1);
121        registerVar( &rotationAcceleration_, sizeof(rotationAcceleration_), network::DATA, 0x1);
122        registerVar( &rotationAccelerationRadian_, sizeof(rotationAccelerationRadian_), network::DATA, 0x1);
123        registerVar( &translationDamping_, sizeof(translationDamping_), network::DATA, 0x1);
124        registerVar( &rotationDamping_, sizeof(rotationDamping_), network::DATA, 0x1);
125        registerVar( &rotationDampingRadian_, sizeof(rotationDampingRadian_), network::DATA, 0x1);
126    }
127
128
129
130void SpaceShip::changedVisibility()
131    {
132        SUPER(SpaceShip, changedVisibility);
133
134        this->tt1_->setEnabled(this->isVisible());
135        this->tt2_->setEnabled(this->isVisible());
136        this->redBillboard_.setVisible(this->isVisible());
137        this->greenBillboard_.setVisible(this->isVisible());
138        this->crosshairNear_.setVisible(this->isVisible());
139        this->crosshairFar_.setVisible(this->isVisible());
140        this->rightThrusterFlare_.setVisible(this->isVisible());
141        this->leftThrusterFlare_.setVisible(this->isVisible());
142        this->smoke_->setVisible(this->isVisible());
143        this->fire_->setVisible(this->isVisible());
144        this->backlight_->setVisible(this->isVisible());
145    }
146
147    void SpaceShip::changedActivity()
148    {
149        SUPER(SpaceShip, changedActivity);
150
151        this->tt1_->setEnabled(this->isVisible());
152        this->tt2_->setEnabled(this->isVisible());
153        this->redBillboard_.setVisible(this->isVisible());
154        this->greenBillboard_.setVisible(this->isVisible());
155        this->crosshairNear_.setVisible(this->isVisible());
156        this->crosshairFar_.setVisible(this->isVisible());
157        this->rightThrusterFlare_.setVisible(this->isVisible());
158        this->leftThrusterFlare_.setVisible(this->isVisible());
159    }
160
161    void SpaceShip::setCamera(const std::string& camera)
162    {
163      camName_=camera;
164      // change camera attributes here, if you want to ;)
165    }
166
167    void SpaceShip::getFocus(){
168      COUT(4) << "requesting focus" << std::endl;
169      //if(!network::Host::running() || network::Host::getShipID()==objectID)
170      if(myShip_)
171        CameraHandler::getInstance()->requestFocus(cam_);
172
173    }
174
175    Camera* SpaceShip::getCamera(){
176        return cam_;
177    }
178
179    void SpaceShip::createCamera(){
180//       COUT(4) << "begin camera creation" << std::endl;
181      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
182      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
183      this->camNode_->setPosition(Vector3(-25,0,5));
184//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
185//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
186//      camNode_->setOrientation(q1*q2);
187      COUT(4) << "position: (cam)" << this->camNode_->getPosition() << std::endl;
188      cam_ = new Camera(this->camNode_);
189
190      cam_->setTargetNode(this->getNode());
191//        cam->setPosition(Vector3(0,-350,0));
192//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,0,1));
193//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,1,0));
194      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
195      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
196
197       this->camNode_->setOrientation(q2*q1);
198      //if(!network::Host::running() || network::Host::getShipID()==objectID){ //TODO: check this
199      if(myShip_){
200        COUT(4) << "requesting focus for camera" << std::endl;
201        //CameraHandler::getInstance()->requestFocus(cam_);
202        if(this->isExactlyA(Class(SpaceShip))){
203          getFocus();
204          COUT(4) << "getting focus for obj id: " << objectID << std::endl;
205        }else
206          COUT(4) << "not getting focus (not exactly spaceship) for obj id: " << objectID << std::endl;
207      }else
208        COUT(4) << "not getting focus (not my ship) for obj id: " << objectID << std::endl;
209    }
210
211    void SpaceShip::setMaxSpeed(float value)
212    { this->maxSpeed_ = value; }
213    void SpaceShip::setMaxSideAndBackSpeed(float value)
214    { this->maxSideAndBackSpeed_ = value; }
215    void SpaceShip::setMaxRotation(float value)
216    { this->maxRotation_ = value; this->maxRotationRadian_ = Radian(value); }
217    void SpaceShip::setTransAcc(float value)
218    { this->translationAcceleration_ = value; }
219    void SpaceShip::setRotAcc(float value)
220    { this->rotationAcceleration_ = value; this->rotationAccelerationRadian_ = Radian(value); }
221    void SpaceShip::setTransDamp(float value)
222    { this->translationDamping_ = value; }
223    void SpaceShip::setRotDamp(float value)
224    { this->rotationDamping_ = value; this->rotationDampingRadian_ = Radian(value); }
225
226
227    std::string SpaceShip::whereAmI() {
228        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
229        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
230        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
231    }
232
233
234
235
236
237
238
239
240}
Note: See TracBrowser for help on using the repository browser.