Panda3D
 All Classes Functions Variables Enumerations
bulletVehicle.h
00001 // Filename: bulletVehicle.h
00002 // Created by:  enn0x (16Feb10)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef __BULLET_VEHICLE_H__
00016 #define __BULLET_VEHICLE_H__
00017 
00018 #include "pandabase.h"
00019 
00020 #include "bullet_includes.h"
00021 #include "bullet_utils.h"
00022 
00023 #include "typedReferenceCount.h"
00024 #include "luse.h"
00025 
00026 class BulletWorld;
00027 class BulletRigidBodyNode;
00028 class BulletWheel;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : BulletVehicleTuning
00032 // Description : Simulates a raycast vehicle which casts a ray per
00033 //               wheel at the ground as a cheap replacement for
00034 //               complex suspension simulation. The suspension can
00035 //               be tuned in various ways. It is possible to add a
00036 //               (probably) arbitrary number of wheels.
00037 ////////////////////////////////////////////////////////////////////
00038 class BulletVehicleTuning {
00039 
00040 PUBLISHED:
00041   INLINE void set_suspension_stiffness(PN_stdfloat value);
00042   INLINE void set_suspension_compression(PN_stdfloat value);
00043   INLINE void set_suspension_damping(PN_stdfloat value);
00044   INLINE void set_max_suspension_travel_cm(PN_stdfloat value);
00045   INLINE void set_friction_slip(PN_stdfloat value);
00046   INLINE void set_max_suspension_force(PN_stdfloat value);
00047 
00048   INLINE PN_stdfloat get_suspension_stiffness() const;
00049   INLINE PN_stdfloat get_suspension_compression() const;
00050   INLINE PN_stdfloat get_suspension_damping() const;
00051   INLINE PN_stdfloat get_max_suspension_travel_cm() const;
00052   INLINE PN_stdfloat get_friction_slip() const;
00053   INLINE PN_stdfloat get_max_suspension_force() const;
00054 
00055 private:
00056   btRaycastVehicle::btVehicleTuning _;
00057 
00058   friend class BulletVehicle;
00059 };
00060 
00061 ////////////////////////////////////////////////////////////////////
00062 //       Class : BulletVehicle
00063 // Description : 
00064 ////////////////////////////////////////////////////////////////////
00065 class EXPCL_PANDABULLET BulletVehicle : public TypedReferenceCount {
00066 
00067 PUBLISHED:
00068   BulletVehicle(BulletWorld *world, BulletRigidBodyNode *chassis);
00069   INLINE ~BulletVehicle();
00070 
00071   void set_coordinate_system(BulletUpAxis up);
00072   void set_steering_value(PN_stdfloat steering, int idx);
00073   void set_brake(PN_stdfloat brake, int idx);
00074   void set_pitch_control(PN_stdfloat pitch);
00075 
00076   BulletRigidBodyNode *get_chassis();
00077   PN_stdfloat get_current_speed_km_hour() const;
00078   PN_stdfloat get_steering_value(int idx) const;
00079   LVector3 get_forward_vector() const;
00080 
00081   void reset_suspension();
00082   void apply_engine_force(PN_stdfloat force, int idx);
00083 
00084   // Wheels
00085   BulletWheel create_wheel();
00086 
00087   INLINE int get_num_wheels() const;
00088   BulletWheel get_wheel(int idx) const;
00089   MAKE_SEQ(get_wheels, get_num_wheels, get_wheel);
00090 
00091   // Tuning
00092   INLINE BulletVehicleTuning &get_tuning();
00093 
00094 public:
00095   INLINE btRaycastVehicle *get_vehicle() const;
00096 
00097   void sync_b2p();
00098 
00099 private:
00100   btRaycastVehicle *_vehicle;
00101   btVehicleRaycaster *_raycaster;
00102 
00103   BulletVehicleTuning _tuning;
00104 
00105   static btVector3 get_axis(int idx);
00106 
00107 ////////////////////////////////////////////////////////////////////
00108 public:
00109   static TypeHandle get_class_type() {
00110     return _type_handle;
00111   }
00112   static void init_type() {
00113     TypedReferenceCount::init_type();
00114     register_type(_type_handle, "BulletVehicle", 
00115                   TypedReferenceCount::get_class_type());
00116   }
00117   virtual TypeHandle get_type() const {
00118     return get_class_type();
00119   }
00120   virtual TypeHandle force_init_type() {
00121     init_type();
00122     return get_class_type();
00123   }
00124 
00125 private:
00126   static TypeHandle _type_handle;
00127 };
00128 
00129 #include "bulletVehicle.I"
00130 
00131 #endif // __BULLET_VEHICLE_H__
 All Classes Functions Variables Enumerations