Panda3D
physxUtilLib.h
1 // Filename: physxUtilLib.h
2 // Created by: enn0x (01Nov09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PHYSXUTILLIB_H
16 #define PHYSXUTILLIB_H
17 
18 #include "pandabase.h"
19 #include "luse.h"
20 
21 #include "config_physx.h"
22 
23 class PhysxBounds3;
24 class PhysxBox;
25 class PhysxCapsule;
26 class PhysxPlane;
27 class PhysxRay;
28 class PhysxSegment;
29 class PhysxSphere;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : PhysxUtilLib
33 // Description :
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDAPHYSX PhysxUtilLib {
36 
37 PUBLISHED:
38  INLINE PhysxUtilLib();
39  INLINE ~PhysxUtilLib();
40 
41  bool box_contains_point(const PhysxBox &box, const LPoint3f &p);
42  PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat);
43  LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index);
44  PhysxCapsule compute_capsule_around_box(const PhysxBox &box);
45  bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b);
46  PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule);
47  void set_fpu_exceptions(bool b);
48  void set_fpu_precision24();
49  void set_fpu_precision53();
50  void set_fpu_precision64();
51  void set_fpu_rounding_chop();
52  void set_fpu_rounding_down();
53  void set_fpu_rounding_near();
54  void set_fpu_rounding_up();
55  int int_ceil(const float &f);
56  int int_chop(const float &f);
57  int int_floor(const float &f);
58  float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point);
59  float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point);
60  PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1);
61  void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2);
62  LMatrix3f find_rotation_matrix(const LVector3f &x, const LVector3f &b);
63  float compute_sphere_mass(float radius, float density);
64  float compute_sphere_density(float radius, float mass);
65  float compute_box_mass(const LVector3f &extents, float density);
66  float compute_box_density(const LVector3f &extents, float mass);
67  float compute_ellipsoid_mass(const LVector3f &extents, float density);
68  float compute_ellipsoid_density(const LVector3f &extents, float mass);
69  float compute_cylinder_mass(float radius, float length, float density);
70  float compute_cylinder_density(float radius, float length, float mass);
71  float compute_cone_mass(float radius, float length, float density);
72  float compute_cone_density(float radius, float length, float mass);
73  LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength);
74  LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow);
75  bool box_box_intersect(const LVector3f &extents0, const LPoint3f &center0, const LMatrix3f &rotation0, const LVector3f &extents1, const LPoint3f &center1, const LMatrix3f &rotation1, bool full_test);
76  bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f &center, const LVector3f &extents);
77  bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane);
78  bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f &center, float radius, LPoint3f &hit_pos);
79  bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept);
80  bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord);
81  bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot);
82  bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max);
83  bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot);
84  unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule);
85  bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1);
86  bool ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull);
87  bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal);
88  bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal);
89  bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
90  bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
91  bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
92  float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot, LPoint3f &params);
93 
94 public:
95  NxUtilLib *_ptr;
96 };
97 
98 #include "physxUtilLib.I"
99 
100 #endif // PHYSUTILLIB_H
101 
102 /*
103 NOT WRAPPED:
104 bool NxComputeBoxPlanes(const NxBox &box, NxPlane *planes)
105 bool NxComputeBoxPoints(const NxBox &box, NxVec3 *pts)
106 bool NxComputeBoxVertexNormals(const NxBox &box, NxVec3 *pts)
107 const NxU32 *NxGetBoxEdges()
108 const NxI32 *NxGetBoxEdgesAxes()
109 const NxU32 *NxGetBoxTriangles()
110 const NxVec3 *NxGetBoxLocalEdgeNormals()
111 const NxU32 *NxGetBoxQuads()
112 const NxU32 *NxBoxVertexToQuad(NxU32 vertexIndex)
113 NxBSphereMethod NxComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
114 bool NxFastComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
115 bool NxDiagonalizeInertiaTensor(const NxMat33 &denseInertia, NxVec3 &diagonalInertia, NxMat33 &rotation)
116 void NxComputeBounds(NxVec3 &min, NxVec3 &max, NxU32 nbVerts, const NxVec3 *verts)
117 NxU32 NxCrc32(const void *buffer, NxU32 nbBytes)
118 NxSepAxis NxSeparatingAxis(const NxVec3 &extents0, const NxVec3 &center0, const NxMat33 &rotation0, const NxVec3 &extents1, const NxVec3 &center1, const NxMat33 &rotation1, bool fullTest=true)
119 void NxSegmentPlaneIntersect(const NxVec3 &v1, const NxVec3 &v2, const NxPlane &plane, NxReal &dist, NxVec3 &pointOnPlane)
120 NxU32 NxRayAABBIntersect2(const NxVec3 &min, const NxVec3 &max, const NxVec3 &origin, const NxVec3 &dir, NxVec3 &coord, NxReal &t)
121 bool NxBuildSmoothNormals(NxU32 nbTris, NxU32 nbVerts, const NxVec3 *verts, const NxU32 *dFaces, const NxU16 *wFaces, NxVec3 *normals, bool flip=false)
122 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)
123 bool NxSweepCapsuleTriangles(NxU32 up_direction, NxU32 nb_tris, const NxTriangle *triangles, const NxU32 *edge_flags, const NxVec3 &center, const float radius, const float height, const NxVec3 &dir, float length, NxVec3 &hit, NxVec3 &normal, float &d, NxU32 &index, NxU32 *cachedIndex=NULL)
124 float NxSegmentOBBSqrDist(const NxSegment &segment, const NxVec3 &c0, const NxVec3 &e0, const NxMat33 &r0, float *t, NxVec3 *p)
125 */
Represents a sphere defined by its center point and radius.
Definition: physxSphere.h:28
Represents an oriented bounding box, as a center point, extents(radii) and a rotation.
Definition: physxBox.h:32
Represention of a axis aligned bounding box.
Definition: physxBounds3.h:32
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
Represents a line segment.
Definition: physxSegment.h:27
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
Represents a capsule.
Definition: physxCapsule.h:27
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
Represents an ray as an origin and direction.
Definition: physxRay.h:28