Main Page Class List Class Members

NvBlastPxSharedHelpers.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27
28
29 #ifndef NVBLASTPXSHAREDTYPESHELPERS_H
30 #define NVBLASTPXSHAREDTYPESHELPERS_H
31
32 #include "NvCTypes.h"
33 #include <PxVec2.h>
34 #include <PxVec3.h>
35 #include <PxVec4.h>
36 #include <PxTransform.h>
37 #include <PxPlane.h>
38 #include <PxMat33.h>
39 #include <PxMat44.h>
40 #include <PxBounds3.h>
41
42 #define WCast(type, name) reinterpret_cast<type>(name)
43 #define RCast(type, name) reinterpret_cast<const type>(name)
44
45 #define CONVERT(BlastType, PxSharedType) \
46 static inline PxSharedType& toPxShared(BlastType& v) \
47 { \
48 return WCast(PxSharedType&, v); \
49 } \
50 static inline const PxSharedType& toPxShared(const BlastType& v) \
51 { \
52 return RCast(PxSharedType&, v); \
53 } \
54 static inline const BlastType& fromPxShared(const PxSharedType& v) \
55 { \
56 return RCast(BlastType&, v); \
57 } \
58 static inline BlastType& fromPxShared(PxSharedType& v) \
59 { \
60 return WCast(BlastType&, v); \
61 } \
62 static inline PxSharedType* toPxShared(BlastType* v) \
63 { \
64 return WCast(PxSharedType*, v); \
65 } \
66 static inline const PxSharedType* toPxShared(const BlastType* v) \
67 { \
68 return RCast(PxSharedType*, v); \
69 } \
70 static inline const BlastType* fromPxShared(const PxSharedType* v) \
71 { \
72 return RCast(BlastType*, v); \
73 } \
74 static inline BlastType* fromPxShared(PxSharedType* v) \
75 { \
76 return WCast(BlastType*, v); \
77 }
78
79
80 CONVERT(NvcVec2, physx::PxVec2)
81 CONVERT(NvcVec3, physx::PxVec3)
82 CONVERT(NvcVec4, physx::PxVec4)
83 CONVERT(NvcQuat, physx::PxQuat)
84 CONVERT(NvcTransform, physx::PxTransform)
85 CONVERT(NvcPlane, physx::PxPlane)
86 CONVERT(NvcMat33, physx::PxMat33)
87 CONVERT(NvcMat44, physx::PxMat44)
88 CONVERT(NvcBounds3, physx::PxBounds3)
89
90 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec2) == sizeof(physx::PxVec2));
91 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec2, x) == NV_OFFSET_OF(physx::PxVec2, x));
92 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec2, y) == NV_OFFSET_OF(physx::PxVec2, y));
93
94 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec3) == sizeof(physx::PxVec3));
95 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, x) == NV_OFFSET_OF(physx::PxVec3, x));
96 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, y) == NV_OFFSET_OF(physx::PxVec3, y));
97 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, z) == NV_OFFSET_OF(physx::PxVec3, z));
98
99 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec4) == sizeof(physx::PxVec4));
100 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, x) == NV_OFFSET_OF(physx::PxVec4, x));
101 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, y) == NV_OFFSET_OF(physx::PxVec4, y));
102 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, z) == NV_OFFSET_OF(physx::PxVec4, z));
103 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, w) == NV_OFFSET_OF(physx::PxVec4, w));
104
105 NV_COMPILE_TIME_ASSERT(sizeof(NvcQuat) == sizeof(physx::PxQuat));
106 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, x) == NV_OFFSET_OF(physx::PxQuat, x));
107 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, y) == NV_OFFSET_OF(physx::PxQuat, y));
108 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, z) == NV_OFFSET_OF(physx::PxQuat, z));
109 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, w) == NV_OFFSET_OF(physx::PxQuat, w));
110
111 NV_COMPILE_TIME_ASSERT(sizeof(NvcTransform) == sizeof(physx::PxTransform));
112 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcTransform, p) == NV_OFFSET_OF(physx::PxTransform, p));
113 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcTransform, q) == NV_OFFSET_OF(physx::PxTransform, q));
114
115 NV_COMPILE_TIME_ASSERT(sizeof(NvcPlane) == sizeof(physx::PxPlane));
116 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcPlane, n) == NV_OFFSET_OF(physx::PxPlane, n));
117 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcPlane, d) == NV_OFFSET_OF(physx::PxPlane, d));
118
119 NV_COMPILE_TIME_ASSERT(sizeof(NvcMat33) == sizeof(physx::PxMat33));
120 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column0) == NV_OFFSET_OF(physx::PxMat33, column0));
121 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column1) == NV_OFFSET_OF(physx::PxMat33, column1));
122 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column2) == NV_OFFSET_OF(physx::PxMat33, column2));
123
124 NV_COMPILE_TIME_ASSERT(sizeof(NvcBounds3) == sizeof(physx::PxBounds3));
125 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcBounds3, minimum) == NV_OFFSET_OF(physx::PxBounds3, minimum));
126 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcBounds3, maximum) == NV_OFFSET_OF(physx::PxBounds3, maximum));
127
128 // Some basic operators
129 inline NvcVec2 operator+(const NvcVec2& v1, const NvcVec2& v2)
130 {
131 return{ v1.x + v2.x, v1.y + v2.y };
132 }
133 inline NvcVec2 operator-(const NvcVec2& v1, const NvcVec2& v2)
134 {
135 return{ v1.x - v2.x, v1.y - v2.y };
136 }
137 inline NvcVec2 operator+(const NvcVec2& v, float f)
138 {
139 return{ v.x + f, v.y + f };
140 }
141 inline NvcVec2 operator+(float f, const NvcVec2& v)
142 {
143 return{ v.x + f, v.y + f };
144 }
145 inline NvcVec2 operator*(const NvcVec2& v, float f)
146 {
147 return{ v.x * f, v.y * f };
148 }
149 inline NvcVec2 operator*(float f, const NvcVec2& v)
150 {
151 return{ v.x * f, v.y * f };
152 }
153 inline NvcVec2 operator/(const NvcVec2& v, float f)
154 {
155 return{ v.x / f, v.y / f };
156 }
157 inline float dot(const NvcVec2& v1, const NvcVec2& v2)
158 {
159 return v1.x * v2.x + v1.y * v2.y;
160 }
161 inline NvcVec2 neg(const NvcVec2& v)
162 {
163 return{ -v.x, -v.y };
164 }
165
166 inline NvcVec3 operator+(const NvcVec3& v1, const NvcVec3& v2)
167 {
168 return{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
169 }
170 inline NvcVec3 operator-(const NvcVec3& v1, const NvcVec3& v2)
171 {
172 return{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
173 }
174 inline NvcVec3 operator*(const NvcVec3& v1, const NvcVec3& v2)
175 {
176 return{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
177 }
178 inline NvcVec3 operator/(const NvcVec3& v1, const NvcVec3& v2)
179 {
180 return{ v1.x / v2.x, v1.y / v2.y, v1.z / v2.z };
181 }
182 inline NvcVec3 operator+(const NvcVec3& v, float f)
183 {
184 return{ v.x + f, v.y + f, v.z + f };
185 }
186 inline NvcVec3 operator+(float f, const NvcVec3& v)
187 {
188 return{ v.x + f, v.y + f, v.z + f };
189 }
190 inline NvcVec3 operator*(const NvcVec3& v, float f)
191 {
192 return{ v.x * f, v.y * f, v.z * f };
193 }
194 inline NvcVec3 operator*(float f, const NvcVec3& v)
195 {
196 return{ v.x * f, v.y * f, v.z * f };
197 }
198 inline NvcVec3 operator/(const NvcVec3& v, float f)
199 {
200 return{ v.x / f, v.y / f, v.z / f };
201 }
202 inline float dot(const NvcVec3& v1, const NvcVec3& v2)
203 {
204 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
205 }
206 inline NvcVec3 neg(const NvcVec3& v)
207 {
208 return{ -v.x, -v.y, -v.z };
209 }
210
211 #endif // #ifndef NVBLASTPHYSXTYPESHELPERS_H
operator+
NvcVec2 operator+(const NvcVec2 &v1, const NvcVec2 &v2)
Definition: NvBlastPxSharedHelpers.h:129
NvcVec4
Definition: NvCTypes.h:55
x
SIMD_FORCE_INLINE const btScalar & x() const
Return the x value.
Definition: btVector3.h:275
NvcVec3::z
float z
Definition: NvCTypes.h:51
NvcPlane
Definition: NvCTypes.h:99
NV_OFFSET_OF
#define NV_OFFSET_OF(X, Y)
Definition: NvPreprocessor.h:450
NvcVec2
Definition: NvCTypes.h:43
NvcMat33
Definition: NvCTypes.h:80
NvcVec3::x
float x
Definition: NvCTypes.h:51
NvcTransform
Definition: NvCTypes.h:67
y
SIMD_FORCE_INLINE const btScalar & y() const
Return the y value.
Definition: btVector3.h:277
dot
float dot(const NvcVec2 &v1, const NvcVec2 &v2)
Definition: NvBlastPxSharedHelpers.h:157
NvcVec2::x
float x
Definition: NvCTypes.h:45
NvcMat44
Definition: NvCTypes.h:86
NvcBounds3
Definition: NvCTypes.h:92
NV_COMPILE_TIME_ASSERT
NV_COMPILE_TIME_ASSERT(sizeof(NvcVec2)==sizeof(physx::PxVec2))
operator/
NvcVec2 operator/(const NvcVec2 &v, float f)
Definition: NvBlastPxSharedHelpers.h:153
operator*
NvcVec2 operator*(const NvcVec2 &v, float f)
Definition: NvBlastPxSharedHelpers.h:145
z
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition: btVector3.h:279
CONVERT
#define CONVERT(BlastType, PxSharedType)
Definition: NvBlastPxSharedHelpers.h:45
w
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btVector3.h:281
operator-
NvcVec2 operator-(const NvcVec2 &v1, const NvcVec2 &v2)
Definition: NvBlastPxSharedHelpers.h:133
NvcVec2::y
float y
Definition: NvCTypes.h:45
NvcVec3
Definition: NvCTypes.h:49
NvcQuat
Definition: NvCTypes.h:61
neg
NvcVec2 neg(const NvcVec2 &v)
Definition: NvBlastPxSharedHelpers.h:161
NvcVec3::y
float y
Definition: NvCTypes.h:51
NvCTypes.h