Panda3D

Loading...
Searching...
No Matches
physxUtilLib.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file physxUtilLib.h
10 * @author enn0x
11 * @date 2009-11-01
12 */
13
14#ifndef PHYSXUTILLIB_H
15#define PHYSXUTILLIB_H
16
17#include "pandabase.h"
18#include "luse.h"
19
20#include "config_physx.h"
21
22 class PhysxBounds3;
23 class PhysxBox;
24 class PhysxCapsule;
25 class PhysxPlane;
26 class PhysxRay;
27 class PhysxSegment;
28 class PhysxSphere;
29
30/**
31 *
32 */
33 class EXPCL_PANDAPHYSX PhysxUtilLib {
34
35PUBLISHED:
36 INLINE PhysxUtilLib();
37 INLINE ~PhysxUtilLib();
38
39 bool box_contains_point(const PhysxBox &box, const LPoint3f &p);
40 PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat);
41 LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index);
42 PhysxCapsule compute_capsule_around_box(const PhysxBox &box);
43 bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b);
44 PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule);
45 void set_fpu_exceptions(bool b);
46 void set_fpu_precision24();
47 void set_fpu_precision53();
48 void set_fpu_precision64();
49 void set_fpu_rounding_chop();
50 void set_fpu_rounding_down();
51 void set_fpu_rounding_near();
52 void set_fpu_rounding_up();
53 int int_ceil(const float &f);
54 int int_chop(const float &f);
55 int int_floor(const float &f);
56 float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point);
57 float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point);
58 PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1);
59 void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2);
60 LMatrix3f find_rotation_matrix(const LVector3f &x, const LVector3f &b);
61 float compute_sphere_mass(float radius, float density);
62 float compute_sphere_density(float radius, float mass);
63 float compute_box_mass(const LVector3f &extents, float density);
64 float compute_box_density(const LVector3f &extents, float mass);
65 float compute_ellipsoid_mass(const LVector3f &extents, float density);
66 float compute_ellipsoid_density(const LVector3f &extents, float mass);
67 float compute_cylinder_mass(float radius, float length, float density);
68 float compute_cylinder_density(float radius, float length, float mass);
69 float compute_cone_mass(float radius, float length, float density);
70 float compute_cone_density(float radius, float length, float mass);
71 LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength);
72 LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow);
73 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);
74 bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f &center, const LVector3f &extents);
75 bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane);
76 bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f &center, float radius, LPoint3f &hit_pos);
77 bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept);
78 bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord);
79 bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot);
80 bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max);
81 bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot);
82 unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule);
83 bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1);
84 bool ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull);
85 bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal);
86 bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal);
87 bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
88 bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
89 bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal);
90 float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot, LPoint3f &params);
91
92 public:
93 NxUtilLib *_ptr;
94};
95
96#include "physxUtilLib.I"
97
98#endif // PHYSUTILLIB_H
99
100/*
101 NOT WRAPPED:
102 bool NxComputeBoxPlanes(const NxBox &box, NxPlane *planes)
103 bool NxComputeBoxPoints(const NxBox &box, NxVec3 *pts)
104 bool NxComputeBoxVertexNormals(const NxBox &box, NxVec3 *pts)
105 const NxU32 *NxGetBoxEdges()
106 const NxI32 *NxGetBoxEdgesAxes()
107 const NxU32 *NxGetBoxTriangles()
108 const NxVec3 *NxGetBoxLocalEdgeNormals()
109 const NxU32 *NxGetBoxQuads()
110 const NxU32 *NxBoxVertexToQuad(NxU32 vertexIndex)
111 NxBSphereMethod NxComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
112 bool NxFastComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
113 bool NxDiagonalizeInertiaTensor(const NxMat33 &denseInertia, NxVec3 &diagonalInertia, NxMat33 &rotation)
114 void NxComputeBounds(NxVec3 &min, NxVec3 &max, NxU32 nbVerts, const NxVec3 *verts)
115 NxU32 NxCrc32(const void *buffer, NxU32 nbBytes)
116 NxSepAxis NxSeparatingAxis(const NxVec3 &extents0, const NxVec3 &center0, const NxMat33 &rotation0, const NxVec3 &extents1, const NxVec3 &center1, const NxMat33 &rotation1, bool fullTest=true)
117 void NxSegmentPlaneIntersect(const NxVec3 &v1, const NxVec3 &v2, const NxPlane &plane, NxReal &dist, NxVec3 &pointOnPlane)
118 NxU32 NxRayAABBIntersect2(const NxVec3 &min, const NxVec3 &max, const NxVec3 &origin, const NxVec3 &dir, NxVec3 &coord, NxReal &t)
119 bool NxBuildSmoothNormals(NxU32 nbTris, NxU32 nbVerts, const NxVec3 *verts, const NxU32 *dFaces, const NxU16 *wFaces, NxVec3 *normals, bool flip=false)
120 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)
121 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)
122 float NxSegmentOBBSqrDist(const NxSegment &segment, const NxVec3 &c0, const NxVec3 &e0, const NxMat33 &r0, float *t, NxVec3 *p)
123*/
PhysxBounds3
Represention of a axis aligned bounding box.
Definition physxBounds3.h:29
PhysxBox
Represents an oriented bounding box, as a center point, extents(radii) and a rotation.
Definition physxBox.h:29
PhysxCapsule
Represents a capsule.
Definition physxCapsule.h:25
PhysxPlane
Definition physxPlane.h:25
PhysxRay
Represents an ray as an origin and direction.
Definition physxRay.h:26
PhysxSegment
Represents a line segment.
Definition physxSegment.h:25
PhysxSphere
Represents a sphere defined by its center point and radius.
Definition physxSphere.h:25
PhysxUtilLib::compute_square_distance
float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point)
Compute the distance squared from a point to a line segment.
Definition physxUtilLib.cxx:221
PhysxUtilLib::compute_box_world_edge_normal
LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index)
Compute and edge normals for an oriented box.
Definition physxUtilLib.cxx:155
PhysxUtilLib::set_fpu_rounding_chop
void set_fpu_rounding_chop()
Set FPU precision.
Definition physxUtilLib.cxx:64
PhysxUtilLib::sweep_box_sphere
bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-sphere sweep test.
Definition physxUtilLib.cxx:734
PhysxUtilLib::compute_box_around_capsule
PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule)
Compute a box which encloses a capsule.
Definition physxUtilLib.cxx:196
PhysxUtilLib::compute_sphere_density
float compute_sphere_density(float radius, float mass)
Computes density of a homogeneous sphere according to sphere mass.
Definition physxUtilLib.cxx:294
PhysxUtilLib::set_fpu_rounding_near
void set_fpu_rounding_near()
Set FPU rounding mode.
Definition physxUtilLib.cxx:82
PhysxUtilLib::ray_aabb_intersect
bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord)
Ray-AABB intersection test.
Definition physxUtilLib.cxx:544
PhysxUtilLib::sweep_box_capsule
bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-capsule sweep test.
Definition physxUtilLib.cxx:709
PhysxUtilLib::compute_cylinder_density
float compute_cylinder_density(float radius, float length, float mass)
Computes density of a homogeneous cylinder according to cylinder mass.
Definition physxUtilLib.cxx:360
PhysxUtilLib::set_fpu_precision24
void set_fpu_precision24()
Set FPU precision.
Definition physxUtilLib.cxx:37
PhysxUtilLib::create_box
PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat)
Create an oriented box from an axis aligned box and a transformation.
Definition physxUtilLib.cxx:140
PhysxUtilLib::int_floor
int int_floor(const float &f)
Convert a floating point number to an integer.
Definition physxUtilLib.cxx:118
PhysxUtilLib::compute_ellipsoid_mass
float compute_ellipsoid_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous ellipsoid according to ellipsoid density.
Definition physxUtilLib.cxx:327
PhysxUtilLib::sweep_sphere_capsule
bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Sphere-vs-capsule sweep test.
Definition physxUtilLib.cxx:786
PhysxUtilLib::compute_cone_mass
float compute_cone_mass(float radius, float length, float density)
Computes mass of a homogeneous cone according to cone density.
Definition physxUtilLib.cxx:371
PhysxUtilLib::box_box_intersect
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)
Boolean intersection test between two OBBs.
Definition physxUtilLib.cxx:422
PhysxUtilLib::set_fpu_precision53
void set_fpu_precision53()
Set FPU precision.
Definition physxUtilLib.cxx:46
PhysxUtilLib::compute_sphere_mass
float compute_sphere_mass(float radius, float density)
Computes mass of a homogeneous sphere according to sphere density.
Definition physxUtilLib.cxx:283
PhysxUtilLib::set_fpu_rounding_up
void set_fpu_rounding_up()
Set FPU rounding mode.
Definition physxUtilLib.cxx:91
PhysxUtilLib::compute_distance_squared
float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point)
Compute the distance squared from a point to a ray.
Definition physxUtilLib.cxx:209
PhysxUtilLib::ray_capsule_intersect
unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule)
Ray-capsule intersection test.
Definition physxUtilLib.cxx:633
PhysxUtilLib::is_box_a_inside_box_b
bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b)
Test if box A is inside another box B.
Definition physxUtilLib.cxx:185
PhysxUtilLib::segment_aabb_intersect
bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max)
Boolean segment-AABB intersection test.
Definition physxUtilLib.cxx:593
PhysxUtilLib::merge_spheres
PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1)
Compute an overall bounding sphere for a pair of spheres.
Definition physxUtilLib.cxx:233
PhysxUtilLib::segment_box_intersect
bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept)
Segment-AABB intersection test.
Definition physxUtilLib.cxx:517
PhysxUtilLib::compute_box_inertia_tensor
LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength)
Computes diagonalized inertia tensor for a box.
Definition physxUtilLib.cxx:394
PhysxUtilLib::box_contains_point
bool box_contains_point(const PhysxBox &box, const LPoint3f &p)
Test if an oriented box contains a point.
Definition physxUtilLib.cxx:129
PhysxUtilLib::compute_capsule_around_box
PhysxCapsule compute_capsule_around_box(const PhysxBox &box)
Compute a capsule which encloses a box.
Definition physxUtilLib.cxx:171
PhysxUtilLib::compute_sphere_inertia_tensor
LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow)
Computes diagonalized inertia tensor for a sphere.
Definition physxUtilLib.cxx:407
PhysxUtilLib::set_fpu_exceptions
void set_fpu_exceptions(bool b)
Set FPU precision.
Definition physxUtilLib.cxx:28
PhysxUtilLib::ray_tri_intersect
bool ray_tri_intersect(const LPoint3f &orig, const LVector3f &dir, const LPoint3f &vert0, const LPoint3f &vert1, const LPoint3f &vert2, LVector3f &hit, bool cull)
Ray-triangle intersection test.
Definition physxUtilLib.cxx:675
PhysxUtilLib::compute_ellipsoid_density
float compute_ellipsoid_density(const LVector3f &extents, float mass)
Computes density of a homogeneous ellipsoid according to ellipsoid mass.
Definition physxUtilLib.cxx:338
PhysxUtilLib::int_ceil
int int_ceil(const float &f)
Convert a floating point number to an integer.
Definition physxUtilLib.cxx:100
PhysxUtilLib::compute_cone_density
float compute_cone_density(float radius, float length, float mass)
Computes density of a homogeneous cone according to cone mass.
Definition physxUtilLib.cxx:382
PhysxUtilLib::find_rotation_matrix
LMatrix3f find_rotation_matrix(const LVector3f &x, const LVector3f &b)
Computes a rotation matrix M so that: M * x = b (x and b are unit vectors).
Definition physxUtilLib.cxx:268
PhysxUtilLib::point_obb_sqr_dist
float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot, LPoint3f &params)
Point-vs-OBB distance computation.
Definition physxUtilLib.cxx:840
PhysxUtilLib::ray_plane_intersect
bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane)
Ray-plane intersection test.
Definition physxUtilLib.cxx:469
PhysxUtilLib::int_chop
int int_chop(const float &f)
Convert a floating point number to an integer.
Definition physxUtilLib.cxx:109
PhysxUtilLib::ray_sphere_intersect
bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f &center, float radius, LPoint3f &hit_pos)
Ray-sphere intersection test.
Definition physxUtilLib.cxx:488
PhysxUtilLib::compute_box_density
float compute_box_density(const LVector3f &extents, float mass)
Computes density of a homogeneous box according to box mass.
Definition physxUtilLib.cxx:316
PhysxUtilLib::compute_cylinder_mass
float compute_cylinder_mass(float radius, float length, float density)
Computes mass of a homogeneous cylinder according to cylinder density.
Definition physxUtilLib.cxx:349
PhysxUtilLib::swept_spheres_intersect
bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1)
Sphere-sphere sweep test.
Definition physxUtilLib.cxx:654
PhysxUtilLib::set_fpu_precision64
void set_fpu_precision64()
Set FPU precision.
Definition physxUtilLib.cxx:55
PhysxUtilLib::sweep_capsule_capsule
bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Capsule-vs-capsule sweep test.
Definition physxUtilLib.cxx:759
PhysxUtilLib::tri_box_intersect
bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f &center, const LVector3f &extents)
Boolean intersection test between a triangle and a box.
Definition physxUtilLib.cxx:447
PhysxUtilLib::compute_box_mass
float compute_box_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous box according to box density.
Definition physxUtilLib.cxx:305
PhysxUtilLib::ray_obb_intersect
bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot)
Boolean ray-OBB intersection test.
Definition physxUtilLib.cxx:613
PhysxUtilLib::set_fpu_rounding_down
void set_fpu_rounding_down()
Set FPU rounding mode.
Definition physxUtilLib.cxx:73
PhysxUtilLib::sweep_box_box
bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Box-vs-box sweep test.
Definition physxUtilLib.cxx:813
PhysxUtilLib::segment_obb_intersect
bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot)
Boolean segment-OBB intersection test.
Definition physxUtilLib.cxx:571
PhysxUtilLib::normal_to_tangents
void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2)
Get the tangent vectors associated with a normal.
Definition physxUtilLib.cxx:246
config_physx.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physxUtilLib.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.