1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30#ifndef GU_SEGMENT_H
31#define GU_SEGMENT_H
32/** \addtogroup geomutils
33@{
34*/
35
36#include "foundation/PxVec3.h"
37#include "Ps.h"
38#include "CmPhysXCommon.h"
39
40namespace physx
41{
42namespace Gu
43{
44
45 /**
46 \brief Represents a line segment.
47
48 Line segment geometry
49 In some cases this structure will be used to represent the infinite line that passes point0 and point1.
50 */
51 class Segment
52 {
53 public:
54 /**
55 \brief Constructor
56 */
57 PX_INLINE Segment()
58 {
59 }
60
61 /**
62 \brief Constructor
63 */
64 PX_INLINE Segment(const PxVec3& _p0, const PxVec3& _p1) : p0(_p0), p1(_p1)
65 {
66 }
67
68 /**
69 \brief Copy constructor
70 */
71 PX_INLINE Segment(const Segment& seg) : p0(seg.p0), p1(seg.p1)
72 {
73 }
74
75 /**
76 \brief Destructor
77 */
78 PX_INLINE ~Segment()
79 {
80 }
81
82 //! Assignment operator
83 PX_INLINE Segment& operator=(const Segment& other)
84 {
85 p0 = other.p0;
86 p1 = other.p1;
87 return *this;
88 }
89
90 //! Equality operator
91 PX_INLINE bool operator==(const Segment& other) const
92 {
93 return (p0==other.p0 && p1==other.p1);
94 }
95
96 //! Inequality operator
97 PX_INLINE bool operator!=(const Segment& other) const
98 {
99 return (p0!=other.p0 || p1!=other.p1);
100 }
101
102 PX_INLINE const PxVec3& getOrigin() const
103 {
104 return p0;
105 }
106
107 //! Return the vector from point0 to point1
108 PX_INLINE PxVec3 computeDirection() const
109 {
110 return p1 - p0;
111 }
112
113 //! Return the vector from point0 to point1
114 PX_INLINE void computeDirection(PxVec3& dir) const
115 {
116 dir = p1 - p0;
117 }
118
119 //! Return the center of the segment segment
120 PX_INLINE PxVec3 computeCenter() const
121 {
122 return (p0 + p1)*0.5f;
123 }
124
125 PX_INLINE PxF32 computeLength() const
126 {
127 return (p1-p0).magnitude();
128 }
129
130 PX_INLINE PxF32 computeSquareLength() const
131 {
132 return (p1-p0).magnitudeSquared();
133 }
134
135 // PT: TODO: remove this one
136 //! Return the square of the length of vector from point0 to point1
137 PX_INLINE PxReal lengthSquared() const
138 {
139 return ((p1 - p0).magnitudeSquared());
140 }
141
142 // PT: TODO: remove this one
143 //! Return the length of vector from point0 to point1
144 PX_INLINE PxReal length() const
145 {
146 return ((p1 - p0).magnitude());
147 }
148
149 /* PX_INLINE void setOriginDirection(const PxVec3& origin, const PxVec3& direction)
150 {
151 p0 = p1 = origin;
152 p1 += direction;
153 }*/
154
155 /**
156 \brief Computes a point on the segment
157
158 \param[out] pt point on segment
159 \param[in] t point's parameter [t=0 => pt = mP0, t=1 => pt = mP1]
160 */
161 PX_INLINE void computePoint(PxVec3& pt, PxF32 t) const
162 {
163 pt = p0 + t * (p1 - p0);
164 }
165
166 // PT: TODO: remove this one
167 //! Return the point at parameter t along the line: point0 + t*(point1-point0)
168 PX_INLINE PxVec3 getPointAt(PxReal t) const
169 {
170 return (p1 - p0)*t + p0;
171 }
172
173 PxVec3 p0; //!< Start of segment
174 PxVec3 p1; //!< End of segment
175 };
176 PX_COMPILE_TIME_ASSERT(sizeof(Gu::Segment) == 24);
177}
178
179}
180
181/** @} */
182#endif
183

source code of qtquick3dphysics/src/3rdparty/PhysX/source/geomutils/include/GuSegment.h