15 #include "physxUtilLib.h" 16 #include "physxManager.h" 17 #include "physxBounds3.h" 19 #include "physxCapsule.h" 20 #include "physxPlane.h" 22 #include "physxSegment.h" 23 #include "physxSphere.h" 33 _ptr->NxSetFPUExceptions(b);
44 _ptr->NxSetFPUPrecision24();
55 _ptr->NxSetFPUPrecision53();
66 _ptr->NxSetFPUPrecision64();
77 _ptr->NxSetFPURoundingChop();
88 _ptr->NxSetFPURoundingDown();
99 _ptr->NxSetFPURoundingNear();
110 _ptr->NxSetFPURoundingUp();
121 return _ptr->NxIntCeil(f);
132 return _ptr->NxIntChop(f);
143 return _ptr->NxIntFloor(f);
195 _ptr->NxComputeBoxWorldEdgeNormal(box._box, edge_index, nNormal);
210 _ptr->NxComputeCapsuleAroundBox(box._box, capsule._capsule);
226 return _ptr->NxIsBoxAInsideBoxB(a._box, b._box);
240 _ptr->NxComputeBoxAroundCapsule(capsule._capsule, box._box);
289 _ptr->NxMergeSpheres(merged._sphere, sphere0._sphere, sphere1._sphere);
350 return _ptr->NxComputeSphereMass(radius, density);
365 return _ptr->NxComputeSphereDensity(radius, mass);
440 return _ptr->NxComputeCylinderMass(radius, length, density);
455 return _ptr->NxComputeCylinderDensity(radius, length, mass);
470 return _ptr->NxComputeConeMass(radius, length, density);
485 return _ptr->NxComputeConeDensity(radius, length, mass);
502 _ptr->NxComputeBoxInertiaTensor(tensor, mass, xlength, ylength, zlength);
519 _ptr->NxComputeSphereInertiaTensor(tensor, mass, radius, hollow);
541 nassertr_always(!extents0.
is_nan(),
false);
542 nassertr_always(!center0.
is_nan(),
false);
543 nassertr_always(!rotation0.
is_nan(),
false);
544 nassertr_always(!extents1.
is_nan(),
false);
545 nassertr_always(!center1.
is_nan(),
false);
546 nassertr_always(!rotation1.
is_nan(),
false);
548 return _ptr->NxBoxBoxIntersect(
572 nassertr_always(!vertex0.
is_nan(),
false);
573 nassertr_always(!vertex1.
is_nan(),
false);
574 nassertr_always(!vertex2.
is_nan(),
false);
575 nassertr_always(!center.
is_nan(),
false);
576 nassertr_always(!extents.
is_nan(),
false);
578 return _ptr->NxTriBoxIntersect(
599 NxVec3 nPointOnPlane;
601 bool result = _ptr->NxRayPlaneIntersect(ray._ray, plane._plane, dist, nPointOnPlane);
603 PhysxManager::update_point3_from_nxVec3(point_on_plane, nPointOnPlane);
624 nassertr_always(!origin.
is_nan(),
false);
625 nassertr_always(!dir.
is_nan(),
false);
626 nassertr_always(!center.
is_nan(),
false);
629 NxVec3 nPointOnPlane;
631 bool result = _ptr->NxRaySphereIntersect(
640 PhysxManager::update_point3_from_nxVec3(hit_pos, nPointOnPlane);
659 nassertr_always(!p1.
is_nan(),
false);
660 nassertr_always(!p2.
is_nan(),
false);
661 nassertr_always(!bbox_min.
is_nan(),
false);
662 nassertr_always(!bbox_max.
is_nan(),
false);
666 bool result =_ptr->NxSegmentBoxIntersect(
673 PhysxManager::update_point3_from_nxVec3(intercept, nIntercept);
692 nassertr_always(!min.
is_nan(),
false);
693 nassertr_always(!max.
is_nan(),
false);
694 nassertr_always(!origin.
is_nan(),
false);
695 nassertr_always(!dir.
is_nan(),
false);
699 bool result = _ptr->NxRayAABBIntersect(
706 PhysxManager::update_point3_from_nxVec3(coord, nCoord);
725 nassertr_always(!p0.
is_nan(),
false);
726 nassertr_always(!p1.
is_nan(),
false);
727 nassertr_always(!center.
is_nan(),
false);
728 nassertr_always(!extents.
is_nan(),
false);
729 nassertr_always(!rot.
is_nan(),
false);
731 return _ptr->NxSegmentOBBIntersect(
753 nassertr_always(!p0.
is_nan(),
false);
754 nassertr_always(!p1.
is_nan(),
false);
755 nassertr_always(!min.
is_nan(),
false);
756 nassertr_always(!max.
is_nan(),
false);
758 return _ptr->NxSegmentAABBIntersect(
779 nassertr_always(!center.
is_nan(),
false);
780 nassertr_always(!extents.
is_nan(),
false);
781 nassertr_always(!rot.
is_nan(),
false);
783 return _ptr->NxRayOBBIntersect(
803 nassertr_always(!origin.
is_nan(), -1);
804 nassertr_always(!dir.
is_nan(), -1);
806 NxReal t[2] = { 0.0f, 0.0f };
808 return _ptr->NxRayCapsuleIntersect(
811 capsule._capsule, t);
829 nassertr_always(!velocity0.
is_nan(),
false);
830 nassertr_always(!velocity1.
is_nan(),
false);
832 return _ptr->NxSweptSpheresIntersect(
858 nassertr_always(!orig.
is_nan(),
false);
859 nassertr_always(!dir.
is_nan(),
false);
860 nassertr_always(!vert0.
is_nan(),
false);
861 nassertr_always(!vert1.
is_nan(),
false);
862 nassertr_always(!vert2.
is_nan(),
false);
866 bool result = _ptr->NxRayTriIntersect(
897 nassertr_always(!dir.
is_nan(),
false);
902 bool result = _ptr->NxSweepBoxCapsule(
903 box._box, lss._capsule,
905 length, min_dist, nNormal);
907 PhysxManager::update_vec3_from_nxVec3(normal, nNormal);
927 nassertr_always(!dir.
is_nan(),
false);
932 bool result = _ptr->NxSweepBoxSphere(
933 box._box, sphere._sphere,
935 length, min_dist, nNormal);
937 PhysxManager::update_vec3_from_nxVec3(normal, nNormal);
958 nassertr_always(!dir.
is_nan(),
false);
964 bool result = _ptr->NxSweepCapsuleCapsule(
965 lss0._capsule, lss1._capsule,
967 length, min_dist, nIp, nNormal);
969 PhysxManager::update_point3_from_nxVec3(ip, nIp);
970 PhysxManager::update_vec3_from_nxVec3(normal, nNormal);
991 nassertr_always(!dir.
is_nan(),
false);
997 bool result = _ptr->NxSweepSphereCapsule(
998 sphere._sphere, lss._capsule,
1000 length, min_dist, nIp, nNormal);
1002 PhysxManager::update_point3_from_nxVec3(ip, nIp);
1003 PhysxManager::update_vec3_from_nxVec3(normal, nNormal);
1024 nassertr_always(!dir.
is_nan(),
false);
1030 bool result = _ptr->NxSweepBoxBox(
1031 box0._box, box1._box,
1033 length, nIp, nNormal, min_dist);
1035 PhysxManager::update_point3_from_nxVec3(ip, nIp);
1036 PhysxManager::update_vec3_from_nxVec3(normal, nNormal);
1055 nassertr_always(!point.
is_nan(), 0.0f);
1056 nassertr_always(!center.
is_nan(), 0.0f);
1057 nassertr_always(!extents.
is_nan(), 0.0f);
1058 nassertr_always(!rot.
is_nan(), 0.0f);
1062 float result = _ptr->NxPointOBBSqrDist(
1069 PhysxManager::update_point3_from_nxVec3(params, nParams);
bool ray_sphere_intersect(const LPoint3f &origin, const LVector3f &dir, float length, const LPoint3f ¢er, float radius, LPoint3f &hit_pos)
Ray-sphere intersection test.
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)
Boolean intersection test between two OBBs.
float compute_sphere_density(float radius, float mass)
Computes density of a homogeneous sphere according to sphere mass.
LVector3f compute_box_inertia_tensor(float mass, float xlength, float ylength, float zlength)
Computes diagonalized inertia tensor for a 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.
float compute_cone_density(float radius, float length, float mass)
Computes density of a homogeneous cone according to cone mass.
bool sweep_capsule_capsule(const PhysxCapsule &lss0, const PhysxCapsule &lss1, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Capsule-vs-capsule sweep test.
Represents a sphere defined by its center point and radius.
bool segment_obb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot)
Boolean segment-OBB intersection test.
PhysxSphere merge_spheres(const PhysxSphere &sphere0, const PhysxSphere &sphere1)
Compute an overall bounding sphere for a pair of spheres.
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.
bool tri_box_intersect(const LPoint3f &vertex0, const LPoint3f &vertex1, const LPoint3f &vertex2, const LPoint3f ¢er, const LVector3f &extents)
Boolean intersection test between a triangle and a box.
float compute_cylinder_density(float radius, float length, float mass)
Computes density of a homogeneous cylinder according to cylinder mass.
Represents an oriented bounding box, as a center point, extents(radii) and a rotation.
static NxVec3 point3_to_nxVec3(const LPoint3f &p)
Converts from LPoint3f to NxVec3.
static const LVector3f & zero()
Returns a zero-length vector.
Represention of a axis aligned bounding box.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
bool segment_box_intersect(const LPoint3f &p1, const LPoint3f &p2, const LPoint3f &bbox_min, const LPoint3f &bbox_max, LPoint3f &intercept)
Segment-AABB intersection test.
static NxMat34 mat4_to_nxMat34(const LMatrix4f &m)
Converts from LMatrix4f to NxMat34.
Represents a line segment.
void set_fpu_rounding_down()
Set FPU rounding mode.
float compute_cylinder_mass(float radius, float length, float density)
Computes mass of a homogeneous cylinder according to cylinder density.
This is a 4-by-4 transform matrix.
int int_chop(const float &f)
Convert a floating point number to an integer.
static NxVec3 vec3_to_nxVec3(const LVector3f &v)
Converts from LVector3f to NxVec3.
bool sweep_sphere_capsule(const PhysxSphere &sphere, const PhysxCapsule &lss, const LVector3f &dir, float length, LPoint3f &ip, LVector3f &normal)
Sphere-vs-capsule sweep test.
bool ray_aabb_intersect(const LPoint3f &min, const LPoint3f &max, const LPoint3f &origin, const LVector3f &dir, LPoint3f &coord)
Ray-AABB intersection test.
static NxMat33 mat3_to_nxMat33(const LMatrix3f &m)
Converts from LMatrix3f to NxMat33.
unsigned int ray_capsule_intersect(const LPoint3f &origin, const LVector3f &dir, const PhysxCapsule &capsule)
Ray-capsule intersection test.
bool segment_aabb_intersect(const LPoint3f &p0, const LPoint3f &p1, const LPoint3f &min, const LPoint3f &max)
Boolean segment-AABB intersection test.
static LVector3f nxVec3_to_vec3(const NxVec3 &v)
Converts from NxVec3 to LVector3f.
LVector3f compute_sphere_inertia_tensor(float mass, float radius, bool hollow)
Computes diagonalized inertia tensor for a sphere.
bool ray_plane_intersect(const PhysxRay &ray, const PhysxPlane &plane, LPoint3f &point_on_plane)
Ray-plane intersection test.
float compute_sphere_mass(float radius, float density)
Computes mass of a homogeneous sphere according to sphere density.
float compute_box_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous box according to box density.
float compute_cone_mass(float radius, float length, float density)
Computes mass of a homogeneous cone according to cone density.
int int_ceil(const float &f)
Convert a floating point number to an integer.
void set_fpu_rounding_up()
Set FPU rounding mode.
void set_fpu_precision64()
Set FPU precision.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
PhysxCapsule compute_capsule_around_box(const PhysxBox &box)
Compute a capsule which encloses a box.
float compute_distance_squared(const PhysxRay &ray, const LPoint3f &point)
Compute the distance squared from a point to a ray.
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).
void set_fpu_rounding_chop()
Set FPU precision.
void set_fpu_rounding_near()
Set FPU rounding mode.
bool is_box_a_inside_box_b(const PhysxBox &a, const PhysxBox &b)
Test if box A is inside another box B.
void normal_to_tangents(const LVector3f &n, LVector3f &t1, LVector3f &t2)
Get the tangent vectors associated with a normal.
bool box_contains_point(const PhysxBox &box, const LPoint3f &p)
Test if an oriented box contains a point.
float compute_ellipsoid_mass(const LVector3f &extents, float density)
Computes mass of a homogeneous ellipsoid according to ellipsoid density.
bool ray_obb_intersect(const PhysxRay &ray, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot)
Boolean ray-OBB intersection test.
void set_fpu_exceptions(bool b)
Set FPU precision.
void set_fpu_precision24()
Set FPU precision.
This is a 3-by-3 transform matrix.
PhysxBox create_box(const PhysxBounds3 &aabb, const LMatrix4f &mat)
Create an oriented box from an axis aligned box and a transformation.
static LMatrix3f nxMat33_to_mat3(const NxMat33 &m)
Converts from NxMat33 to LMatrix3f.
int int_floor(const float &f)
Convert a floating point number to an integer.
float compute_box_density(const LVector3f &extents, float mass)
Computes density of a homogeneous box according to box mass.
float point_obb_sqr_dist(const LPoint3f &point, const LPoint3f ¢er, const LVector3f &extents, const LMatrix3f &rot, LPoint3f ¶ms)
Point-vs-OBB distance computation.
bool sweep_box_capsule(const PhysxBox &box, const PhysxCapsule &lss, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-capsule sweep test.
float compute_square_distance(const PhysxSegment &seg, const LPoint3f &point)
Compute the distance squared from a point to a line segment.
bool sweep_box_sphere(const PhysxBox &box, const PhysxSphere &sphere, const LVector3f &dir, float length, LVector3f &normal)
Box-vs-sphere sweep test.
Represents an ray as an origin and direction.
PhysxBox compute_box_around_capsule(const PhysxCapsule &capsule)
Compute a box which encloses a capsule.
bool swept_spheres_intersect(const PhysxSphere &sphere0, const LVector3f &velocity0, const PhysxSphere &sphere1, const LVector3f &velocity1)
Sphere-sphere sweep test.
void set_fpu_precision53()
Set FPU precision.
LVector3f compute_box_world_edge_normal(const PhysxBox &box, unsigned int edge_index)
Compute and edge normals for an oriented box.