aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Source/GeomUtils/src/GuBounds.h
blob: 1f94d2540df48efe5b95a4e22c3e1361c43ce5e7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  

#ifndef GU_BOUNDS_H
#define GU_BOUNDS_H

#include "foundation/PxBounds3.h"
#include "foundation/PxFlags.h"
#include "GuSIMDHelpers.h"
#include <stddef.h>
#include "PxGeometry.h"
#include "GuBox.h"
#include "GuCenterExtents.h"
#include "GuSphere.h"
#include "GuCapsule.h"

namespace physx
{
class PxGeometry;

namespace Gu
{

//For spheres, planes, capsules and boxes just set localSpaceBounds to NULL.
//For convex meshes, triangle meshes, and heightfields set localSpaceBounds to the relevant pointer if it has already been pre-fetched.  
//For convex meshes, triangle meshes, and heightfields set localSpaceBounds to NULL if it has not already been pre-fetched.   computeBounds will synchronously 
//prefetch the local space bounds if localSpaceBounds is NULL.
//'contactOffset' and 'inflation' should not be used at the same time, i.e. either contactOffset==0.0f, or inflation==1.0f
PX_PHYSX_COMMON_API void computeBounds(PxBounds3& bounds, const PxGeometry& geometry, const PxTransform& transform, float contactOffset, const CenterExtentsPadded* PX_RESTRICT localSpaceBounds, float inflation, bool extrudeHeightfields);	//AABB in world space.

//For spheres, planes, capsules and boxes just set localSpaceBounds to NULL.
//For convex meshes, triangle meshes, and heightfields set localSpaceBounds to the relevant pointer if it has not already been pre-fetched.  
//For convex meshes, triangle meshes, and heightfields set localSpaceBounds to NULL if it has not already been pre-fetched.   computeBounds will synchronously 
//prefetch the local space bounds if localSpaceBounds is NULL.
PX_PHYSX_COMMON_API PxF32 computeBoundsWithCCDThreshold(Vec3p& origin, Vec3p& extent, const PxGeometry& geometry, const PxTransform& transform, const CenterExtentsPadded* PX_RESTRICT localSpaceBounds);	//AABB in world space.


PX_FORCE_INLINE PxBounds3 computeBounds(const PxGeometry& geometry, const PxTransform& pose, bool extrudeHeightfields)
{
	PxBounds3 bounds;
	computeBounds(bounds, geometry, pose, 0.0f, NULL, 1.0f, extrudeHeightfields);
	return bounds;
}

class ShapeData
{
public:

	PX_PHYSX_COMMON_API						ShapeData(const PxGeometry& g, const PxTransform& t, PxReal inflation);	

	// PT: used by overlaps (box, capsule, convex)
	PX_FORCE_INLINE const PxVec3&			getPrunerBoxGeomExtentsInflated()	const	{ return mPrunerBoxGeomExtents; }

	// PT: used by overlaps (box, capsule, convex)
	PX_FORCE_INLINE const PxVec3&			getPrunerWorldPos()					const	{ return mGuBox.center;			}

	PX_FORCE_INLINE const PxBounds3&		getPrunerInflatedWorldAABB()		const	{ return mPrunerInflatedAABB;	}

	// PT: used by overlaps (box, capsule, convex)
	PX_FORCE_INLINE const PxMat33&			getPrunerWorldRot33()				const	{ return mGuBox.rot;			}

	// PT: this one only used by overlaps so far (for sphere shape, pruner level)
	PX_FORCE_INLINE const Gu::Sphere&		getGuSphere() const
	{
		PX_ASSERT(mType == PxGeometryType::eSPHERE);
		return reinterpret_cast<const Gu::Sphere&>(mGuSphere);
	}

	// PT: this one only used by sweeps so far (for box shape, NP level)
	PX_FORCE_INLINE const Gu::Box&			getGuBox() const
	{
		PX_ASSERT(mType == PxGeometryType::eBOX);
		return mGuBox;
	}

	// PT: this one used by sweeps (NP level) and overlaps (pruner level) - for capsule shape
	PX_FORCE_INLINE const Gu::Capsule&		getGuCapsule() const
	{
		PX_ASSERT(mType == PxGeometryType::eCAPSULE);
		return reinterpret_cast<const Gu::Capsule&>(mGuCapsule);
	}

	PX_FORCE_INLINE float					getCapsuleHalfHeight() const
	{
		PX_ASSERT(mType == PxGeometryType::eCAPSULE);
		return mGuBox.extents.x;
	}

	PX_FORCE_INLINE	PxU32					isOBB()		const { return PxU32(mIsOBB);				}
	PX_FORCE_INLINE	PxGeometryType::Enum	getType()	const { return PxGeometryType::Enum(mType);	}

	PX_NOCOPY(ShapeData)
private:

	// PT: box: pre-inflated box extents
	//     capsule: pre-inflated extents of box-around-capsule
	//     convex: pre-inflated extents of box-around-convex
	//     sphere: not used
	PxVec3				mPrunerBoxGeomExtents;	// used for pruners. This volume encloses but can differ from the original shape

	// PT:
	//
	// box center = unchanged copy of initial shape's position, except for convex (position of box around convex)
	// SIMD code will load it as a V4 (safe because member is not last of Gu structure)
	//
	// box rot = precomputed PxMat33 version of initial shape's rotation, except for convex (rotation of box around convex)
	// SIMD code will load it as V4s (safe because member is not last of Gu structure)
	//
	// box extents = non-inflated initial box extents for box shape, half-height for capsule, otherwise not used
	Gu::Box				mGuBox;

	PxBounds3			mPrunerInflatedAABB;	// precomputed AABB for the pruner shape
	PxU16				mIsOBB;					// true for OBB, false for AABB. Also used as padding for mPrunerInflatedAABB, don't move.
	PxU16				mType;					// shape's type

	// these union Gu shapes are only precomputed for narrow phase (not pruners), can be different from mPrunerVolume
	// so need separate storage
	union
	{
		PxU8 mGuCapsule[sizeof(Gu::Capsule)];	// 28
		PxU8 mGuSphere[sizeof(Gu::Sphere)];		// 16
	};
};

// PT: please make sure it fits in "one" cache line
PX_COMPILE_TIME_ASSERT(sizeof(ShapeData)==128);

}  // namespace Gu

}
#endif