Panda3D

physxScene.h

00001 // Filename: physxScene.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 PHYSXSCENE_H
00016 #define PHYSXSCENE_H
00017 
00018 #include "pandabase.h"
00019 #include "luse.h"
00020 
00021 #include "physxObject.h"
00022 #include "physxObjectCollection.h"
00023 #include "physxEnums.h"
00024 #include "physxContactReport.h"
00025 #include "physxControllerReport.h"
00026 #include "physxTriggerReport.h"
00027 #include "physxOverlapReport.h"
00028 #include "physxMask.h"
00029 #include "physxGroupsMask.h"
00030 #include "physx_includes.h"
00031 
00032 class PhysxActor;
00033 class PhysxActorDesc;
00034 class PhysxController;
00035 class PhysxControllerDesc;
00036 class PhysxConstraintDominance;
00037 class PhysxDebugGeomNode;
00038 class PhysxForceField;
00039 class PhysxForceFieldDesc;
00040 class PhysxForceFieldShapeGroup;
00041 class PhysxForceFieldShapeGroupDesc;
00042 class PhysxJoint;
00043 class PhysxJointDesc;
00044 class PhysxMaterial;
00045 class PhysxMaterialDesc;
00046 class PhysxOverlapReport;
00047 class PhysxRay;
00048 class PhysxRaycastHit;
00049 class PhysxRaycastReport;
00050 class PhysxSceneStats2;
00051 class PhysxVehicle;
00052 class PhysxVehicleDesc;
00053 class PhysxCloth;
00054 class PhysxClothDesc;
00055 class PhysxSoftBody;
00056 class PhysxSoftBodyDesc;
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //       Class : PhysxScene
00060 // Description : A scene is a collection of bodies, constraints,
00061 //               and effectors which can interact.
00062 //
00063 //               The scene simulates the behavior of these objects
00064 //               over time. Several scenes may exist at the same
00065 //               time, but each body, constraint, or effector object
00066 //               is specific to a scene -- they may not be shared.
00067 //
00068 //               For example, attempting to create a joint in one
00069 //               scene and then using it to attach bodies from a
00070 //               different scene results in undefined behavior.
00071 ////////////////////////////////////////////////////////////////////
00072 class EXPCL_PANDAPHYSX PhysxScene : public PhysxObject, public PhysxEnums {
00073 
00074 PUBLISHED:
00075   INLINE PhysxScene();
00076   INLINE ~PhysxScene();
00077 
00078   void simulate(float dt);
00079   void fetch_results();
00080   void set_timing_variable();
00081   void set_timing_fixed(float maxTimestep=1.0f/60.0f, unsigned int maxIter=8);
00082 
00083   PhysxDebugGeomNode *get_debug_geom_node();
00084 
00085   void enable_contact_reporting(bool enabled);
00086   bool is_contact_reporting_enabled() const;
00087   void enable_trigger_reporting(bool enabled);
00088   bool is_trigger_reporting_enabled() const;
00089   void enable_controller_reporting(bool enabled);
00090   bool is_controller_reporting_enabled() const;
00091 
00092   void set_gravity(const LVector3f &gravity);
00093 
00094   LVector3f get_gravity() const;
00095   PhysxSceneStats2 get_stats2() const;
00096   bool get_flag(PhysxSceneFlag flag) const; 
00097   bool is_hardware_scene() const;
00098 
00099   // Actors
00100   unsigned int get_num_actors() const;
00101   PhysxActor *create_actor(PhysxActorDesc &desc);
00102   PhysxActor *get_actor(unsigned int idx) const;
00103   MAKE_SEQ(get_actors, get_num_actors, get_actor);
00104 
00105   // Joints
00106   unsigned int get_num_joints() const;
00107   PhysxJoint *create_joint(PhysxJointDesc &desc);
00108   PhysxJoint *get_joint(unsigned int idx) const;
00109   MAKE_SEQ(get_joints, get_num_joints, get_joint);
00110 
00111   // Materials
00112   unsigned int get_num_materials() const;
00113   unsigned int get_hightest_material_index() const;
00114   PhysxMaterial *create_material(PhysxMaterialDesc &desc);
00115   PhysxMaterial *create_material();
00116   PhysxMaterial *get_material(unsigned int idx) const;
00117   PhysxMaterial *get_material_from_index(unsigned int idx) const;
00118   MAKE_SEQ(get_materials, get_num_materials, get_material);
00119 
00120   // Controllers
00121   unsigned int get_num_controllers() const;
00122   PhysxController *create_controller(PhysxControllerDesc &controllerDesc);
00123   PhysxController *get_controller(unsigned int idx) const;
00124   MAKE_SEQ(get_controllers, get_num_controllers, get_controller);
00125 
00126   // Force fields
00127   unsigned int get_num_force_fields() const;
00128   PhysxForceField *create_force_field(PhysxForceFieldDesc &desc);
00129   PhysxForceField *get_force_field(unsigned int idx) const;
00130   MAKE_SEQ(get_force_fields, get_num_force_fields, get_force_field);
00131 
00132   // Force field shape groups
00133   unsigned int get_num_force_field_shape_groups() const;
00134   PhysxForceFieldShapeGroup *create_force_field_shape_group(PhysxForceFieldShapeGroupDesc &desc);
00135   PhysxForceFieldShapeGroup *get_force_field_shape_group(unsigned int idx) const;
00136   MAKE_SEQ(get_force_field_shape_groups, get_num_force_field_shape_groups, get_force_field_shape_group);
00137 
00138   // Cloths
00139   unsigned int get_num_cloths() const;
00140   PhysxCloth *create_cloth(PhysxClothDesc &desc);
00141   PhysxCloth *get_cloth(unsigned int idx) const;
00142   MAKE_SEQ(get_cloths, get_num_cloths, get_cloth);
00143 
00144   // Soft bodies
00145   unsigned int get_num_soft_bodies() const;
00146   PhysxSoftBody *create_soft_body(PhysxSoftBodyDesc &desc);
00147   PhysxSoftBody *get_soft_body(unsigned int idx) const;
00148   MAKE_SEQ(get_soft_bodies, get_num_soft_bodies, get_soft_body);
00149 
00150   // Vehicles
00151   unsigned int get_num_vehicles() const;
00152   PhysxVehicle *create_vehicle(PhysxVehicleDesc &desc);
00153   PhysxVehicle *get_vehicle(unsigned int idx) const;
00154   MAKE_SEQ(get_vehicles, get_num_vehicles, get_vehicle);
00155 
00156   // Raycast queries
00157   bool raycast_any_shape(const PhysxRay &ray,
00158     PhysxShapesType shapesType=ST_all,
00159     PhysxMask mask=PhysxMask::all_on(),
00160     PhysxGroupsMask *groups=NULL) const;
00161 
00162   PhysxRaycastHit raycast_closest_shape(const PhysxRay &ray,
00163     PhysxShapesType shapesType=ST_all,
00164     PhysxMask mask=PhysxMask::all_on(),
00165     PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
00166 
00167   PhysxRaycastReport raycast_all_shapes(const PhysxRay &ray,
00168     PhysxShapesType shapesType=ST_all,
00169     PhysxMask mask=PhysxMask::all_on(),
00170     PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
00171 
00172   bool raycast_any_bounds(const PhysxRay &ray,
00173     PhysxShapesType shapesType=ST_all,
00174     PhysxMask mask=PhysxMask::all_on(),
00175     PhysxGroupsMask *groups=NULL) const;
00176 
00177   PhysxRaycastHit raycast_closest_bounds(const PhysxRay &ray,
00178     PhysxShapesType shapesType=ST_all,
00179     PhysxMask mask=PhysxMask::all_on(),
00180     PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
00181 
00182   PhysxRaycastReport raycast_all_bounds(const PhysxRay &ray,
00183     PhysxShapesType shapesType=ST_all,
00184     PhysxMask mask=PhysxMask::all_on(),
00185     PhysxGroupsMask *groups=NULL, bool smoothNormal=true) const;
00186 
00187   // Overlap queries
00188   PhysxOverlapReport overlap_sphere_shapes(const LPoint3f &center, float radius,
00189     PhysxShapesType shapesType=ST_all,
00190     PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
00191 
00192   PhysxOverlapReport overlap_capsule_shapes(const LPoint3f &p0, const LPoint3f &p1, float radius,
00193     PhysxShapesType shapesType=ST_all,
00194     PhysxMask mask=PhysxMask::all_on(), bool accurateCollision=true) const;
00195 
00196   // Filters
00197   void set_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag, bool value);
00198   void set_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB, bool value);
00199   void set_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag, bool value);
00200   void set_group_collision_flag(unsigned int g1, unsigned int g2, bool enable);
00201   void set_filter_ops(PhysxFilterOp op0, PhysxFilterOp op1, PhysxFilterOp op2);
00202   void set_filter_bool(bool flag);
00203   void set_filter_constant0(const PhysxGroupsMask &mask);
00204   void set_filter_constant1(const PhysxGroupsMask &mask);
00205   void set_dominance_group_pair(unsigned int g1, unsigned int g2, PhysxConstraintDominance dominance);
00206 
00207   bool get_actor_pair_flag(PhysxActor &actorA, PhysxActor &actorB, PhysxContactPairFlag flag);
00208   bool get_shape_pair_flag(PhysxShape &shapeA, PhysxShape &shapeB);
00209   bool get_actor_group_pair_flag(unsigned int g1, unsigned int g2, PhysxContactPairFlag flag);
00210   bool get_group_collision_flag(unsigned int g1, unsigned int g2);
00211   bool get_filter_bool() const;
00212   PhysxGroupsMask get_filter_constant0() const;
00213   PhysxGroupsMask get_filter_constant1() const;
00214   PhysxFilterOp get_filter_op0() const;
00215   PhysxFilterOp get_filter_op1() const;
00216   PhysxFilterOp get_filter_op2() const;
00217   PhysxConstraintDominance get_dominance_group_pair(unsigned int g1, unsigned int g2);
00218 
00219 ////////////////////////////////////////////////////////////////////
00220 PUBLISHED:
00221   void release();
00222 
00223   INLINE void ls() const;
00224   INLINE void ls(ostream &out, int indent_level=0) const;
00225 
00226 public:
00227   INLINE NxScene *ptr() const { return _ptr; };
00228   INLINE NxControllerManager *cm() const { return _cm; };
00229 
00230   void link(NxScene *ptr);
00231   void unlink();
00232 
00233   PhysxObjectCollection<PhysxMaterial> _materials;
00234   PhysxObjectCollection<PhysxActor> _actors;
00235   PhysxObjectCollection<PhysxJoint> _joints;
00236   PhysxObjectCollection<PhysxForceField> _forcefields;
00237   PhysxObjectCollection<PhysxForceFieldShapeGroup> _ffgroups;
00238   PhysxObjectCollection<PhysxController> _controllers;
00239   PhysxObjectCollection<PhysxVehicle> _vehicles;
00240   PhysxObjectCollection<PhysxCloth> _cloths;
00241   PhysxObjectCollection<PhysxSoftBody> _softbodies;
00242 
00243   PhysxMaterial *get_wheel_shape_material();
00244 
00245 private:
00246   NxScene *_ptr;
00247   NxControllerManager *_cm;
00248   PT(PhysxDebugGeomNode) _debugNode;
00249   PT(PhysxMaterial) _wheelShapeMaterial;
00250 
00251   PhysxContactReport _contact_report;
00252   PhysxControllerReport _controller_report;
00253   PhysxTriggerReport _trigger_report;
00254 
00255   static PStatCollector _pcollector_fetch_results;
00256   static PStatCollector _pcollector_update_transforms;
00257   static PStatCollector _pcollector_debug_renderer;
00258   static PStatCollector _pcollector_simulate;
00259   static PStatCollector _pcollector_cloth;
00260   static PStatCollector _pcollector_softbody;
00261 
00262 ////////////////////////////////////////////////////////////////////
00263 public:
00264   static TypeHandle get_class_type() {
00265     return _type_handle;
00266   }
00267   static void init_type() {
00268     PhysxObject::init_type();
00269     register_type(_type_handle, "PhysxScene", 
00270                   PhysxObject::get_class_type());
00271   }
00272   virtual TypeHandle get_type() const {
00273     return get_class_type();
00274   }
00275   virtual TypeHandle force_init_type() {
00276     init_type();
00277     return get_class_type();
00278   }
00279 
00280 private:
00281   static TypeHandle _type_handle;
00282 };
00283 
00284 #include "physxScene.I"
00285 
00286 #endif // PHYSXSCENE_H
 All Classes Functions Variables Enumerations