[1985] | 1 | /*************************************************************************** |
---|
| 2 | |
---|
| 3 | This source file is part of OGREBULLET |
---|
| 4 | (Object-oriented Graphics Rendering Engine Bullet Wrapper) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10 |
---|
| 6 | |
---|
| 7 | Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes) |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | This program is free software; you can redistribute it and/or modify it under |
---|
| 12 | the terms of the GPL General Public License with runtime exception as published by the Free Software |
---|
| 13 | Foundation; either version 2 of the License, or (at your option) any later |
---|
| 14 | version. |
---|
| 15 | |
---|
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
| 18 | FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details. |
---|
| 19 | |
---|
| 20 | You should have received a copy of the GPL General Public License with runtime exception along with |
---|
| 21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
| 22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
| 23 | http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 24 | ----------------------------------------------------------------------------- |
---|
| 25 | */ |
---|
| 26 | #ifndef _OGREBULLETDYNAMICS_RaycastVehicle_H |
---|
| 27 | #define _OGREBULLETDYNAMICS_RaycastVehicle_H |
---|
| 28 | |
---|
| 29 | #include "OgreBulletDynamicsPreRequisites.h" |
---|
| 30 | |
---|
| 31 | #include "OgreBulletDynamicsConstraint.h" |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | namespace OgreBulletDynamics |
---|
| 35 | { |
---|
| 36 | |
---|
| 37 | // ------------------------------------------------------------------------- |
---|
| 38 | // VehicleRayCaster class |
---|
| 39 | class VehicleRayCaster |
---|
| 40 | { |
---|
| 41 | public: |
---|
| 42 | VehicleRayCaster(DynamicsWorld *world); |
---|
| 43 | virtual ~VehicleRayCaster(); |
---|
| 44 | |
---|
| 45 | btVehicleRaycaster *getBulletVehicleRayCaster() |
---|
| 46 | {return static_cast <btVehicleRaycaster*> (mBulletVehicleRayCaster);}; |
---|
| 47 | |
---|
| 48 | private: |
---|
| 49 | btDefaultVehicleRaycaster *mBulletVehicleRayCaster; |
---|
| 50 | }; |
---|
| 51 | // ------------------------------------------------------------------------- |
---|
| 52 | // VehicleTuning class |
---|
| 53 | class VehicleTuning |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | VehicleTuning( |
---|
| 57 | const Ogre::Real suspensionStiffness, |
---|
| 58 | const Ogre::Real suspensionCompression, |
---|
| 59 | const Ogre::Real suspensionDamping, |
---|
| 60 | const Ogre::Real maxSuspensionTravelCm, |
---|
| 61 | const Ogre::Real frictionSlip); |
---|
| 62 | virtual ~VehicleTuning(); |
---|
| 63 | |
---|
| 64 | btRaycastVehicle::btVehicleTuning *getBulletTuning() |
---|
| 65 | {return mBulletTuning;}; |
---|
| 66 | |
---|
| 67 | private: |
---|
| 68 | btRaycastVehicle::btVehicleTuning *mBulletTuning; |
---|
| 69 | }; |
---|
| 70 | // ------------------------------------------------------------------------- |
---|
| 71 | // RaycastVehicle class |
---|
| 72 | class WheelInfo |
---|
| 73 | { |
---|
| 74 | public: |
---|
| 75 | WheelInfo(btWheelInfo &w): |
---|
| 76 | mWheel(&w) |
---|
| 77 | {}; |
---|
| 78 | virtual ~WheelInfo(){}; |
---|
| 79 | |
---|
| 80 | btWheelInfo *getBulletWheelInfo(){return static_cast<btWheelInfo *> (mWheel);} |
---|
| 81 | |
---|
| 82 | protected: |
---|
| 83 | btWheelInfo *mWheel; |
---|
| 84 | }; |
---|
| 85 | // ------------------------------------------------------------------------- |
---|
| 86 | // RaycastVehicle class |
---|
| 87 | class RaycastVehicle : public TypedConstraint |
---|
| 88 | { |
---|
| 89 | public: |
---|
| 90 | RaycastVehicle(WheeledRigidBody *body, |
---|
| 91 | VehicleTuning *vt, |
---|
| 92 | VehicleRayCaster *caster = 0); |
---|
| 93 | |
---|
| 94 | virtual ~RaycastVehicle(); |
---|
| 95 | |
---|
| 96 | btRaycastVehicle *getBulletVehicle() |
---|
| 97 | {return static_cast<btRaycastVehicle *> (mConstraint);}; |
---|
| 98 | void setCoordinateSystem(int rightIndex,int upIndex,int forwardIndex); |
---|
| 99 | |
---|
| 100 | void addWheel( |
---|
| 101 | Ogre::SceneNode *node, |
---|
| 102 | const Ogre::Vector3 &connectionPoint, |
---|
| 103 | const Ogre::Vector3 &wheelDirection, |
---|
| 104 | const Ogre::Vector3 &wheelAxle, |
---|
| 105 | const Ogre::Real suspensionRestLength, |
---|
| 106 | const Ogre::Real wheelRadius, |
---|
| 107 | const bool isFrontWheel, |
---|
| 108 | const Ogre::Real wheelFriction, |
---|
| 109 | const Ogre::Real rollInfluence); |
---|
| 110 | |
---|
| 111 | // when all wheels are attached, make vehicle aware of it |
---|
| 112 | void setWheelsAttached(); |
---|
| 113 | // update wheels when needed. |
---|
| 114 | void setTransform(); |
---|
| 115 | |
---|
| 116 | void applyEngineForce (float engineForce, int wheel); |
---|
| 117 | void setSteeringValue(float steering, int wheel); |
---|
| 118 | |
---|
| 119 | protected: |
---|
| 120 | VehicleTuning *mTuning; |
---|
| 121 | VehicleRayCaster *mRayCaster; |
---|
| 122 | |
---|
| 123 | std::vector<btWheelInfo *> mWheelsInfo; |
---|
| 124 | std::vector<Ogre::SceneNode *> mWheelNodes; |
---|
| 125 | |
---|
| 126 | WheeledRigidBody* mChassisBody; |
---|
| 127 | Ogre::SceneNode *mNode; |
---|
| 128 | |
---|
| 129 | }; |
---|
| 130 | } |
---|
| 131 | #endif //_OGREBULLETDYNAMICS_RaycastVehicle_H |
---|
| 132 | |
---|