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
22class PhysxBounds3;
23class PhysxBox;
24class PhysxCapsule;
25class PhysxPlane;
26class PhysxRay;
27class PhysxSegment;
28class PhysxSphere;
29
30/**
31 *
32 */
33class 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);
43 bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b);
45 void set_fpu_exceptions(bool b);
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
92public:
93 NxUtilLib *_ptr;
94};
95
96#include "physxUtilLib.I"
97
98#endif // PHYSUTILLIB_H
99
100/*
101NOT WRAPPED:
102bool NxComputeBoxPlanes(const NxBox &box, NxPlane *planes)
103bool NxComputeBoxPoints(const NxBox &box, NxVec3 *pts)
104bool NxComputeBoxVertexNormals(const NxBox &box, NxVec3 *pts)
105const NxU32 *NxGetBoxEdges()
106const NxI32 *NxGetBoxEdgesAxes()
107const NxU32 *NxGetBoxTriangles()
108const NxVec3 *NxGetBoxLocalEdgeNormals()
109const NxU32 *NxGetBoxQuads()
110const NxU32 *NxBoxVertexToQuad(NxU32 vertexIndex)
111NxBSphereMethod NxComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
112bool NxFastComputeSphere(NxSphere &sphere, unsigned nb_verts, const NxVec3 *verts)
113bool NxDiagonalizeInertiaTensor(const NxMat33 &denseInertia, NxVec3 &diagonalInertia, NxMat33 &rotation)
114void NxComputeBounds(NxVec3 &min, NxVec3 &max, NxU32 nbVerts, const NxVec3 *verts)
115NxU32 NxCrc32(const void *buffer, NxU32 nbBytes)
116NxSepAxis NxSeparatingAxis(const NxVec3 &extents0, const NxVec3 &center0, const NxMat33 &rotation0, const NxVec3 &extents1, const NxVec3 &center1, const NxMat33 &rotation1, bool fullTest=true)
117void NxSegmentPlaneIntersect(const NxVec3 &v1, const NxVec3 &v2, const NxPlane &plane, NxReal &dist, NxVec3 &pointOnPlane)
118NxU32 NxRayAABBIntersect2(const NxVec3 &min, const NxVec3 &max, const NxVec3 &origin, const NxVec3 &dir, NxVec3 &coord, NxReal &t)
119bool NxBuildSmoothNormals(NxU32 nbTris, NxU32 nbVerts, const NxVec3 *verts, const NxU32 *dFaces, const NxU16 *wFaces, NxVec3 *normals, bool flip=false)
120bool 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)
121bool 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)
122float NxSegmentOBBSqrDist(const NxSegment &segment, const NxVec3 &c0, const NxVec3 &e0, const NxMat33 &r0, float *t, NxVec3 *p)
123*/
Represention of a axis aligned bounding box.
Represents an oriented bounding box, as a center point, extents(radii) and a rotation.
Definition physxBox.h:29
Represents a capsule.
Represents an ray as an origin and direction.
Definition physxRay.h:26
Represents a line segment.
Represents a sphere defined by its center point and radius.
Definition physxSphere.h:25
float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point)
Compute the distance squared from a point to a line segment.
LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index)
Compute and edge normals for an oriented box.
void set_fpu_rounding_chop()
Set FPU precision.
bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-sphere sweep test.
PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule)
Compute a box which encloses a capsule.
float compute_sphere_density(float radius, float mass)
Computes density of a homogeneous sphere according to sphere mass.
void set_fpu_rounding_near()
Set FPU rounding mode.
bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord)
Ray-AABB intersection test.
bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-capsule sweep test.
float compute_cylinder_density(float radius, float length, float mass)
Computes density of a homogeneous cylinder according to cylinder mass.
void set_fpu_precision24()
Set FPU precision.
PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat)
Create an oriented box from an axis aligned box and a transformation.
int int_floor(const float &f)
Convert a floating point number to an integer.
float compute_ellipsoid_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous ellipsoid according to ellipsoid density.
bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Sphere-vs-capsule sweep test.
float compute_cone_mass(float radius, float length, float density)
Computes mass of a homogeneous cone according to cone density.
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.
void set_fpu_precision53()
Set FPU precision.
float compute_sphere_mass(float radius, float density)
Computes mass of a homogeneous sphere according to sphere density.
void set_fpu_rounding_up()
Set FPU rounding mode.
float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point)
Compute the distance squared from a point to a ray.
unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule)
Ray-capsule intersection test.
bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b)
Test if box A is inside another box B.
bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max)
Boolean segment-AABB intersection test.
PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1)
Compute an overall bounding sphere for a pair of spheres.
bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept)
Segment-AABB intersection test.
LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength)
Computes diagonalized inertia tensor for a box.
bool box_contains_point(const PhysxBox &box, const LPoint3f &p)
Test if an oriented box contains a point.
PhysxCapsule compute_capsule_around_box(const PhysxBox &box)
Compute a capsule which encloses a box.
LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow)
Computes diagonalized inertia tensor for a sphere.
void set_fpu_exceptions(bool b)
Set FPU precision.
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.
float compute_ellipsoid_density(const LVector3f &extents, float mass)
Computes density of a homogeneous ellipsoid according to ellipsoid mass.
int int_ceil(const float &f)
Convert a floating point number to an integer.
float compute_cone_density(float radius, float length, float mass)
Computes density of a homogeneous cone according to cone mass.
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).
float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot, LPoint3f &params)
Point-vs-OBB distance computation.
bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane)
Ray-plane intersection test.
int int_chop(const float &f)
Convert a floating point number to an integer.
bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f &center, float radius, LPoint3f &hit_pos)
Ray-sphere intersection test.
float compute_box_density(const LVector3f &extents, float mass)
Computes density of a homogeneous box according to box mass.
float compute_cylinder_mass(float radius, float length, float density)
Computes mass of a homogeneous cylinder according to cylinder density.
bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1)
Sphere-sphere sweep test.
void set_fpu_precision64()
Set FPU precision.
bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Capsule-vs-capsule sweep test.
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.
float compute_box_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous box according to box density.
bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot)
Boolean ray-OBB intersection test.
void set_fpu_rounding_down()
Set FPU rounding mode.
bool sweep_box_box(const PhysxBox &box0, const PhysxBox &box1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Box-vs-box sweep test.
bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &center, const LVector3f &extents, const LMatrix3f &rot)
Boolean segment-OBB intersection test.
void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2)
Get the tangent vectors associated with a normal.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.