Main Page
Class Hierarchy
Compound List
Compound Members
Include
foundation
PxVec2.h
Go to the documentation of this file.
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_FOUNDATION_PX_VEC2_H
15
#define PX_FOUNDATION_PX_VEC2_H
16
21
#include "
foundation/PxMath.h
"
22
23
#ifndef PX_DOXYGEN
24
namespace
physx
25
{
26
#endif
27
28
34
class
PxVec2
35
{
36
public
:
37
41
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
() {}
42
43
47
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
(
PxZERO
r): x(0.0f), y(0.0f)
48
{
49
PX_UNUSED
(r);
50
}
51
59
explicit
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
(
PxReal
a): x(a), y(a) {}
60
67
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
(
PxReal
nx,
PxReal
ny): x(nx), y(ny){}
68
72
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
(
const
PxVec2
& v): x(v.x), y(v.y) {}
73
74
//Operators
75
79
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
&
operator=
(
const
PxVec2
& p) { x = p.
x
; y = p.
y
;
return
*
this
; }
80
84
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
& operator[](
int
index)
85
{
86
PX_ASSERT
(index>=0 && index<=1);
87
88
return
reinterpret_cast<
PxReal
*
>
(
this
)[index];
89
}
90
94
PX_CUDA_CALLABLE
PX_FORCE_INLINE
const
PxReal
& operator[](
int
index)
const
95
{
96
PX_ASSERT
(index>=0 && index<=1);
97
98
return
reinterpret_cast<
const
PxReal
*
>
(
this
)[index];
99
}
100
104
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
operator==
(
const
PxVec2
&v)
const
{
return
x == v.
x
&& y == v.
y
; }
105
109
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
operator!=
(
const
PxVec2
&v)
const
{
return
x != v.
x
|| y != v.
y
; }
110
114
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isZero
()
const
{
return
x==0.0f && y==0.0f; }
115
119
PX_CUDA_CALLABLE
PX_INLINE
bool
isFinite()
const
120
{
121
return
PxIsFinite
(x) &&
PxIsFinite
(y);
122
}
123
127
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isNormalized()
const
128
{
129
const
float
unitTolerance = 1e-4f;
130
return
isFinite() &&
PxAbs
(magnitude()-1)<unitTolerance;
131
}
132
138
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
magnitudeSquared
()
const
{
return
x * x + y * y; }
139
143
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
magnitude
()
const
{
return
PxSqrt
(magnitudeSquared()); }
144
148
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
operator -()
const
149
{
150
return
PxVec2
(-x, -y);
151
}
152
156
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
operator +
(
const
PxVec2
& v)
const
{
return
PxVec2
(x + v.
x
, y + v.
y
); }
157
161
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
operator -(
const
PxVec2
& v)
const
{
return
PxVec2
(x - v.
x
, y - v.
y
); }
162
166
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
operator *
(
PxReal
f)
const
{
return
PxVec2
(x * f, y * f); }
167
171
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
operator /(
PxReal
f)
const
172
{
173
f = 1.0f / f;
// PT: inconsistent notation with operator /=
174
return
PxVec2
(x * f, y * f);
175
}
176
180
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
& operator +=(
const
PxVec2
& v)
181
{
182
x += v.
x
;
183
y += v.
y
;
184
return
*
this
;
185
}
186
190
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
& operator -=(
const
PxVec2
& v)
191
{
192
x -= v.
x
;
193
y -= v.
y
;
194
return
*
this
;
195
}
196
200
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
& operator *=(
PxReal
f)
201
{
202
x *= f;
203
y *= f;
204
return
*
this
;
205
}
209
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
& operator /=(
PxReal
f)
210
{
211
f = 1.0f/f;
// PT: inconsistent notation with operator /
212
x *= f;
213
y *= f;
214
return
*
this
;
215
}
216
220
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
dot(
const
PxVec2
& v)
const
221
{
222
return
x * v.
x
+ y * v.
y
;
223
}
224
227
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
getNormalized()
const
228
{
229
const
PxReal
m = magnitudeSquared();
230
return
m>0.0f ? *
this
*
PxRecipSqrt
(m) :
PxVec2
(0,0);
231
}
232
236
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
normalize()
237
{
238
const
PxReal
m = magnitude();
239
if
(m>0.0f)
240
*
this
/= m;
241
return
m;
242
}
243
247
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
multiply(
const
PxVec2
& a)
const
248
{
249
return
PxVec2
(x*a.
x
, y*a.
y
);
250
}
251
255
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
minimum(
const
PxVec2
& v)
const
256
{
257
return
PxVec2
(
PxMin
(x, v.
x
),
PxMin
(y,v.
y
));
258
}
259
263
PX_CUDA_CALLABLE
PX_FORCE_INLINE
float
minElement()
const
264
{
265
return
PxMin
(x, y);
266
}
267
271
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec2
maximum(
const
PxVec2
& v)
const
272
{
273
return
PxVec2
(
PxMax
(x, v.
x
),
PxMax
(y,v.
y
));
274
}
275
279
PX_CUDA_CALLABLE
PX_FORCE_INLINE
float
maxElement()
const
280
{
281
return
PxMax
(x, y);
282
}
283
284
PxReal
x,
y
;
285
};
286
287
PX_CUDA_CALLABLE
static
PX_FORCE_INLINE
PxVec2
operator *
(
PxReal
f,
const
PxVec2
& v)
288
{
289
return
PxVec2
(f * v.
x
, f * v.
y
);
290
}
291
292
#ifndef PX_DOXYGEN
293
}
// namespace physx
294
#endif
295
297
#endif // PX_FOUNDATION_PX_VEC2_H
Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.
www.nvidia.com