SuperTuxKart
Loading...
Searching...
No Matches
moveable.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
4// Copyright (C) 2006-2015 Joerg Henrichs, Steve Baker
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 3
9// of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20#ifndef HEADER_MOVEABLE_HPP
21#define HEADER_MOVEABLE_HPP
22
23namespace irr
24{
25 namespace scene { class IMesh; class IMeshSceneNode; class ISceneNode; }
26}
27using namespace irr;
28#include "btBulletDynamicsCommon.h"
29
31#include "physics/kart_motion_state.hpp"
32#include "physics/user_pointer.hpp"
33#include "utils/no_copy.hpp"
34#include "utils/vec3.hpp"
35
36#include <memory>
37#include <string>
38
39class Material;
40
44class Moveable: public NoCopy,
46{
47private:
50 float m_heading;
52 float m_pitch;
54 float m_roll;
55protected:
57 btTransform m_transform;
58 UserPointer m_user_pointer;
59 scene::ISceneNode *m_node;
60 std::unique_ptr<btRigidBody> m_body;
61 std::unique_ptr<KartMotionState> m_motion_state;
62 // ------------------------------------------------------------------------
63 void updateSmoothedGraphics(float dt);
64 // ------------------------------------------------------------------------
65 virtual void updateGraphics(const Vec3& off_xyz = Vec3(0.0f, 0.0f, 0.0f),
66 const btQuaternion& off_rotation =
67 btQuaternion(0.0f, 0.0f, 0.0f, 1.0f));
68
69public:
70 Moveable();
71 virtual ~Moveable();
73 scene::ISceneNode
74 *getNode() const { return m_node; }
75 void setNode(scene::ISceneNode *n);
76 virtual const btVector3
77 &getVelocity() const {return m_body->getLinearVelocity();}
78 const btVector3
79 &getVelocityLC() const {return m_velocityLC; }
80 virtual void setVelocity(const btVector3& v) {m_body->setLinearVelocity(v); }
81 const Vec3& getXYZ() const {return (Vec3&)m_transform.getOrigin();}
83 float getHeading() const {return m_heading; }
85 float getPitch() const {return m_pitch; }
87 float getRoll() const {return m_roll; }
88 const btQuaternion
89 getRotation() const {return m_transform.getRotation(); }
90
92 virtual void flyUp();
93 virtual void flyDown();
94 virtual void stopFlying();
95
97 virtual void setXYZ(const Vec3& a)
98 {
99 m_transform.setOrigin(a);
100 if(m_motion_state)
101 m_motion_state->setWorldTransform(m_transform);
102 } // setXYZ
103 // ------------------------------------------------------------------------
105 void setRotation(const btMatrix3x3 &m)
106 {
107 m_transform.setBasis(m);
108 if(m_motion_state)
109 m_motion_state->setWorldTransform(m_transform);
110 } // setRotation(btMatrix3x3)
111 // ------------------------------------------------------------------------
113 void setRotation(const btQuaternion &q)
114 {
115 m_transform.setRotation(q);
116 if(m_motion_state)
117 m_motion_state->setWorldTransform(m_transform);
118 } // setRotation(btQuaternion)
119 // ------------------------------------------------------------------------
120 virtual void reset();
121 virtual void update(int ticks) ;
122 btRigidBody *getBody() const {return m_body.get(); }
123 void createBody(float mass, btTransform& trans,
124 btCollisionShape *shape,
125 float restitution);
126 const btTransform
127 &getTrans() const {return m_transform;}
128 void setTrans(const btTransform& t);
129 void updatePosition();
130 // ------------------------------------------------------------------------
135 virtual void updateGraphics(float dt) = 0;
136 // ------------------------------------------------------------------------
137 void prepareSmoothing()
138 {
139 SmoothNetworkBody::prepareSmoothing(m_transform, getVelocity());
140 }
141 // ------------------------------------------------------------------------
142 void checkSmoothing()
143 {
145 }
146 // ------------------------------------------------------------------------
147 const btTransform &getSmoothedTrans() const
148 { return SmoothNetworkBody::getSmoothedTrans(); }
149 // ------------------------------------------------------------------------
150 const Vec3& getSmoothedXYZ() const
151 { return (Vec3&)SmoothNetworkBody::getSmoothedTrans().getOrigin(); }
152 // ------------------------------------------------------------------------
153 virtual const std::string& getIdent() const
154 {
155 static std::string unused("unused");
156 return unused;
157 }
158}; // class Moveable
159
160#endif
Definition: material.hpp:48
Definition: moveable.hpp:46
void createBody(float mass, btTransform &trans, btCollisionShape *shape, float restitution)
Creates the bullet rigid body for this moveable.
Definition: moveable.cpp:184
float getHeading() const
Returns the heading between -pi and pi.
Definition: moveable.hpp:83
virtual void flyUp()
Enter flying mode.
Definition: moveable.cpp:130
float m_pitch
The pitch between -90 and 90 degrees.
Definition: moveable.hpp:52
void updatePosition()
Updates the current position and rotation.
Definition: moveable.cpp:165
float m_heading
The 'real' heading between -180 to 180 degrees.
Definition: moveable.hpp:50
scene::ISceneNode * getNode() const
Returns the scene node of this moveable.
Definition: moveable.hpp:74
float getRoll() const
Returns the roll of the kart between -pi and pi.
Definition: moveable.hpp:87
virtual void updateGraphics(float dt)=0
Called once per rendered frame.
virtual void updateGraphics(const Vec3 &off_xyz=Vec3(0.0f, 0.0f, 0.0f), const btQuaternion &off_rotation=btQuaternion(0.0f, 0.0f, 0.0f, 1.0f))
Updates the graphics model.
Definition: moveable.cpp:83
Vec3 m_velocityLC
Velocity in kart coordinates.
Definition: moveable.hpp:48
virtual void update(int ticks)
Updates the current position and rotation from the corresponding physics body, and then calls updateG...
Definition: moveable.cpp:153
void setRotation(const btQuaternion &q)
Sets the rotation of the physical body this moveable.
Definition: moveable.hpp:113
void setTrans(const btTransform &t)
Places this moveable at a certain location and stores this transform in this Moveable,...
Definition: moveable.cpp:221
virtual void setXYZ(const Vec3 &a)
Sets the XYZ coordinates of the moveable.
Definition: moveable.hpp:97
btTransform m_transform
The bullet transform of this rigid body.
Definition: moveable.hpp:57
float getPitch() const
Returns the pitch of the kart, restricted to between -pi/2 and pi/2.
Definition: moveable.hpp:85
float m_roll
The roll between -180 and 180 degrees.
Definition: moveable.hpp:54
virtual void reset()
The reset position must be set before calling reset.
Definition: moveable.cpp:104
void setRotation(const btMatrix3x3 &m)
Sets the rotation of the physical body this moveable.
Definition: moveable.hpp:105
void setNode(scene::ISceneNode *n)
Sets the mesh for this model.
Definition: moveable.cpp:51
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: smooth_network_body.hpp:39
void checkSmoothing(const btTransform &current_transform, const Vec3 &current_velocity)
Adds a new error between graphical and physical position/rotation.
Definition: smooth_network_body.cpp:57
A UserPointer is stored as a user pointer in all bullet bodies.
Definition: user_pointer.hpp:36
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
This class help to smooth the graphicial transformation of network controlled object....