00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OgreBulletListener_H_
00019 #define _OgreBulletListener_H_
00020
00021 #include "OgreBulletDynamics.h"
00022
00023 #include "OgreBulletInputListener.h"
00024 #include "OgreBulletGuiListener.h"
00025
00026 #define BASIC_HELP_INFO0 "Use F1, F2, F3, F4"
00027 #define BASIC_HELP_INFO1 "B,N,G,H to Throw a Cube, Sphere, Cone, Cylinder"
00028 #define BASIC_HELP_INFO2 "J,K,I,U to Drop a Cube, Sphere, Cone, Cylinder"
00029 #define BASIC_HELP_INFO3 ""
00030 #define BASIC_HELP_INFO4 "left click to drag"
00031 #define BASIC_HELP_INFO5 "right to camera move"
00032 #define BASIC_HELP_INFO6 "middle for impulse"
00033
00034 enum QueryFlags
00035 {
00036 ANY_QUERY_MASK = 1<<0,
00037 RAGDOLL_QUERY_MASK = 1<<1,
00038 GEOMETRY_QUERY_MASK = 1<<2,
00039 VEHICLE_QUERY_MASK = 1<<3,
00040 STATIC_GEOMETRY_QUERY_MASK = 1<<4
00041 };
00042
00043 class OgreBulletApplication;
00044
00045
00046
00047
00048 class OgreBulletListener
00049 {
00050 public:
00051
00052
00053 OgreBulletListener();
00054 virtual ~OgreBulletListener(){};
00055 virtual void init(Ogre::Root *root, Ogre::RenderWindow *win, OgreBulletApplication *application);
00056
00057 virtual void shutdown();
00058
00059 void setPhysicGUI();
00060 void setBasicLight();
00061
00062 const BULLET_KEY_CODE getNextKey() const {return mActivationKeyCode;};
00063 void setNextKey(BULLET_KEY_CODE code){mActivationKeyCode = code;};
00064
00065 void setInfoText();
00066
00067 const Ogre::String getName() {return mName;}
00068
00069 virtual bool frameStarted(Ogre::Real elapsedTime);
00070 virtual bool frameEnded(Ogre::Real elapsedTime);
00071
00072 bool checkIfEnoughPlaceToAddObject(float maxDist);
00073 void throwDynamicObject(BULLET_KEY_CODE key);
00074 void dropDynamicObject(BULLET_KEY_CODE key);
00075
00076 OgreBulletInputListener *getInputListener(){return mInputListener;}
00077
00078 virtual void mouseMoved();
00079
00080 virtual void button0Pressed();
00081 virtual void button1Pressed();
00082 virtual void button2Pressed();
00083
00084 virtual void button0Released();
00085 virtual void button1Released();
00086 virtual void button2Released();
00087
00088 virtual void keyPressed(BULLET_KEY_CODE key);
00089 virtual void keyReleased(BULLET_KEY_CODE key);
00090
00091 bool *getBoolActivator(){return &mActivationBool;}
00092
00093 void setDebugText(const Ogre::String &debugText){mDebugText = debugText;}
00094
00095 protected:
00096
00097 void initWorld (const Ogre::Vector3 &gravityVector = Ogre::Vector3 (0,-9.81,0),
00098 const Ogre::AxisAlignedBox &bounds = Ogre::AxisAlignedBox (Ogre::Vector3 (-10000, -10000, -10000),
00099 Ogre::Vector3 (10000, 10000, 10000)));
00100
00101 void addGround();
00102
00103 OgreBulletDynamics::RigidBody *addCube(const Ogre::String instanceName,
00104 const Ogre::Vector3 &pos, const Ogre::Quaternion &q, const Ogre::Vector3 &size,
00105 const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
00106 const Ogre::Real bodyMass);
00107
00108 OgreBulletDynamics::RigidBody *addCylinder(const Ogre::String instanceName,
00109 const Ogre::Vector3 &pos, const Ogre::Quaternion &q, const Ogre::Vector3 &size,
00110 const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
00111 const Ogre::Real bodyMass);
00112
00113 OgreBulletDynamics::RigidBody *addSphere(const Ogre::String instanceName,
00114 const Ogre::Vector3 &pos, const Ogre::Quaternion &q, const Ogre::Real radius,
00115 const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
00116 const Ogre::Real bodyMass);
00117
00118
00119 OgreBulletDynamics::RigidBody *addCone(const Ogre::String instanceName,
00120 const Ogre::Vector3 &pos, const Ogre::Quaternion &q, const Ogre::Vector3 &size,
00121 const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction,
00122 const Ogre::Real bodyMass);
00123
00124 OgreBulletDynamics::RigidBody *addStaticTrimesh(const Ogre::String &instanceName,
00125 const Ogre::String &meshName,
00126 const Ogre::Vector3 &pos,
00127 const Ogre::Quaternion &q,
00128 const Ogre::Real bodyRestitution,
00129 const Ogre::Real bodyFriction,
00130 const bool castShadow = true);
00131
00132 OgreBulletDynamics::RigidBody *addStaticPlane( const Ogre::Real bodyRestitution,
00133 const Ogre::Real bodyFriction);
00134
00135
00136 void getDebugLines();
00137
00138 OgreBulletDynamics::RigidBody* getBodyUnderCursorUsingBullet(Ogre::Vector3 &intersectionPoint, Ogre::Ray &rayTo);
00139 OgreBulletDynamics::RigidBody* getBodyUnderCursorUsingOgre(Ogre::Vector3 &intersectionPoint, Ogre::Ray &rayTo);
00140
00141
00142 protected:
00143 static size_t mNumEntitiesInstanced;
00144
00145 Ogre::RenderWindow *mWindow;
00146 Ogre::Root *mRoot;
00147 Ogre::SceneManager *mSceneMgr;
00148
00149 int mCurrentShadowTechnique;
00150 Ogre::Light *mSunLight;
00151 Ogre::Light *mLight;
00152 Ogre::Light *mLight2;
00153
00154
00155 Ogre::Camera *mCamera;
00156 Ogre::Radian mCameraRotX;
00157 Ogre::Radian mCameraRotY;
00158 float mCameraMove;
00159 Ogre::Vector3 mCameraTrans;
00160
00161 OgreBulletDynamics::DynamicsWorld *mWorld;
00162 OgreBulletApplication *mApplication;
00163
00164
00165 std::deque<Ogre::Entity *> mEntities;
00166 std::deque<OgreBulletDynamics::RigidBody *> mBodies;
00167 std::deque<OgreBulletCollisions::CollisionShape *> mShapes;
00168
00169 bool mStatsOn;
00170 bool mQuit;
00171 bool mDoOnestep;
00172
00173 float mShootSpeed;
00174 float mImpulseForce;
00175 bool mPaused;
00176
00177
00178 bool mWireFrame;
00179 bool mDrawAabb;
00180 bool mDrawFeaturesText;
00181 bool mDrawContactPoints;
00182 bool mNoDeactivation;
00183 bool mNoHelpText;
00184 bool mDrawText;
00185 bool mProfileTimings;
00186 bool mEnableSatComparison;
00187 bool mDisableBulletLCP;
00188 bool mEnableCCD;
00189
00190
00191 BetaGUI::StaticText* mFpsStaticText;
00192
00193
00194
00195 OgreBulletDynamics::RigidBody *mPickedBody;
00196 OgreBulletDynamics::TypedConstraint *mPickConstraint;
00197 Ogre::Vector3 mOldPickingPos;
00198 Ogre::Vector3 mOldPickingDist;
00199 OgreBulletCollisions::CollisionClosestRayResultCallback *mCollisionClosestRayResultCallback;
00200
00201 OgreBulletCollisions::DebugLines *mDebugRayLine;
00202 Ogre::RaySceneQuery *mRayQuery;
00203
00204 BULLET_KEY_CODE mActivationKeyCode;
00205 bool mActivationBool;
00206
00207 OgreBulletInputListener *mInputListener;
00208 OgreBulletGuiListener *mGuiListener;
00209
00210 Ogre::String mDebugText;
00211
00212 Ogre::String mName;
00213 std::vector<Ogre::String> mHelpKeys;
00214 void updateStats();
00215 };
00216
00217 #endif
00218