1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_PHYSICS_NX_CAPSULE_GEOMETRY
15#define PX_PHYSICS_NX_CAPSULE_GEOMETRY
16/** \addtogroup geomutils
17@{
18*/
19#include "geometry/PxGeometry.h"
20
21#ifndef PX_DOXYGEN
22namespace physx
23{
24#endif
25
26/**
27\brief Class representing the geometry of a capsule.
28
29Capsules are shaped as the union of a cylinder of length 2 * halfHeight and with the
30given radius centered at the origin and extending along the x axis, and two hemispherical ends.
31\note The scaling of the capsule is expected to be baked into these values, there is no additional scaling parameter.
32
33The function PxTransformFromSegment is a helper for generating an appropriate transform for the capsule from the capsule's interior line segment.
34
35@see PxTransformFromSegment
36*/
37class PxCapsuleGeometry : public PxGeometry
38{
39public:
40 /**
41 \brief Default constructor, initializes to a capsule with zero height and radius.
42 */
43 PX_INLINE PxCapsuleGeometry() : PxGeometry(PxGeometryType::eCAPSULE), radius(0), halfHeight(0) {}
44
45 /**
46 \brief Constructor, initializes to a capsule with passed radius and half height.
47 */
48 PX_INLINE PxCapsuleGeometry(PxReal radius_, PxReal halfHeight_) : PxGeometry(PxGeometryType::eCAPSULE), radius(radius_), halfHeight(halfHeight_) {}
49
50 /**
51 \brief Returns true if the geometry is valid.
52
53 \return True if the current settings are valid.
54
55 \note A valid capsule has radius > 0, halfHeight > 0.
56 It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a capsule that has zero radius or height.
57
58 @see PxRigidActor::createShape, PxPhysics::createShape
59 */
60 PX_INLINE bool isValid() const;
61
62public:
63 /**
64 \brief The radius of the capsule.
65 */
66 PxReal radius;
67
68 /**
69 \brief half of the capsule's height, measured between the centers of the hemispherical ends.
70 */
71 PxReal halfHeight;
72};
73
74
75PX_INLINE bool PxCapsuleGeometry::isValid() const
76{
77 if (mType != PxGeometryType::eCAPSULE)
78 return false;
79 if (!PxIsFinite(radius) || !PxIsFinite(halfHeight))
80 return false;
81 if (radius <= 0.0f || halfHeight <= 0.0f)
82 return false;
83
84 return true;
85}
86
87
88/** \brief creates a transform from the endpoints of a segment, suitable for an actor transform for a PxCapsuleGeometry
89
90\param[in] p0 one end of major axis of the capsule
91\param[in] p1 the other end of the axis of the capsule
92\param[out] halfHeight the halfHeight of the capsule. This parameter is optional.
93\return A PxTransform which will transform the vector (1,0,0) to the capsule axis shrunk by the halfHeight
94*/
95
96PX_FOUNDATION_API PxTransform PxTransformFromSegment(const PxVec3& p0, const PxVec3& p1, PxReal* halfHeight = NULL);
97
98
99#ifndef PX_DOXYGEN
100} // namespace physx
101#endif
102
103/** @} */
104#endif
105