OpenMW
libs/openengine/bullet/pmove.h
Go to the documentation of this file.
00001 #ifndef OENGINE_BULLET_PMOVE_H
00002 #define OENGINE_BULLET_PMOVE_H
00003 /*
00004 This source file is a *modified* version of various header files from the Quake 3 Arena source code,
00005 which was released under the GNU GPL (v2) in 2005.
00006 Quake 3 Arena is copyright (C) 1999-2005 Id Software, Inc.
00007 */
00008 
00009 #include <OgreMath.h>
00010 #include <float.h>
00011 #include "trace.h"
00012 #include "physic.hpp"
00013 
00014 #include <OgreVector3.h>
00015 
00016 //#include "GameMath.h"
00017 //#include "GameTime.h"
00018 
00019 // Forwards-declare it!
00020 
00021 /*#ifndef COMPILING_PMOVE
00022 #include "Scene.h"
00023 extern SceneInstance* global_lastscene;
00024 #endif*/
00025 
00026 static const Ogre::Vector3 halfExtentsDefault(14.64f * 2, 14.24f * 2, 33.25f * 2);
00027 
00028 #define MAX_CLIP_PLANES 5
00029 #define OVERCLIP 1.001f
00030 //#define       STEPSIZE 18 // 18 is way too much
00031 #define STEPSIZE (9)
00032 #ifndef M_PI
00033         #define M_PI 3.14159265358979323846f
00034 #endif
00035 #define YAW 0
00036 #define PITCH /*1*/2
00037 #define ROLL /*2*/1
00038 #define SHORT2ANGLE(x) ( (x) * (360.0f / 65536.0f) )
00039 #define ANGLE2SHORT(x) ( (const short)( (x) / (360.0f / 65536.0f) ) )
00040 #define GENTITYNUM_BITS 10 // don't need to send any more
00041 #define MAX_GENTITIES (1 << GENTITYNUM_BITS)
00042 #define ENTITYNUM_NONE (MAX_GENTITIES - 1)
00043 #define ENTITYNUM_WORLD (MAX_GENTITIES - 2)
00044 #define MIN_WALK_NORMAL .7f // can't walk on very steep slopes
00045 #define PS_PMOVEFRAMECOUNTBITS 6
00046 #define MINS_Z -24
00047 #define DEFAULT_VIEWHEIGHT 26
00048 #define CROUCH_VIEWHEIGHT 12
00049 #define DEAD_VIEWHEIGHT (-16)
00050 #define CONTENTS_SOLID                  1               // an eye is never valid in a solid
00051 #define CONTENTS_LAVA                   8
00052 #define CONTENTS_SLIME                  16
00053 #define CONTENTS_WATER                  32
00054 #define CONTENTS_FOG                    64
00055 static const float      pm_accelerate = 10.0f;
00056 static const float      pm_stopspeed = 100.0f;
00057 static const float      pm_friction = 12.0f;
00058 static const float  pm_flightfriction = 3.0f;
00059 static const float      pm_waterfriction = 1.0f;
00060 static const float      pm_airaccelerate = 1.0f;
00061 static const float      pm_swimScale = 0.50f;
00062 static const float      pm_duckScale = 0.25f;
00063 static const float  pm_flyaccelerate = 8.0f;
00064 static const float      pm_wateraccelerate = 4.0f;
00065 
00066 enum pmtype_t
00067 {
00068         PM_NORMAL,              // can accelerate and turn
00069         PM_NOCLIP,              // noclip movement
00070         PM_SPECTATOR,   // still run into walls
00071         PM_DEAD,                // no acceleration or turning, but free falling
00072         PM_FREEZE,              // stuck in place with no control
00073         PM_INTERMISSION,        // no movement or status bar
00074         PM_SPINTERMISSION       // no movement or status bar
00075 };
00076 
00077 enum waterlevel_t
00078 {
00079         WL_DRYLAND = 0,
00080         WL_ANKLE,
00081         WL_WAIST,
00082         WL_UNDERWATER
00083 };
00084 
00085 
00086 //#include "bprintf.h"
00087 
00088 struct playerMove
00089 {
00090         struct playerStruct
00091         {
00092                 playerStruct() : gravity(800.0f), speed(480.0f), jump_velocity(270), pmove_framecount(20), groundEntityNum(ENTITYNUM_NONE), commandTime(40), move_type(PM_NOCLIP), pm_time(0), snappingImplemented(true), bSnap(false), counter(-1), halfExtents(halfExtentsDefault)
00093                 {
00094                         origin = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00095                         velocity = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00096 
00097                         viewangles = Ogre::Vector3(0.0f, 0.0f, 0.0f);
00098 
00099                         delta_angles[0] = delta_angles[1] = delta_angles[2] = 0;
00100 
00101                         lastframe_origin.x = lastframe_origin.y = lastframe_origin.z = 0;
00102                         lerp_multiplier.x = lerp_multiplier.y = lerp_multiplier.z = 0;
00103                 }
00104 
00105                 inline void SpeedUp(void)
00106                 {
00107                         //printf("speed up to: %f\n", speed);
00108                         speed *= 1.25f;
00109                 }
00110 
00111                 inline void SpeedDown(void)
00112                 {
00113                         //printf("speed down to %f\n", speed);
00114                         speed /= 1.25f;
00115                 }
00116 
00117                 Ogre::Vector3 velocity;
00118                 Ogre::Vector3 origin;
00119         Ogre::Vector3 halfExtents;
00120         bool bSnap;
00121         bool snappingImplemented;
00122         int counter;
00123                 float gravity; // default = 800
00124                 float speed; // default = 320
00125         float jump_velocity;  //default = 270
00126 
00127                 int commandTime; // the time at which this command was issued (in milliseconds)
00128 
00129                 int pm_time;
00130 
00131                 Ogre::Vector3 viewangles;
00132 
00133                 int groundEntityNum;
00134 
00135                 int pmove_framecount;
00136 
00137                 int watertype;
00138                 waterlevel_t waterlevel;
00139 
00140                 signed short delta_angles[3];
00141 
00142                 pmtype_t move_type;
00143 
00144                 float last_compute_time;
00145                 Ogre::Vector3 lastframe_origin;
00146                 Ogre::Vector3 lerp_multiplier;
00147         } ps;
00148 
00149         struct playercmd
00150         {
00151                 enum CMDstateChange
00152                 {
00153                         NO_CHANGE,
00154                         KEYDOWN,
00155                         KEYUP
00156                 };
00157 
00158                 playercmd() : forwardmove(0), rightmove(0), upmove(0), serverTime(50), ducking(false),
00159                         activating(false), lastActivatingState(false), procActivating(NO_CHANGE),
00160                         dropping(false), lastDroppingState(false), procDropping(NO_CHANGE)
00161                 {
00162                         angles[0] = angles[1] = angles[2] = 0;
00163                 }
00164 
00165                 int serverTime;
00166 
00167                 short angles[3];
00168 
00169                 signed char forwardmove;
00170                 signed char rightmove;
00171                 signed char upmove;
00172 
00173                 bool ducking;
00174                 bool activating; // if the user is holding down the activate button
00175                 bool dropping; // if the user is dropping an item
00176 
00177                 bool lastActivatingState;
00178                 bool lastDroppingState;
00179 
00180                 CMDstateChange procActivating;
00181                 CMDstateChange procDropping;
00182         } cmd;
00183 
00184         playerMove() : msec(50), pmove_fixed(false), pmove_msec(50), waterHeight(0), isInterior(true), hasWater(false)
00185         {
00186         }
00187 
00188         int msec;
00189         int pmove_msec;
00190         bool pmove_fixed;
00191         int waterHeight;
00192         bool hasWater;
00193         bool isInterior;
00194         OEngine::Physic::PhysicEngine* mEngine;
00195 };
00196 
00197 void Pmove (playerMove* const pmove);
00198 void Ext_UpdateViewAngles(playerMove* const pm);
00199 void AngleVectors( const Ogre::Vector3& angles, Ogre::Vector3* const forward, Ogre::Vector3* const right, Ogre::Vector3* const up) ;
00200 #endif