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