Panda3D

physxActor.h

00001 // Filename: physxActor.h
00002 // Created by:  enn0x (14Sep09)
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 PHYSXACTOR_H
00016 #define PHYSXACTOR_H
00017 
00018 #include "pandabase.h"
00019 #include "nodePath.h"
00020 #include "lmatrix.h"
00021 #include "lvector3.h"
00022 #include "lpoint3.h"
00023 #include "lquaternion.h"
00024 
00025 #include "physxObject.h"
00026 #include "physxObjectCollection.h"
00027 #include "physxEnums.h"
00028 #include "physx_includes.h"
00029 
00030 class PhysxController;
00031 class PhysxScene;
00032 class PhysxShape;
00033 class PhysxShapeDesc;
00034 class PhysxActorDesc;
00035 class PhysxBodyDesc;
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : PhysxActor
00039 // Description : Actors are the main simulation objects. Actors
00040 //               are owned by a scene (PhysxScene).
00041 //
00042 //               An actor may optionally encapsulate a dynamic rigid
00043 //               body by setting the body member of the actor's
00044 //               descriptor when it is created. Otherwise the actor
00045 //               will be static (fixed in the world).
00046 //
00047 //               Instances of PhysxActor are created by calling
00048 //               PhysxScene::create_actor() and destroyed by calling
00049 //               PhysxActor::release().
00050 ////////////////////////////////////////////////////////////////////
00051 class EXPCL_PANDAPHYSX PhysxActor : public PhysxObject, public PhysxEnums {
00052 
00053 PUBLISHED:
00054   INLINE PhysxActor();
00055   INLINE ~PhysxActor();
00056 
00057   bool save_body_to_desc(PhysxBodyDesc &bodyDesc) const;
00058   void save_to_desc(PhysxActorDesc &actorDesc) const;
00059 
00060   void set_name(const char *name);
00061   void set_global_pos(const LPoint3f &pos);
00062   void set_global_mat(const LMatrix4f &mat);
00063   void set_global_hpr(float h, float p, float r);
00064   void set_body_flag(PhysxBodyFlag flag, bool value);
00065   void set_actor_flag(PhysxActorFlag flag, bool value);
00066   void set_contact_report_flag(PhysxContactPairFlag flag, bool value);
00067   void set_contact_report_threshold(float threshold);
00068   void set_group(unsigned int group);
00069   void set_dominance_group(unsigned int group);
00070   void set_shape_group( unsigned int group );
00071 
00072   const char *get_name() const;
00073   LPoint3f get_global_pos() const;
00074   LMatrix4f get_global_mat() const;
00075   LQuaternionf get_global_quat() const;
00076   bool get_body_flag(PhysxBodyFlag flag) const;
00077   bool get_actor_flag(PhysxActorFlag flag) const;
00078   unsigned int get_group() const;
00079   unsigned int get_dominance_group() const;
00080 
00081   bool is_dynamic() const;
00082   float compute_kinetic_energy() const;
00083   bool update_mass_from_shapes(float density, float totalMass);
00084 
00085   PhysxScene *get_scene() const;
00086 
00087   // NodePath
00088   void attach_node_path(const NodePath &np);
00089   void detach_node_path();
00090   NodePath get_node_path() const;
00091 
00092   // Shapes
00093   unsigned int get_num_shapes() const;
00094   PhysxShape *create_shape(PhysxShapeDesc &desc);
00095   PhysxShape *get_shape(unsigned int idx) const;
00096   PhysxShape *get_shape_by_name(const char *name) const;
00097   MAKE_SEQ(get_shapes, get_num_shapes, get_shape);
00098 
00099   // Forces
00100   void add_force(const LVector3f force, 
00101      PhysxForceMode mode=FM_force, bool wakeup=true);
00102   void add_force_at_pos(const LVector3f force, const LPoint3f &pos,
00103      PhysxForceMode mode=FM_force, bool wakeup=true);
00104   void add_force_at_local_pos(const LVector3f force, const LPoint3f &pos,
00105      PhysxForceMode mode=FM_force, bool wakeup=true);
00106   void add_torque(const LVector3f torque,
00107      PhysxForceMode mode=FM_force, bool wakeup=true);
00108   void add_local_force(const LVector3f force,
00109      PhysxForceMode mode=FM_force, bool wakeup=true);
00110   void add_local_force_at_pos(const LVector3f force, const LPoint3f &pos,
00111      PhysxForceMode mode=FM_force, bool wakeup=true);
00112   void add_local_force_at_local_pos(const LVector3f force, const LPoint3f &pos,
00113      PhysxForceMode mode=FM_force, bool wakeup=true);
00114   void add_local_torque(const LVector3f torque,
00115      PhysxForceMode mode=FM_force, bool wakeup=true);
00116 
00117   // Mass manipulation
00118   void set_mass(float mass);
00119   void set_c_mass_offset_local_mat(const LMatrix4f &mat);
00120   void set_c_mass_offset_local_pos(const LPoint3f &pos);
00121   void set_c_mass_offset_local_orientation(const LMatrix3f &mat);
00122   void set_c_mass_offset_global_mat(const LMatrix4f &mat);
00123   void set_c_mass_offset_global_pos(const LPoint3f &pos);
00124   void set_c_mass_offset_global_orientation(const LMatrix3f &mat);
00125   void set_c_mass_global_mat(const LMatrix4f &mat);
00126   void set_c_mass_global_pos(const LPoint3f &pos);
00127   void set_c_mass_global_orientation(const LMatrix3f &mat);
00128   void set_mass_space_inertia_tensor(const LVector3f &m);
00129 
00130   float get_mass() const;
00131   LMatrix4f get_c_mass_global_mat() const;
00132   LPoint3f get_c_mass_global_pos() const;
00133   LMatrix3f get_c_mass_global_orientation() const;
00134   LMatrix4f get_c_mass_local_mat() const;
00135   LPoint3f get_c_mass_local_pos() const;
00136   LMatrix3f get_c_mass_local_orientation() const;
00137   LVector3f get_mass_space_inertia_tensor() const;
00138   LMatrix3f get_global_inertia_tensor() const;
00139   LMatrix3f get_global_inertia_tensor_inverse() const;
00140 
00141   // Damping
00142   void set_linear_damping(float linDamp);
00143   void set_angular_damping(float angDamp);
00144   float get_linear_damping() const;
00145   float get_angular_damping() const;
00146 
00147   // Velocity
00148   void set_linear_velocity(const LVector3f &linVel);
00149   void set_angular_velocity(const LVector3f &angVel);
00150   void set_max_angular_velocity(float maxAngVel);
00151 
00152   LVector3f get_linear_velocity() const;
00153   LVector3f get_angular_velocity() const;
00154   float get_max_angular_velocity() const;
00155 
00156   // Point Velocity 
00157   LVector3f get_point_velocity(const LPoint3f &point) const;
00158   LVector3f get_local_point_velocity(const LPoint3f &point) const; 
00159 
00160   // Momentum
00161   void set_linear_momentum(const LVector3f &momentum);
00162   void set_angular_momentum(const LVector3f &momentum);
00163   LVector3f get_linear_momentum() const;
00164   LVector3f get_angular_momentum() const;
00165 
00166   // Sleeping
00167   void set_sleep_linear_velocity(float threshold);
00168   void set_sleep_angular_velocity(float threshold);
00169   void set_sleep_energy_threshold(float threshold);
00170   float get_sleep_linear_velocity() const;
00171   float get_sleep_angular_velocity() const;
00172   float get_sleep_energy_threshold() const;
00173   bool is_sleeping() const;
00174   void wake_up(float wakeCounterValue=NX_SLEEP_INTERVAL);
00175   void put_to_sleep();
00176 
00177   // Kinematic
00178   void move_global_pos(const LPoint3f &pos);
00179   void move_global_mat(const LMatrix4f &mat);
00180   void move_global_hpr(float h, float p, float r);
00181 
00182   INLINE void ls() const;
00183   INLINE void ls(ostream &out, int indent_level=0) const;
00184 
00185 public:
00186   void update_transform(const LMatrix4f m);
00187 
00188 ////////////////////////////////////////////////////////////////////
00189 PUBLISHED:
00190   void release();
00191 
00192 public:
00193   INLINE NxActor *ptr() const { return _ptr; };
00194 
00195   void link_controller(PhysxController *controller);
00196   void link(NxActor *ptr);
00197   void unlink();
00198 
00199   PhysxObjectCollection<PhysxShape> _shapes;
00200 
00201 private:
00202   NxActor *_ptr;
00203   NodePath _np;
00204   PT(PhysxController) _controller;
00205   string _name;
00206 
00207 ////////////////////////////////////////////////////////////////////
00208 public:
00209   static TypeHandle get_class_type() {
00210     return _type_handle;
00211   }
00212   static void init_type() {
00213     PhysxObject::init_type();
00214     register_type(_type_handle, "PhysxActor", 
00215                   PhysxObject::get_class_type());
00216   }
00217   virtual TypeHandle get_type() const {
00218     return get_class_type();
00219   }
00220   virtual TypeHandle force_init_type() {
00221     init_type();
00222     return get_class_type();
00223   }
00224 
00225 private:
00226   static TypeHandle _type_handle;
00227 };
00228 
00229 #include "physxActor.I"
00230 
00231 #endif // PHYSXACTOR_H
 All Classes Functions Variables Enumerations