Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6867 was 6867, checked in by freicy, 14 years ago

commit by cyrill

File size: 6.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 *      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    FpsPlayer::~FpsPlayer()
84    {
85    }
86
87    void FpsPlayer::XMLPort(Element& xmlelement, XMLPort::Mode mode)
88    {
89        SUPER(FpsPlayer, XMLPort, xmlelement, mode);
90       
91        XMLPortParamVariable(FpsPlayer, "primaryThrust",  primaryThrust_,  xmlelement, mode);
92        XMLPortParamVariable(FpsPlayer, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
93        XMLPortParamVariable(FpsPlayer, "rotationThrust", rotationThrust_, xmlelement, mode);
94    }
95
96    void FpsPlayer::registerVariables()
97    {
98        registerVariable(this->primaryThrust_,  VariableDirection::ToClient);
99        registerVariable(this->auxilaryThrust_, VariableDirection::ToClient);
100        registerVariable(this->rotationThrust_, VariableDirection::ToClient);
101    }
102
103    void FpsPlayer::setConfigValues()
104    {
105        SetConfigValue(bInvertYAxis_, false).description("Set this to true for joystick-like mouse behaviour (mouse up = targetting down).");
106    }
107
108    bool FpsPlayer::isCollisionTypeLegal(WorldEntity::CollisionType type) const
109    {
110        if (type != WorldEntity::Dynamic)
111        {
112            CCOUT(1) << "Error: Cannot tell a FpsPlayer not to be dynamic! Ignoring." << std::endl;
113            assert(false); // Only in debug mode
114            return false;
115        }
116        else
117            return true;
118    }
119
120    void FpsPlayer::tick(float dt)
121    {
122        if (this->hasLocalController())
123        {
124           
125            thistickboost=false;
126           
127            float localSpeedSquared = this->localVelocity_.squaredLength();
128            float localSpeed;
129            if (localSpeedSquared > 1.0)
130                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
131            else
132                localSpeed = this->speed_;
133
134            this->localVelocity_.x *= localSpeed;
135            this->localVelocity_.z *= localSpeed;
136            Vector3 temp = this->getOrientation() * this->localVelocity_;
137            if(localVelocity_.y==jumpvalue) this->setVelocity(Vector3(temp.x, temp.y + this->getVelocity().y, temp.z));
138            else this->setVelocity(Vector3(temp.x, this->getVelocity().y, temp.z));
139            this->localVelocity_.x = 0;
140            this->localVelocity_.y = 0;
141            this->localVelocity_.z = 0;
142
143            if (!this->isInMouseLook())
144            {
145                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()),WorldEntity::Parent);
146                //this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
147                this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
148 //               this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
149            }
150
151            this->yaw_ = this->pitch_ = this->roll_ = 0;
152        }
153
154        SUPER(FpsPlayer, tick, dt);
155    }
156
157    void FpsPlayer::setPlayer(PlayerInfo* player)
158    {
159        ControllableEntity::setPlayer(player);
160
161//        this->setSyncMode(ObjectDirection::ToClient);
162    }
163
164    void FpsPlayer::startLocalHumanControl()
165    {
166        ControllableEntity::startLocalHumanControl();
167    }
168   
169    void FpsPlayer::moveFrontBack(const Vector2& value)
170    {
171        this->localVelocity_.z -= value.x;
172    }
173
174
175    void FpsPlayer::moveRightLeft(const Vector2& value)
176    {
177        this->localVelocity_.x += value.x;
178    }
179
180    void FpsPlayer::moveUpDown(const Vector2& value)
181    {
182        //this->localVelocity_.y += value.x;
183    }
184
185    void FpsPlayer::rotateYaw(const Vector2& value)
186    {
187        this->yaw_ += value.y;
188
189        ControllableEntity::rotateYaw(value);
190    }
191
192    void FpsPlayer::rotatePitch(const Vector2& value)
193    {
194        this->pitch_ += value.y;
195
196        ControllableEntity::rotatePitch(value);
197    }
198
199    void FpsPlayer::rotateRoll(const Vector2& value)
200    {
201        this->roll_ += value.y;
202
203        ControllableEntity::rotateRoll(value);
204    }
205
206    void FpsPlayer::fire()
207    {
208    }
209   
210    void FpsPlayer::boost()                                     //acctually jump
211    {
212        if(isfloor) { 
213                if(!thistickboost) this->localVelocity_.y = jumpvalue;
214                //this->physicalBody_->applyCentralImpulse(btVector3(0, jumpvalue, 0));
215                thistickboost=true;
216                isfloor=false;
217        }
218    }
219
220    bool FpsPlayer::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
221    {
222        if(contactPoint.m_normalWorldOnB.y() > 0.6) isfloor=true;
223        else isfloor=false;
224       
225        return false;
226    }
227   
228}
Note: See TracBrowser for help on using the repository browser.