Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/hover/HoverShip.cc @ 12290

Last change on this file since 12290 was 12290, checked in by wiesep, 5 years ago

Rolled back to r12201

  • Property svn:eol-style set to native
File size: 4.2 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 Burgener
24 *
25 */
26
27/**
28    @file HoverShip.cc
29    @brief Implementation of the HoverShip control
30*/
31
32#include "HoverShip.h"
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35#include "graphics/Camera.h"
36
37#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
38
39namespace orxonox
40{
41    RegisterClass(HoverShip);
42
43    HoverShip::HoverShip(Context* context) : SpaceShip(context)
44    {
45        RegisterObject(HoverShip);
46        enableCollisionCallback();
47        isFloor_ = false;
48        jumpBoost_ = 0;   
49    }
50
51    void HoverShip::moveFrontBack(const Vector2& value)
52        { this->steering_.z -= value.x; 
53            Vector3 currentPosition = this->getPosition();
54            currentPosition.y -= 2*value.y;
55            this->setPosition(currentPosition);
56        }
57
58    void HoverShip::moveRightLeft(const Vector2& value)
59        { 
60            this->steering_.x += value.x; 
61            Vector3 currentPosition = this->getPosition();
62            currentPosition.x -= 2*value.x;
63            this->setPosition(currentPosition);
64        }
65
66    void HoverShip::moveUpDown(const Vector2& value)
67        { 
68            this->steering_.y += value.x; 
69            this->setPosition(Vector3(0, 0, 0));
70        }
71
72    void HoverShip::rotateYaw(const Vector2& value)
73    {
74        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
75
76        Pawn::rotateYaw(value);
77    }
78
79    void HoverShip::XMLPort(Element& xmlelement, XMLPort::Mode mode)
80    {
81        SUPER(HoverShip, XMLPort, xmlelement, mode);
82
83        XMLPortParam(HoverShip, "jumpBoost", setJumpBoost, getJumpBoost, xmlelement, mode);
84    }
85
86    void HoverShip::tick(float dt)
87    {
88        SUPER(HoverShip, tick, dt);
89                //Execute movement
90        if (this->hasLocalController())
91            {
92             // Camera
93            Camera* camera = this->getCamera();
94            if (camera != nullptr)
95            {
96                camera->setPosition(0,1000,0);
97                camera->setOrientation(Vector3::UNIT_X, Degree(-90));
98
99            }
100        }
101    }
102
103    /**
104    @brief
105        Removed, does nothing.
106    @param value
107    */
108    void HoverShip::rotatePitch(const Vector2& value) { }
109
110    /**
111    @brief
112        Removed, does nothing.
113    @param value
114    */
115    void HoverShip::rotateRoll(const Vector2& value) { }
116
117    /**
118    @brief
119        Checks if the ship is touching the floor. The ship can only jump if there is contact with someting beneath it.
120    */
121    bool HoverShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
122    {
123        SpaceShip::collidesAgainst(otherObject, cs, contactPoint);
124        //SUPER(HoverShip, collidesAgainst, otherObject, cs, contactPoint);
125
126        if (contactPoint.m_normalWorldOnB.y() > 0.6
127            && this->getVelocity().y < 1) {
128            this->isFloor_ = true;
129        } else {
130            this->isFloor_ = false;
131        }
132
133        return false;
134    }
135
136    /**
137    @brief
138        Makes the ship jump
139    @param bBoost
140    */
141    void HoverShip::boost(bool bBoost) {
142        if (bBoost && this->isFloor_)
143        {
144            this->setVelocity(
145                this->getVelocity().x,
146                jumpBoost_,
147                this->getVelocity().z
148                );
149            this->isFloor_ = false;
150        }
151    }
152}
Note: See TracBrowser for help on using the repository browser.