00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTPXSHAREDTYPESHELPERS_H
00030 #define NVBLASTPXSHAREDTYPESHELPERS_H
00031
00032 #include "NvCTypes.h"
00033 #include <PxVec2.h>
00034 #include <PxVec3.h>
00035 #include <PxVec4.h>
00036 #include <PxTransform.h>
00037 #include <PxPlane.h>
00038 #include <PxMat33.h>
00039 #include <PxMat44.h>
00040 #include <PxBounds3.h>
00041
00042 #define WCast(type, name) reinterpret_cast<type>(name)
00043 #define RCast(type, name) reinterpret_cast<const type>(name)
00044
00045 #define CONVERT(BlastType, PxSharedType) \
00046 static inline PxSharedType& toPxShared(BlastType& v) \
00047 { \
00048 return WCast(PxSharedType&, v); \
00049 } \
00050 static inline const PxSharedType& toPxShared(const BlastType& v) \
00051 { \
00052 return RCast(PxSharedType&, v); \
00053 } \
00054 static inline const BlastType& fromPxShared(const PxSharedType& v) \
00055 { \
00056 return RCast(BlastType&, v); \
00057 } \
00058 static inline BlastType& fromPxShared(PxSharedType& v) \
00059 { \
00060 return WCast(BlastType&, v); \
00061 } \
00062 static inline PxSharedType* toPxShared(BlastType* v) \
00063 { \
00064 return WCast(PxSharedType*, v); \
00065 } \
00066 static inline const PxSharedType* toPxShared(const BlastType* v) \
00067 { \
00068 return RCast(PxSharedType*, v); \
00069 } \
00070 static inline const BlastType* fromPxShared(const PxSharedType* v) \
00071 { \
00072 return RCast(BlastType*, v); \
00073 } \
00074 static inline BlastType* fromPxShared(PxSharedType* v) \
00075 { \
00076 return WCast(BlastType*, v); \
00077 }
00078
00079
00080 CONVERT(NvcVec2, physx::PxVec2)
00081 CONVERT(NvcVec3, physx::PxVec3)
00082 CONVERT(NvcVec4, physx::PxVec4)
00083 CONVERT(NvcQuat, physx::PxQuat)
00084 CONVERT(NvcTransform, physx::PxTransform)
00085 CONVERT(NvcPlane, physx::PxPlane)
00086 CONVERT(NvcMat33, physx::PxMat33)
00087 CONVERT(NvcMat44, physx::PxMat44)
00088 CONVERT(NvcBounds3, physx::PxBounds3)
00089
00090 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec2) == sizeof(physx::PxVec2));
00091 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec2, x) == NV_OFFSET_OF(physx::PxVec2, x));
00092 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec2, y) == NV_OFFSET_OF(physx::PxVec2, y));
00093
00094 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec3) == sizeof(physx::PxVec3));
00095 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, x) == NV_OFFSET_OF(physx::PxVec3, x));
00096 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, y) == NV_OFFSET_OF(physx::PxVec3, y));
00097 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec3, z) == NV_OFFSET_OF(physx::PxVec3, z));
00098
00099 NV_COMPILE_TIME_ASSERT(sizeof(NvcVec4) == sizeof(physx::PxVec4));
00100 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, x) == NV_OFFSET_OF(physx::PxVec4, x));
00101 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, y) == NV_OFFSET_OF(physx::PxVec4, y));
00102 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, z) == NV_OFFSET_OF(physx::PxVec4, z));
00103 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcVec4, w) == NV_OFFSET_OF(physx::PxVec4, w));
00104
00105 NV_COMPILE_TIME_ASSERT(sizeof(NvcQuat) == sizeof(physx::PxQuat));
00106 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, x) == NV_OFFSET_OF(physx::PxQuat, x));
00107 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, y) == NV_OFFSET_OF(physx::PxQuat, y));
00108 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, z) == NV_OFFSET_OF(physx::PxQuat, z));
00109 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcQuat, w) == NV_OFFSET_OF(physx::PxQuat, w));
00110
00111 NV_COMPILE_TIME_ASSERT(sizeof(NvcTransform) == sizeof(physx::PxTransform));
00112 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcTransform, p) == NV_OFFSET_OF(physx::PxTransform, p));
00113 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcTransform, q) == NV_OFFSET_OF(physx::PxTransform, q));
00114
00115 NV_COMPILE_TIME_ASSERT(sizeof(NvcPlane) == sizeof(physx::PxPlane));
00116 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcPlane, n) == NV_OFFSET_OF(physx::PxPlane, n));
00117 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcPlane, d) == NV_OFFSET_OF(physx::PxPlane, d));
00118
00119 NV_COMPILE_TIME_ASSERT(sizeof(NvcMat33) == sizeof(physx::PxMat33));
00120 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column0) == NV_OFFSET_OF(physx::PxMat33, column0));
00121 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column1) == NV_OFFSET_OF(physx::PxMat33, column1));
00122 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcMat33, column2) == NV_OFFSET_OF(physx::PxMat33, column2));
00123
00124 NV_COMPILE_TIME_ASSERT(sizeof(NvcBounds3) == sizeof(physx::PxBounds3));
00125 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcBounds3, minimum) == NV_OFFSET_OF(physx::PxBounds3, minimum));
00126 NV_COMPILE_TIME_ASSERT(NV_OFFSET_OF(NvcBounds3, maximum) == NV_OFFSET_OF(physx::PxBounds3, maximum));
00127
00128
00129 inline NvcVec2 operator+(const NvcVec2& v1, const NvcVec2& v2)
00130 {
00131 return{ v1.x + v2.x, v1.y + v2.y };
00132 }
00133 inline NvcVec2 operator-(const NvcVec2& v1, const NvcVec2& v2)
00134 {
00135 return{ v1.x - v2.x, v1.y - v2.y };
00136 }
00137 inline NvcVec2 operator+(const NvcVec2& v, float f)
00138 {
00139 return{ v.x + f, v.y + f };
00140 }
00141 inline NvcVec2 operator+(float f, const NvcVec2& v)
00142 {
00143 return{ v.x + f, v.y + f };
00144 }
00145 inline NvcVec2 operator*(const NvcVec2& v, float f)
00146 {
00147 return{ v.x * f, v.y * f };
00148 }
00149 inline NvcVec2 operator*(float f, const NvcVec2& v)
00150 {
00151 return{ v.x * f, v.y * f };
00152 }
00153 inline NvcVec2 operator/(const NvcVec2& v, float f)
00154 {
00155 return{ v.x / f, v.y / f };
00156 }
00157 inline float dot(const NvcVec2& v1, const NvcVec2& v2)
00158 {
00159 return v1.x * v2.x + v1.y * v2.y;
00160 }
00161 inline NvcVec2 neg(const NvcVec2& v)
00162 {
00163 return{ -v.x, -v.y };
00164 }
00165
00166 inline NvcVec3 operator+(const NvcVec3& v1, const NvcVec3& v2)
00167 {
00168 return{ v1.x + v2.x, v1.y + v2.y, v1.z + v2.z };
00169 }
00170 inline NvcVec3 operator-(const NvcVec3& v1, const NvcVec3& v2)
00171 {
00172 return{ v1.x - v2.x, v1.y - v2.y, v1.z - v2.z };
00173 }
00174 inline NvcVec3 operator*(const NvcVec3& v1, const NvcVec3& v2)
00175 {
00176 return{ v1.x * v2.x, v1.y * v2.y, v1.z * v2.z };
00177 }
00178 inline NvcVec3 operator/(const NvcVec3& v1, const NvcVec3& v2)
00179 {
00180 return{ v1.x / v2.x, v1.y / v2.y, v1.z / v2.z };
00181 }
00182 inline NvcVec3 operator+(const NvcVec3& v, float f)
00183 {
00184 return{ v.x + f, v.y + f, v.z + f };
00185 }
00186 inline NvcVec3 operator+(float f, const NvcVec3& v)
00187 {
00188 return{ v.x + f, v.y + f, v.z + f };
00189 }
00190 inline NvcVec3 operator*(const NvcVec3& v, float f)
00191 {
00192 return{ v.x * f, v.y * f, v.z * f };
00193 }
00194 inline NvcVec3 operator*(float f, const NvcVec3& v)
00195 {
00196 return{ v.x * f, v.y * f, v.z * f };
00197 }
00198 inline NvcVec3 operator/(const NvcVec3& v, float f)
00199 {
00200 return{ v.x / f, v.y / f, v.z / f };
00201 }
00202 inline float dot(const NvcVec3& v1, const NvcVec3& v2)
00203 {
00204 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
00205 }
00206 inline NvcVec3 neg(const NvcVec3& v)
00207 {
00208 return{ -v.x, -v.y, -v.z };
00209 }
00210
00211 #endif // #ifndef NVBLASTPHYSXTYPESHELPERS_H