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 #ifndef NX_FROM_PX_H
00029 #define NX_FROM_PX_H
00030
00036 #include "NxApexDefs.h"
00037
00038 #if NX_SDK_VERSION_MAJOR == 2
00039 #include "NxVec3.h"
00040 #include "NxMat33.h"
00041 #include "NxMat34.h"
00042 #include "NxStream.h"
00043 #include "NxBounds3.h"
00044
00045 #include "foundation/PxQuat.h"
00046 #include "PxFileBuf.h"
00047 #elif NX_SDK_VERSION_MAJOR == 3
00048 #include "geometry/PxConvexMesh.h"
00049 #include "PxFileBuf.h"
00050 #include "foundation/PxIO.h"
00051 #endif
00052
00053 #include "foundation/PxVec3.h"
00054 #include "foundation/PxBounds3.h"
00055 #include "PxMat33Legacy.h"
00056 #include "PxMat34Legacy.h"
00057
00058 namespace physx
00059 {
00060 namespace apex
00061 {
00062
00063 PX_PUSH_PACK_DEFAULT
00064
00065 #if NX_SDK_VERSION_MAJOR == 2
00066 PX_INLINE void PxFromNxVec3(physx::PxVec3& out, const NxVec3& in)
00067 {
00068 out = physx::PxVec3(in.x, in.y, in.z);
00069 }
00070 PX_INLINE physx::PxVec3 PxFromNxVec3(const NxVec3& in)
00071 {
00072 return physx::PxVec3(in.x, in.y, in.z);
00073 }
00074 PX_INLINE void NxFromPxVec3(NxVec3& out, const physx::PxVec3& in)
00075 {
00076 out.set(in.x, in.y, in.z);
00077 }
00078 PX_INLINE NxVec3 NxFromPxVec3(const physx::PxVec3& in)
00079 {
00080 return NxVec3(in.x, in.y, in.z);
00081 }
00082 PX_INLINE void PxFromNxQuat(physx::PxQuat& out, const NxQuat& in)
00083 {
00084 out = physx::PxQuat(in.x, in.y, in.z, in.w);
00085 }
00086 PX_INLINE void NxFromPxQuat(NxQuat& out, const physx::PxQuat& in)
00087 {
00088 out.setXYZW(in.x, in.y, in.z, in.w);
00089 }
00090 PX_INLINE void PxFromNxMat33(physx::PxMat33Legacy& out, const NxMat33& in)
00091 {
00092 physx::PxF32 buf[9];
00093 in.getRowMajor(buf);
00094 out.setRowMajor(buf);
00095 }
00096 PX_INLINE void PxFromNxMat33(physx::PxMat33& out, const NxMat33& in)
00097 {
00098 physx::PxF32 buf[9];
00099 in.getRowMajor(buf);
00100 out = physx::PxMat33(buf);
00101 }
00102 PX_INLINE void NxFromPxMat33(NxMat33& out, const physx::PxMat33Legacy& in)
00103 {
00104 physx::PxF32 buf[9];
00105 in.getRowMajor(buf);
00106 out.setRowMajor(buf);
00107 }
00108 PX_INLINE void PxFromNxMat34(physx::PxMat34Legacy& out, const NxMat34& in)
00109 {
00110 PxFromNxMat33(out.M, in.M);
00111 PxFromNxVec3(out.t, in.t);
00112 }
00113
00114 PX_INLINE void PxFromNxMat34(physx::PxMat44& out, const NxMat34& in)
00115 {
00116 physx::PxMat34Legacy tmp;
00117 PxFromNxMat34(tmp, in);
00118 out = physx::PxMat44(tmp);
00119 }
00120 PX_INLINE void NxFromPxMat34(NxMat34& out, const physx::PxMat34Legacy& in)
00121 {
00122 NxFromPxMat33(out.M, in.M);
00123 NxFromPxVec3(out.t, in.t);
00124 }
00125 PX_INLINE void PxFromNxBounds3(physx::PxBounds3& out, const NxBounds3& in)
00126 {
00127 PxFromNxVec3(out.minimum, in.min);
00128 PxFromNxVec3(out.maximum, in.max);
00129 }
00130 PX_INLINE void NxFromPxBounds3(NxBounds3& out, const physx::PxBounds3& in)
00131 {
00132 NxFromPxVec3(out.min, in.minimum);
00133 NxFromPxVec3(out.max, in.maximum);
00134 }
00135 PX_INLINE void ArrayFromPxQuat(physx::PxF32 arr[4], const physx::PxQuat& q)
00136 {
00137 arr[0] = q.x;
00138 arr[1] = q.y;
00139 arr[2] = q.z;
00140 arr[3] = q.w;
00141 }
00142
00143 PX_INLINE NxVec3& NxFromPxVec3Fast(physx::PxVec3& in)
00144 {
00145 return reinterpret_cast<NxVec3&>(in);
00146 }
00147 PX_INLINE const NxVec3& NxFromPxVec3Fast(const physx::PxVec3& in)
00148 {
00149 return reinterpret_cast<const NxVec3&>(in);
00150 }
00151 PX_INLINE physx::PxVec3& PxFromNxVec3Fast(NxVec3& in)
00152 {
00153 return reinterpret_cast<physx::PxVec3&>(in);
00154 }
00155 PX_INLINE const physx::PxVec3& PxFromNxVec3Fast(const NxVec3& in)
00156 {
00157 return reinterpret_cast<const physx::PxVec3&>(in);
00158 }
00159 PX_INLINE NxQuat& NxFromPxQuatFast(physx::PxQuat& in)
00160 {
00161 return reinterpret_cast<NxQuat&>(in);
00162 }
00163 PX_INLINE const NxQuat& NxFromPxQuatFast(const physx::PxQuat& in)
00164 {
00165 return reinterpret_cast<const NxQuat&>(in);
00166 }
00167 PX_INLINE physx::PxQuat& PxFromNxQuatFast(NxQuat& in)
00168 {
00169 return reinterpret_cast<physx::PxQuat&>(in);
00170 }
00171 PX_INLINE const physx::PxQuat& PxFromNxQuatFast(const NxQuat& in)
00172 {
00173 return reinterpret_cast<const physx::PxQuat&>(in);
00174 }
00175 PX_INLINE void NxFromPxMat44(NxMat34& out, const physx::PxMat44& in)
00176 {
00177 out.setColumnMajor44(in.front());
00178 }
00179
00180 #define PXFROMNXVEC3(nxv) physx::PxVec3((nxv).x, (nxv).y, (nxv).z)
00181 #define NXFROMPXVEC3(pxv) NxVec3((pxv).x, (pxv).y, (pxv).z)
00182
00183 #endif // NX_SDK_VERSION_MAJOR == 2
00184
00185
00189 class NxFromPxStream :
00190 #if NX_SDK_VERSION_MAJOR == 2
00191 public NxStream
00192 #elif NX_SDK_VERSION_MAJOR == 3
00193 public physx::PxInputStream, public physx::PxOutputStream
00194 #endif
00195 {
00196 private:
00197 physx::general_PxIOStream2::PxFileBuf& mPx;
00198 NxFromPxStream& operator=(const NxFromPxStream&)
00199 {
00200 return *this;
00201 }
00202
00203 public:
00205 NxFromPxStream(physx::general_PxIOStream2::PxFileBuf& px) : mPx(px) {}
00206
00207 #if NX_SDK_VERSION_MAJOR == 2
00208
00209 physx::PxU8 readByte() const
00210 {
00211 return mPx.readByte();
00212 }
00213
00215 physx::PxU16 readWord() const
00216 {
00217 return mPx.readWord();
00218 }
00219
00221 physx::PxU32 readDword() const
00222 {
00223 return mPx.readDword();
00224 }
00225
00227 physx::PxF32 readFloat() const
00228 {
00229 return mPx.readFloat();
00230 }
00231
00233 physx::PxF64 readDouble() const
00234 {
00235 return mPx.readDouble();
00236 }
00237
00239 void readBuffer(void* buffer, physx::PxU32 size) const
00240 {
00241 mPx.read(buffer, size);
00242 }
00243
00245 NxStream& storeByte(physx::PxU8 b)
00246 {
00247 mPx.storeByte(b);
00248 return *this;
00249 }
00250
00252 NxStream& storeWord(physx::PxU16 w)
00253 {
00254 mPx.storeWord(w);
00255 return *this;
00256 }
00257
00259 NxStream& storeDword(physx::PxU32 d)
00260 {
00261 mPx.storeDword(d);
00262 return *this;
00263 }
00264
00266 NxStream& storeFloat(physx::PxF32 f)
00267 {
00268 mPx.storeFloat(f);
00269 return *this;
00270 }
00271
00273 NxStream& storeDouble(physx::PxF64 f)
00274 {
00275 mPx.storeDouble(f);
00276 return *this;
00277 }
00278
00280 NxStream& storeBuffer(const void* buffer, physx::PxU32 size)
00281 {
00282 mPx.write(buffer, size);
00283 return *this;
00284 }
00285
00286 #endif
00287
00289 physx::PxU32 read(void* dest, PxU32 count)
00290 {
00291 return mPx.read(dest, count);
00292 }
00293
00295 physx::PxU32 write(const void* src, PxU32 count)
00296 {
00297 return mPx.write(src, count);
00298 }
00299 };
00300
00301
00303 PX_INLINE void PxBounds3boundsOfOBB(physx::PxBounds3& b, const physx::PxMat33Legacy& orientation, const physx::PxVec3& translation, const physx::PxVec3& halfDims)
00304 {
00305 physx::PxF32 dimx = halfDims[0];
00306 physx::PxF32 dimy = halfDims[1];
00307 physx::PxF32 dimz = halfDims[2];
00308
00309 physx::PxF32 x = abs(orientation(0, 0) * dimx) + abs(orientation(0, 1) * dimy) + abs(orientation(0, 2) * dimz);
00310 physx::PxF32 y = abs(orientation(1, 0) * dimx) + abs(orientation(1, 1) * dimy) + abs(orientation(1, 2) * dimz);
00311 physx::PxF32 z = abs(orientation(2, 0) * dimx) + abs(orientation(2, 1) * dimy) + abs(orientation(2, 2) * dimz);
00312
00313 physx::PxVec3 minimum(-x + translation[0], -y + translation[1], -z + translation[2]);
00314 physx::PxVec3 maximum(x + translation[0], y + translation[1], z + translation[2]);
00315 b = physx::PxBounds3(minimum, maximum);
00316 }
00317
00319 PX_INLINE void PxBounds3Transform(physx::PxBounds3& b, const physx::PxMat33Legacy& orientation, const physx::PxVec3& translation)
00320 {
00321
00322 physx::PxVec3 center, extents;
00323 center = b.getCenter();
00324 extents = b.getExtents();
00325
00326 center = orientation * center + translation;
00327 PxBounds3boundsOfOBB(b, orientation, center, extents);
00328 }
00329
00331 PX_INLINE void PxBounds3boundsOfOBB(physx::PxBounds3& b, const physx::PxMat44& tm, const physx::PxVec3& center, const physx::PxVec3& halfDims)
00332 {
00333 physx::PxF32 dimx = halfDims[0];
00334 physx::PxF32 dimy = halfDims[1];
00335 physx::PxF32 dimz = halfDims[2];
00336
00337 physx::PxF32 x = abs(tm(0, 0) * dimx) + abs(tm(0, 1) * dimy) + abs(tm(0, 2) * dimz);
00338 physx::PxF32 y = abs(tm(1, 0) * dimx) + abs(tm(1, 1) * dimy) + abs(tm(1, 2) * dimz);
00339 physx::PxF32 z = abs(tm(2, 0) * dimx) + abs(tm(2, 1) * dimy) + abs(tm(2, 2) * dimz);
00340
00341 physx::PxVec3 minimum(-x + center[0], -y + center[1], -z + center[2]);
00342 physx::PxVec3 maximum(x + center[0], y + center[1], z + center[2]);
00343 b = physx::PxBounds3(minimum, maximum);
00344 }
00345
00347 PX_INLINE void PxBounds3Transform(physx::PxBounds3& b, const physx::PxMat44& tm)
00348 {
00349
00350 physx::PxVec3 center, extents;
00351 center = b.getCenter();
00352 extents = b.getExtents();
00353
00354 center = tm.transform(center);
00355 PxBounds3boundsOfOBB(b, tm, center, extents);
00356 }
00357
00359 PX_INLINE bool PxVec3equals(const physx::PxVec3& a, const physx::PxVec3& v, physx::PxF32 epsilon)
00360 {
00361 return
00362 physx::PxEquals(a.x, v.x, epsilon) &&
00363 physx::PxEquals(a.y, v.y, epsilon) &&
00364 physx::PxEquals(a.z, v.z, epsilon);
00365 }
00366
00368 PX_INLINE void PxVec3FromArray(physx::PxVec3& out, const physx::PxF32 arr[3])
00369 {
00370 out = physx::PxVec3(arr[0], arr[1], arr[2]);
00371 }
00372
00374 PX_INLINE void PxVec3FromArray(physx::PxVec3& out, const physx::PxF64 arr[3])
00375 {
00376 out = physx::PxVec3((physx::PxF32)arr[0], (physx::PxF32)arr[1], (physx::PxF32)arr[2]);
00377 }
00378
00380 PX_INLINE void PxQuatFromArray(physx::PxQuat& out, const physx::PxF32 arr[4])
00381 {
00382 out.x = arr[0];
00383 out.y = arr[1];
00384 out.z = arr[2];
00385 out.w = arr[3];
00386 }
00387
00388 PX_POP_PACK
00389
00390 }
00391 }
00392
00393 #endif // NX_FROM_PX_H