Panda3D
|
00001 // Filename: physxUtilLib.h 00002 // Created by: enn0x (01Nov09) 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 PHYSXUTILLIB_H 00016 #define PHYSXUTILLIB_H 00017 00018 #include "pandabase.h" 00019 #include "luse.h" 00020 00021 #include "config_physx.h" 00022 00023 class PhysxBounds3; 00024 class PhysxBox; 00025 class PhysxCapsule; 00026 class PhysxPlane; 00027 class PhysxRay; 00028 class PhysxSegment; 00029 class PhysxSphere; 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : PhysxUtilLib 00033 // Description : 00034 //////////////////////////////////////////////////////////////////// 00035 class EXPCL_PANDAPHYSX PhysxUtilLib { 00036 00037 PUBLISHED: 00038 INLINE PhysxUtilLib(); 00039 INLINE ~PhysxUtilLib(); 00040 00041 bool box_contains_point(const PhysxBox &box, const LPoint3f &p); 00042 PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat); 00043 LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index); 00044 PhysxCapsule compute_capsule_around_box(const PhysxBox &box); 00045 bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b); 00046 PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule); 00047 void set_fpu_exceptions(bool b); 00048 void set_fpu_precision24(); 00049 void set_fpu_precision53(); 00050 void set_fpu_precision64(); 00051 void set_fpu_rounding_chop(); 00052 void set_fpu_rounding_down(); 00053 void set_fpu_rounding_near(); 00054 void set_fpu_rounding_up(); 00055 int int_ceil(const float &f); 00056 int int_chop(const float &f); 00057 int int_floor(const float &f); 00058 float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point); 00059 float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point); 00060 PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1); 00061 void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2); 00062 LMatrix3f find_rotation_matrix(const LVector3f &x, const LVector3f &b); 00063 float compute_sphere_mass(float radius, float density); 00064 float compute_sphere_density(float radius, float mass); 00065 float compute_box_mass(const LVector3f &extents, float density); 00066 float compute_box_density(const LVector3f &extents, float mass); 00067 float compute_ellipsoid_mass(const LVector3f &extents, float density); 00068 float compute_ellipsoid_density(const LVector3f &extents, float mass); 00069 float compute_cylinder_mass(float radius, float length, float density); 00070 float compute_cylinder_density(float radius, float length, float mass); 00071 float compute_cone_mass(float radius, float length, float density); 00072 float compute_cone_density(float radius, float length, float mass); 00073 LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength); 00074 LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow); 00075 bool box_box_intersect(const LVector3f &extents0, const LPoint3f ¢er0, const LMatrix3f &rotation0, const LVector3f &extents1, const LPoint3f ¢er1, const LMatrix3f &rotation1, bool full_test); 00076 bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f ¢er, const LVector3f &extents); 00077 bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane); 00078 bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f ¢er, float radius, LPoint3f &hit_pos); 00079 bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept); 00080 bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord); 00081 bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot); 00082 bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max); 00083 bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot); 00084 unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule); 00085 bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1); 00086 bool ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull); 00087 bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal); 00088 bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal); 00089 bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); 00090 bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); 00091 bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal); 00092 float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot, LPoint3f ¶ms); 00093 00094 public: 00095 NxUtilLib *_ptr; 00096 }; 00097 00098 #include "physxUtilLib.I" 00099 00100 #endif // PHYSUTILLIB_H 00101 00102 /* 00103 NOT WRAPPED: 00104 bool NxComputeBoxPlanes(const NxBox &box, NxPlane *planes) 00105 bool NxComputeBoxPoints(const NxBox &box, NxVec3 *pts) 00106 bool NxComputeBoxVertexNormals(const NxBox &box, NxVec3 *pts) 00107 const NxU32 *NxGetBoxEdges() 00108 const NxI32 *NxGetBoxEdgesAxes() 00109 const NxU32 *NxGetBoxTriangles() 00110 const NxVec3 *NxGetBoxLocalEdgeNormals() 00111 const NxU32 *NxGetBoxQuads() 00112 const NxU32 *NxBoxVertexToQuad(NxU32 vertexIndex) 00113 NxBSphereMethod NxComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts) 00114 bool NxFastComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts) 00115 bool NxDiagonalizeInertiaTensor(const NxMat33 &denseInertia, NxVec3 &diagonalInertia, NxMat33 &rotation) 00116 void NxComputeBounds(NxVec3 &min, NxVec3 &max, NxU32 nbVerts, const NxVec3 *verts) 00117 NxU32 NxCrc32(const void *buffer, NxU32 nbBytes) 00118 NxSepAxis NxSeparatingAxis(const NxVec3 &extents0, const NxVec3 ¢er0, const NxMat33 &rotation0, const NxVec3 &extents1, const NxVec3 ¢er1, const NxMat33 &rotation1, bool fullTest=true) 00119 void NxSegmentPlaneIntersect(const NxVec3 &v1, const NxVec3 &v2, const NxPlane &plane, NxReal &dist, NxVec3 &pointOnPlane) 00120 NxU32 NxRayAABBIntersect2(const NxVec3 &min, const NxVec3 &max, const NxVec3 &origin, const NxVec3 &dir, NxVec3 &coord, NxReal &t) 00121 bool NxBuildSmoothNormals(NxU32 nbTris, NxU32 nbVerts, const NxVec3 *verts, const NxU32 *dFaces, const NxU16 *wFaces, NxVec3 *normals, bool flip=false) 00122 bool NxSweepBoxTriangles(NxU32 nb_tris, const NxTriangle *triangles, const NxTriangle *edge_triangles, const NxU32 *edge_flags, const NxBounds3 &box, const NxVec3 &dir, float length, NxVec3 &hit, NxVec3 &normal, float &d, NxU32 &index, NxU32 *cachedIndex=NULL) 00123 bool NxSweepCapsuleTriangles(NxU32 up_direction, NxU32 nb_tris, const NxTriangle *triangles, const NxU32 *edge_flags, const NxVec3 ¢er, const float radius, const float height, const NxVec3 &dir, float length, NxVec3 &hit, NxVec3 &normal, float &d, NxU32 &index, NxU32 *cachedIndex=NULL) 00124 float NxSegmentOBBSqrDist(const NxSegment &segment, const NxVec3 &c0, const NxVec3 &e0, const NxMat33 &r0, float *t, NxVec3 *p) 00125 */