Ensuring all names are the correct casing for Linux
[Torque-3d.git] / Engine / source / T3D / components / Physics / playerControllerComponent.h
blobd384108884095cb8cf62da6bdf54961727d9dbe1
1 //-----------------------------------------------------------------------------
2 // Copyright (c) 2012 GarageGames, LLC
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to
6 // deal in the Software without restriction, including without limitation the
7 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 // sell copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 // IN THE SOFTWARE.
21 //-----------------------------------------------------------------------------
23 #ifndef PLAYER_CONTORLLER_COMPONENT_H
24 #define PLAYER_CONTORLLER_COMPONENT_H
26 #ifndef PHYSICSBEHAVIOR_H
27 #include "T3D/components/physics/physicsBehavior.h"
28 #endif
29 #ifndef __RESOURCE_H__
30 #include "core/resource.h"
31 #endif
32 #ifndef _TSSHAPE_H_
33 #include "ts/tsShape.h"
34 #endif
35 #ifndef _SCENERENDERSTATE_H_
36 #include "scene/sceneRenderState.h"
37 #endif
38 #ifndef _MBOX_H_
39 #include "math/mBox.h"
40 #endif
41 #ifndef ENTITY_H
42 #include "T3D/entity.h"
43 #endif
44 #ifndef _CONVEX_H_
45 #include "collision/convex.h"
46 #endif
47 #ifndef _BOXCONVEX_H_
48 #include "collision/boxConvex.h"
49 #endif
50 #ifndef _T3D_PHYSICSCOMMON_H_
51 #include "T3D/physics/physicsCommon.h"
52 #endif
53 #ifndef _T3D_PHYSICS_PHYSICSWORLD_H_
54 #include "T3D/physics/physicsWorld.h"
55 #endif
56 #ifndef PHYSICS_COMPONENT_INTERFACE_H
57 #include "T3D/components/physics/physicsComponentInterface.h"
58 #endif
59 #ifndef COLLISION_INTERFACES_H
60 #include "T3D/components/collision/collisionInterfaces.h"
61 #endif
63 class SceneRenderState;
64 class PhysicsWorld;
65 class PhysicsPlayer;
66 class SimplePhysicsBehaviorInstance;
67 class CollisionInterface;
69 //////////////////////////////////////////////////////////////////////////
70 ///
71 ///
72 //////////////////////////////////////////////////////////////////////////
73 class PlayerControllerComponent : public Component,
74 public PhysicsComponentInterface
76 typedef Component Parent;
78 enum MaskBits {
79 VelocityMask = Parent::NextFreeMask << 0,
80 PositionMask = Parent::NextFreeMask << 1,
81 NextFreeMask = Parent::NextFreeMask << 2
84 struct StateDelta
86 Move move; ///< Last move from server
87 F32 dt; ///< Last interpolation time
88 // Interpolation data
89 Point3F pos;
90 Point3F posVec;
91 QuatF rot[2];
92 // Warp data
93 S32 warpTicks; ///< Number of ticks to warp
94 S32 warpCount; ///< Current pos in warp
95 Point3F warpOffset;
96 QuatF warpRot[2];
99 StateDelta mDelta;
101 PhysicsPlayer *mPhysicsRep;
102 PhysicsWorld *mPhysicsWorld;
104 CollisionInterface* mOwnerCollisionInterface;
106 struct ContactInfo
108 bool contacted, jump, run;
109 SceneObject *contactObject;
110 VectorF contactNormal;
111 F32 contactTime;
113 void clear()
115 contacted = jump = run = false;
116 contactObject = NULL;
117 contactNormal.set(1, 1, 1);
120 ContactInfo() { clear(); }
122 } mContactInfo;
124 protected:
125 F32 mDrag;
126 F32 mBuoyancy;
127 F32 mFriction;
128 F32 mElasticity;
129 F32 mMaxVelocity;
130 bool mSticky;
132 bool mFalling;
133 bool mSwimming;
134 bool mInWater;
136 S32 mContactTimer; ///< Ticks since last contact
138 U32 mIntegrationCount;
140 Point3F mJumpSurfaceNormal; ///< Normal of the surface the player last jumped on
142 F32 maxStepHeight; ///< Maximum height the player can step up
143 F32 moveSurfaceAngle; ///< Maximum angle from vertical in degrees the player can run up
144 F32 contactSurfaceAngle; ///< Maximum angle from vertical in degrees we consider having real 'contact'
146 F32 horizMaxSpeed; ///< Max speed attainable in the horizontal
147 F32 horizMaxAccel;
148 F32 horizResistSpeed; ///< Speed at which resistance will take place
149 F32 horizResistFactor; ///< Factor of resistance once horizResistSpeed has been reached
151 F32 upMaxSpeed; ///< Max vertical speed attainable
152 F32 upMaxAccel;
153 F32 upResistSpeed; ///< Speed at which resistance will take place
154 F32 upResistFactor; ///< Factor of resistance once upResistSpeed has been reached
156 F32 fallingSpeedThreshold; ///< Downward speed at which we consider the player falling
158 // Air control
159 F32 airControl;
161 Point3F mInputVelocity;
163 bool mUseDirectMoveInput;
165 public:
166 PlayerControllerComponent();
167 virtual ~PlayerControllerComponent();
168 DECLARE_CONOBJECT(PlayerControllerComponent);
170 virtual bool onAdd();
171 virtual void onRemove();
172 static void initPersistFields();
174 virtual void onComponentAdd();
176 virtual void componentAddedToOwner(Component *comp);
177 virtual void componentRemovedFromOwner(Component *comp);
179 virtual void ownerTransformSet(MatrixF *mat);
181 virtual U32 packUpdate(NetConnection *con, U32 mask, BitStream *stream);
182 virtual void unpackUpdate(NetConnection *con, BitStream *stream);
184 void updatePhysics(PhysicsCollision *collision = NULL);
186 virtual void processTick();
187 virtual void interpolateTick(F32 dt);
188 virtual void updatePos(const F32 dt);
189 void updateMove();
191 virtual VectorF getVelocity() { return mVelocity; }
192 virtual void setVelocity(const VectorF& vel);
193 virtual void setTransform(const MatrixF& mat);
195 void findContact(bool *run, bool *jump, VectorF *contactNormal);
196 Point3F getContactNormal() { return mContactInfo.contactNormal; }
197 SceneObject* getContactObject() { return mContactInfo.contactObject; }
198 bool isContacted() { return mContactInfo.contacted; }
201 void applyImpulse(const Point3F &pos, const VectorF &vec);
203 //This is a weird artifact of the PhysicsReps. We want the collision component to be privvy to any events that happen
204 //so when the physics components do a findContact test during their update, they'll have a signal collision components
205 //can be listening to to update themselves with that info
206 Signal< void(SceneObject*) > PlayerControllerComponent::onContactSignal;
209 DECLARE_CALLBACK(void, updateMove, (PlayerControllerComponent* obj));
212 #endif // _COMPONENT_H_