Panda3D

physxController.h

00001 // Filename: physxController.h
00002 // Created by:  enn0x (24Sep09)
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 PHYSXCONTROLLER_H
00016 #define PHYSXCONTROLLER_H
00017 
00018 #include "pandabase.h"
00019 #include "pointerTo.h"
00020 #include "lpoint3.h"
00021 #include "lmatrix.h"
00022 #include "lquaternion.h"
00023 
00024 #include "physxObject.h"
00025 #include "physxEnums.h"
00026 #include "physx_includes.h"
00027 
00028 class PhysxActor;
00029 
00030 ////////////////////////////////////////////////////////////////////
00031 //       Class : PhysxController
00032 // Description : Abstract base class for character controllers.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDAPHYSX PhysxController : public PhysxObject, public PhysxEnums {
00035 
00036 PUBLISHED:
00037   void release();
00038 
00039   PhysxActor *get_actor() const;
00040 
00041   void set_pos(const LPoint3f &pos);
00042   void set_sharpness(float sharpness);
00043   void set_collision(bool enable);
00044   void set_min_distance(float min_dist);
00045   void set_step_offset(float offset);
00046 
00047   LPoint3f get_pos() const;
00048   float get_sharpness() const;
00049 
00050   void set_global_speed(const LVector3f &speed);
00051   void set_local_speed(const LVector3f &speed);
00052   void set_omega(float omega);
00053   void set_h(float heading);
00054   float get_h() const;
00055 
00056   void report_scene_changed();
00057   void start_jump(float v0);
00058   void stop_jump();
00059 
00060   INLINE void ls() const;
00061   INLINE void ls(ostream &out, int indent_level=0) const;
00062 
00063 public:
00064   void update_controller(float dt);
00065 
00066   static PhysxController *factory(NxControllerType shapeType);
00067 
00068   virtual NxController *ptr() const = 0;
00069 
00070   virtual void link(NxController *controllerPtr) = 0;
00071   virtual void unlink() = 0;
00072 
00073 protected:
00074   INLINE PhysxController();
00075 
00076 private:
00077   NxReal get_jump_height(float dt, NxVec3 &gravity);
00078 
00079   float _sharpness;
00080   float _min_dist;
00081 
00082   bool  _jumping;
00083   float _jump_time;
00084   float _jump_v0;
00085 
00086   float _omega;
00087   float _heading;
00088   NxVec3 _speed;
00089 
00090   NxVec3 _up_vector;
00091   NxQuat _up_quat;
00092   NxQuat _up_quat_inv;
00093   NxHeightFieldAxis _up_axis;
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 public:
00097   static TypeHandle get_class_type() {
00098     return _type_handle;
00099   }
00100   static void init_type() {
00101     PhysxObject::init_type();
00102     register_type(_type_handle, "PhysxController", 
00103                   PhysxObject::get_class_type());
00104   }
00105   virtual TypeHandle get_type() const {
00106     return get_class_type();
00107   }
00108   virtual TypeHandle force_init_type() {
00109     init_type();
00110     return get_class_type();
00111   }
00112 
00113 private:
00114   static TypeHandle _type_handle;
00115 };
00116 
00117 #include "physxController.I"
00118 
00119 #endif // PHYSXCONTROLLER_H
 All Classes Functions Variables Enumerations