Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fps/src/orxonox/worldentities/pawns/FpsPlayer.cc @ 6876

Last change on this file since 6876 was 6872, checked in by edwind, 15 years ago

commit by ed

File size: 6.8 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 *      Cyrill Frei
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "FpsPlayer.h"
30
31#include <OgreSceneNode.h>
32#include <BulletDynamics/Dynamics/btRigidBody.h>
33#include <LinearMath/btVector3.h>
34#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
35
36
37#include "core/CoreIncludes.h"
38#include "core/ConfigValueIncludes.h"
39#include "core/Template.h"
40#include "core/XMLPort.h"
41#include "items/Engine.h"
42
43#include <cmath>
44
45namespace orxonox
46{
47    const float orientationGain = 100;
48    const float jumpvalue = 300;
49    CreateFactory(FpsPlayer);
50
51    FpsPlayer::FpsPlayer(BaseObject* creator) : Pawn(creator)
52    {
53        RegisterObject(FpsPlayer);
54        this->speed_ = 200;
55        this->localVelocity_ = Vector3::ZERO;
56/*
57 *        this->primaryThrust_  = 100;
58 *        this->auxilaryThrust_ =  30;
59 *        this->rotationThrust_ =  10;
60 *
61 *        this->localLinearAcceleration_.setValue(0, 0, 0);
62 *        this->localAngularAcceleration_.setValue(0, 0, 0);
63 *        this->bBoost_ = false;
64 *        this->bPermanentBoost_ = false;
65 *        this->steering_ = Vector3::ZERO;
66*/     
67
68
69        this->bInvertYAxis_ = false;
70
71        this->setDestroyWhenPlayerLeft(true);
72
73        // FpsPlayer is always a physical object per default
74        // Be aware of this call: The collision type legality check will not reach derived classes!
75        this->setCollisionType(WorldEntity::Dynamic);
76        // Get notification about collisions
77        this->enableCollisionCallback();
78
79        this->setConfigValues();
80        this->registerVariables();
81       
82    }
83
84    FpsPlayer::~FpsPlayer()
85    {
86    }
87
88    void FpsPlayer::XMLPort(Element& xmlelement, XMLPort::Mode mode)
89    {
90        SUPER(FpsPlayer, XMLPort, xmlelement, mode);
91       
92        XMLPortParamVariable(FpsPlayer, "primaryThrust",  primaryThrust_,  xmlelement, mode);
93        XMLPortParamVariable(FpsPlayer, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
94        XMLPortParamVariable(FpsPlayer, "rotationThrust", rotationThrust_, xmlelement, mode);
95    }
96
97    void FpsPlayer::registerVariables()
98    {
99        registerVariable(this->primaryThrust_,  VariableDirection::ToClient);
100        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
101        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
102    }
103
104    void FpsPlayer::setConfigValues()
105    {
106        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = targetting down).");
107    }
108
109    bool FpsPlayer::isCollisionTypeLegal(WorldEntity::CollisionType type) const
110    {
111        if (type != WorldEntity::Dynamic)
112        {
113            CCOUT(1) << "Error: Cannot tell a FpsPlayer not to be dynamic! Ignoring." << std::endl;
114            assert(false); // Only in debug mode
115            return false;
116        }
117        else
118            return true;
119    }
120
121    void FpsPlayer::tick(float dt)
122    {
123        if (this->hasLocalController())
124        {
125            this->setOrientation(savedOrientation_);
126           
127            thistickboost=false;
128           
129            float localSpeedSquared = this->localVelocity_.squaredLength();
130            float localSpeed;
131            if (localSpeedSquared > 1.0)
132                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
133            else
134                localSpeed = this->speed_;
135
136            this->localVelocity_.x *= localSpeed;
137            this->localVelocity_.z *= localSpeed;
138            Vector3 temp = this->getOrientation() * this->localVelocity_;
139            if(localVelocity_.y==jumpvalue) this->setVelocity(Vector3(temp.x, temp.y + this->getVelocity().y, temp.z));
140            else this->setVelocity(Vector3(temp.x, this->getVelocity().y, temp.z));
141            this->localVelocity_.x = 0;
142            this->localVelocity_.y = 0;
143            this->localVelocity_.z = 0;
144
145            if (!this->isInMouseLook())
146            {
147                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()),WorldEntity::Parent);
148                //this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
149                this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
150 //               this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
151            }
152
153            this->yaw_ = this->pitch_ = this->roll_ = 0;
154           
155            //Quaternion q=this->getOrientation();
156            //if( q.y<0.99 ) this->setOrientation(q.w, q.x, 1.0, q.z);
157            this->setAngularVelocity(0.0, 0.0, 0.0);
158            savedOrientation_=this->getOrientation();
159        }
160
161        SUPER(FpsPlayer, tick, dt);
162    }
163
164    void FpsPlayer::setPlayer(PlayerInfo* player)
165    {
166        ControllableEntity::setPlayer(player);
167
168//        this->setSyncMode(ObjectDirection::ToClient);
169    }
170
171    void FpsPlayer::startLocalHumanControl()
172    {
173        ControllableEntity::startLocalHumanControl();
174    }
175   
176    void FpsPlayer::moveFrontBack(const Vector2& value)
177    {
178        this->localVelocity_.z -= value.x;
179    }
180
181
182    void FpsPlayer::moveRightLeft(const Vector2& value)
183    {
184        this->localVelocity_.x += value.x;
185    }
186
187    void FpsPlayer::moveUpDown(const Vector2& value)
188    {
189        //this->localVelocity_.y += value.x;
190    }
191
192    void FpsPlayer::rotateYaw(const Vector2& value)
193    {
194        this->yaw_ += value.y;
195
196        ControllableEntity::rotateYaw(value);
197    }
198
199    void FpsPlayer::rotatePitch(const Vector2& value)
200    {
201        this->pitch_ += value.y;
202
203        ControllableEntity::rotatePitch(value);
204    }
205
206    void FpsPlayer::rotateRoll(const Vector2& value)
207    {
208        this->roll_ += value.y;
209
210        ControllableEntity::rotateRoll(value);
211    }
212
213    void FpsPlayer::fire()
214    {
215    }
216   
217    void FpsPlayer::boost()                                     //acctually jump
218    {
219        if(isfloor) { 
220                if(!thistickboost) this->localVelocity_.y = jumpvalue;
221                //this->physicalBody_->applyCentralImpulse(btVector3(0, jumpvalue, 0));
222                thistickboost=true;
223                isfloor=false;
224        }
225    }
226
227    bool FpsPlayer::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
228    {
229        if(contactPoint.m_normalWorldOnB.y() > 0.6) isfloor=true;
230        else isfloor=false;
231       
232        return false;
233    }
234   
235}
Note: See TracBrowser for help on using the repository browser.