Panda3D
 All Classes Functions Variables Enumerations
physxManager.h
00001 // Filename: physxManager.h
00002 // Created by:  enn0x (01Sep09)
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 PHYSXMANAGER_H
00016 #define PHYSXMANAGER_H
00017 
00018 #include "pandabase.h"
00019 #include "pointerTo.h"
00020 #include "luse.h"
00021 
00022 #include "physxEnums.h"
00023 #include "physxObjectCollection.h"
00024 #include "physx_includes.h"
00025 
00026 class PhysxScene;
00027 class PhysxSceneDesc;
00028 class PhysxHeightField;
00029 class PhysxHeightFieldDesc;
00030 class PhysxTriangleMesh;
00031 class PhysxConvexMesh;
00032 class PhysxClothMesh;
00033 class PhysxSoftBodyMesh;
00034 class PhysxOutputStream;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : PhysxManager
00038 // Description : The central interface to the PhysX subsystem.
00039 //               Used e. g. for setting/retrieving global parameters
00040 //               or for creating scenes.
00041 ////////////////////////////////////////////////////////////////////
00042 class EXPCL_PANDAPHYSX PhysxManager : public PhysxEnums {
00043 
00044 protected:
00045   PhysxManager();
00046 
00047 public:
00048   ~PhysxManager();
00049 
00050 PUBLISHED:
00051   static PhysxManager *get_global_ptr();
00052 
00053   void set_parameter(PhysxParameter param, float value);
00054   float get_parameter(PhysxParameter param);
00055 
00056   bool is_hardware_available();
00057   unsigned int get_num_ppus();
00058   unsigned int get_hw_version();
00059   const char *get_internal_version();
00060 
00061   unsigned int get_num_scenes() const;
00062   PhysxScene *create_scene(PhysxSceneDesc &desc);
00063   PhysxScene *get_scene(unsigned int idx) const;
00064   MAKE_SEQ(get_scenes, get_num_scenes, get_scene);
00065 
00066   unsigned int get_num_height_fields();
00067   PhysxHeightField *create_height_field(PhysxHeightFieldDesc &desc);
00068   PhysxHeightField *get_height_field(unsigned int idx);
00069   MAKE_SEQ(get_height_fields, get_num_height_fields, get_height_field);
00070 
00071   unsigned int get_num_convex_meshes();
00072   PhysxConvexMesh *get_convex_mesh(unsigned int idx);
00073   MAKE_SEQ(get_convex_meshes, get_num_convex_meshes, get_convex_mesh);
00074 
00075   unsigned int get_num_triangle_meshes();
00076   PhysxTriangleMesh *get_triangle_mesh(unsigned int idx);
00077   MAKE_SEQ(get_triangle_meshes, get_num_triangle_meshes, get_triangle_mesh);
00078 
00079   unsigned int get_num_cloth_meshes();
00080   PhysxClothMesh *get_cloth_mesh(unsigned int idx);
00081   MAKE_SEQ(get_cloth_meshes, get_num_cloth_meshes, get_cloth_mesh);
00082 
00083   unsigned int get_num_soft_body_meshes();
00084   PhysxSoftBodyMesh *get_soft_body_mesh(unsigned int idx);
00085   MAKE_SEQ(get_soft_body_meshes, get_num_soft_body_meshes, get_soft_body_mesh);
00086 
00087   INLINE void ls() const;
00088   INLINE void ls(ostream &out, int indent_level=0) const;
00089 
00090 public:
00091   INLINE NxPhysicsSDK *get_sdk() const;
00092 
00093   PhysxObjectCollection<PhysxScene> _scenes;
00094   PhysxObjectCollection<PhysxHeightField> _heightfields;
00095   PhysxObjectCollection<PhysxConvexMesh> _convex_meshes;
00096   PhysxObjectCollection<PhysxTriangleMesh> _triangle_meshes;
00097   PhysxObjectCollection<PhysxClothMesh> _cloth_meshes;
00098   PhysxObjectCollection<PhysxSoftBodyMesh> _softbody_meshes;
00099 
00100   INLINE static NxVec3 vec3_to_nxVec3(const LVector3f &v);
00101   INLINE static LVector3f nxVec3_to_vec3(const NxVec3 &v);
00102   INLINE static NxExtendedVec3 vec3_to_nxExtVec3(const LVector3f &v);
00103   INLINE static LVector3f nxExtVec3_to_vec3(const NxExtendedVec3 &v);
00104   INLINE static NxVec3 point3_to_nxVec3(const LPoint3f &p);
00105   INLINE static LPoint3f nxVec3_to_point3(const NxVec3 &p);
00106   INLINE static NxExtendedVec3 point3_to_nxExtVec3(const LPoint3f &p);
00107   INLINE static LPoint3f nxExtVec3_to_point3(const NxExtendedVec3 &p);
00108   INLINE static NxQuat quat_to_nxQuat(const LQuaternionf &q);
00109   INLINE static LQuaternionf nxQuat_to_quat(const NxQuat &q);
00110   INLINE static NxMat34 mat4_to_nxMat34(const LMatrix4f &m);
00111   INLINE static LMatrix4f nxMat34_to_mat4(const NxMat34 &m);
00112   INLINE static NxMat33 mat3_to_nxMat33(const LMatrix3f &m);
00113   INLINE static LMatrix3f nxMat33_to_mat3(const NxMat33 &m);
00114 
00115   INLINE static void update_vec3_from_nxVec3(LVector3f &v, const NxVec3 &nVec);
00116   INLINE static void update_point3_from_nxVec3(LPoint3f &p, const NxVec3 &nVec);
00117 
00118 private:
00119   NxPhysicsSDK *_sdk;
00120 
00121   static PhysxManager *_global_ptr;
00122 
00123   class PhysxOutputStream : public NxUserOutputStream {
00124     void reportError(NxErrorCode code, const char *message, const char *file, int line);
00125     NxAssertResponse reportAssertViolation(const char *message, const char *file, int line);
00126     void print(const char *message);
00127     const char *get_error_code_string(NxErrorCode code);
00128   };
00129   static PhysxOutputStream _outputStream;
00130 
00131   static const char *get_sdk_error_string(const NxSDKCreateError &error);
00132 };
00133 
00134 #include "physxManager.I"
00135 
00136 #endif // PHYSXMANAGER_H
 All Classes Functions Variables Enumerations