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