Init
This commit is contained in:
57
physx/samples/pxtoolkit/include/PxTkBmpLoader.h
Normal file
57
physx/samples/pxtoolkit/include/PxTkBmpLoader.h
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_BMP_LOADER_H
|
||||
#define PX_TOOLKIT_BMP_LOADER_H
|
||||
|
||||
#include "extensions/PxDefaultStreams.h"
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
|
||||
class BmpLoader
|
||||
{
|
||||
public:
|
||||
|
||||
BmpLoader(void);
|
||||
~BmpLoader(void);
|
||||
|
||||
// returns true if success. Data is persists until the class is destructed.
|
||||
bool loadBmp(const char* filename);
|
||||
bool loadBmp(PxFileHandle f);
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
unsigned char* mRGB;
|
||||
bool mHasAlpha;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
61
physx/samples/pxtoolkit/include/PxTkFPS.h
Normal file
61
physx/samples/pxtoolkit/include/PxTkFPS.h
Normal file
@ -0,0 +1,61 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_FPS_H
|
||||
#define PX_TOOLKIT_FPS_H
|
||||
|
||||
#include "common/PxPhysXCommonConfig.h"
|
||||
#include "PsTime.h"
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
using namespace physx;
|
||||
|
||||
class FPS
|
||||
{
|
||||
public:
|
||||
FPS();
|
||||
~FPS();
|
||||
|
||||
void update();
|
||||
PX_FORCE_INLINE float getFPS() const { return mFPS; }
|
||||
PX_FORCE_INLINE float getInstantFPS() const { return mInstantFPS; }
|
||||
|
||||
private:
|
||||
shdfnd::Time mTimer;
|
||||
shdfnd::Time mTimer2;
|
||||
PxReal mFPS;
|
||||
PxReal mInstantFPS;
|
||||
PxU32 mFrames;
|
||||
PxU32 mFrames2;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
86
physx/samples/pxtoolkit/include/PxTkFile.h
Normal file
86
physx/samples/pxtoolkit/include/PxTkFile.h
Normal file
@ -0,0 +1,86 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
|
||||
#ifndef PX_TOOLKIT_FILE_H
|
||||
#define PX_TOOLKIT_FILE_H
|
||||
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
// fopen_s - returns 0 on success, non-zero on failure
|
||||
|
||||
#if PX_MICROSOFT_FAMILY
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
|
||||
PX_INLINE physx::PxI32 fopen_s(FILE** file, const char* name, const char* mode)
|
||||
{
|
||||
static const physx::PxU32 MAX_LEN = 300;
|
||||
char buf[MAX_LEN+1];
|
||||
|
||||
physx::PxU32 i;
|
||||
for(i = 0; i<MAX_LEN && name[i]; i++)
|
||||
buf[i] = name[i] == '/' ? '\\' : name[i];
|
||||
buf[i] = 0;
|
||||
|
||||
return i == MAX_LEN ? -1 : ::fopen_s(file, buf, mode);
|
||||
};
|
||||
|
||||
} // namespace PxToolkit
|
||||
|
||||
#elif PX_UNIX_FAMILY || PX_PS4 || PX_SWITCH
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
|
||||
PX_INLINE physx::PxI32 fopen_s(FILE** file, const char* name, const char* mode)
|
||||
{
|
||||
FILE* fp = ::fopen(name, mode);
|
||||
if (fp)
|
||||
{
|
||||
*file = fp;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // PxToolkit
|
||||
|
||||
#else
|
||||
|
||||
#error "Platform not supported!"
|
||||
|
||||
#endif
|
||||
|
||||
#endif //PX_TOOLKIT_FILE_H
|
||||
|
||||
48
physx/samples/pxtoolkit/include/PxTkMatrixUtils.h
Normal file
48
physx/samples/pxtoolkit/include/PxTkMatrixUtils.h
Normal file
@ -0,0 +1,48 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_MATRIX_UTILS_H
|
||||
#define PX_TOOLKIT_MATRIX_UTILS_H
|
||||
|
||||
#include "common/PxPhysXCommonConfig.h"
|
||||
#include "foundation/PxMat33.h"
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
using namespace physx;
|
||||
void setRotX(PxMat33& m, PxReal angle);
|
||||
void setRotY(PxMat33& m, PxReal angle);
|
||||
void setRotZ(PxMat33& m, PxReal angle);
|
||||
|
||||
PxQuat getRotXQuat(float angle);
|
||||
PxQuat getRotYQuat(float angle);
|
||||
PxQuat getRotZQuat(float angle);
|
||||
}
|
||||
|
||||
#endif
|
||||
39
physx/samples/pxtoolkit/include/PxTkNamespaceMangle.h
Normal file
39
physx/samples/pxtoolkit/include/PxTkNamespaceMangle.h
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_NAMESPACE_MANGLE_H
|
||||
#define PX_TOOLKIT_NAMESPACE_MANGLE_H
|
||||
#include "Ps.h"
|
||||
|
||||
namespace physx {
|
||||
namespace Ps = shdfnd;
|
||||
// we need this until all our code lives in physx namespace
|
||||
}
|
||||
|
||||
#endif
|
||||
137
physx/samples/pxtoolkit/include/PxTkRandom.h
Normal file
137
physx/samples/pxtoolkit/include/PxTkRandom.h
Normal file
@ -0,0 +1,137 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_RANDOM_H
|
||||
#define PX_TOOLKIT_RANDOM_H
|
||||
|
||||
#include "common/PxPhysXCommonConfig.h"
|
||||
#define TEST_MAX_RAND 0xffff
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
using namespace physx;
|
||||
|
||||
class BasicRandom
|
||||
{
|
||||
public:
|
||||
BasicRandom(PxU32 seed=0) : mRnd(seed) {}
|
||||
~BasicRandom() {}
|
||||
|
||||
PX_FORCE_INLINE void setSeed(PxU32 seed) { mRnd = seed; }
|
||||
PX_FORCE_INLINE PxU32 getCurrentValue() const { return mRnd; }
|
||||
PxU32 randomize() { mRnd = mRnd * 2147001325 + 715136305; return mRnd; }
|
||||
|
||||
PX_FORCE_INLINE PxU32 rand() { return randomize() & 0xffff; }
|
||||
PX_FORCE_INLINE PxU32 rand32() { return randomize() & 0xffffffff; }
|
||||
|
||||
PxF32 rand(PxF32 a, PxF32 b)
|
||||
{
|
||||
const PxF32 r = rand32()/(static_cast<PxF32>(0xffffffff));
|
||||
return r*(b-a) + a;
|
||||
}
|
||||
|
||||
PxI32 rand(PxI32 a, PxI32 b)
|
||||
{
|
||||
return a + static_cast<PxI32>(rand32()%(b-a));
|
||||
}
|
||||
|
||||
PxF32 randomFloat()
|
||||
{
|
||||
return rand()/(static_cast<PxF32>(0xffff)) - 0.5f;
|
||||
}
|
||||
PxF32 randomFloat32()
|
||||
{
|
||||
return rand32()/(static_cast<PxF32>(0xffffffff)) - 0.5f;
|
||||
}
|
||||
|
||||
PxF32 randomFloat32(PxReal a, PxReal b) { return rand32()/PxF32(0xffffffff)*(b-a)+a; }
|
||||
void unitRandomPt(physx::PxVec3& v);
|
||||
void unitRandomQuat(physx::PxQuat& v);
|
||||
|
||||
PxVec3 unitRandomPt();
|
||||
PxQuat unitRandomQuat();
|
||||
|
||||
private:
|
||||
PxU32 mRnd;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
// Fast, very good random numbers
|
||||
//
|
||||
// Period = 2^249
|
||||
//
|
||||
// Kirkpatrick, S., and E. Stoll, 1981; A Very Fast Shift-Register
|
||||
// Sequence Random Number Generator, Journal of Computational Physics,
|
||||
// V. 40.
|
||||
//
|
||||
// Maier, W.L., 1991; A Fast Pseudo Random Number Generator,
|
||||
// Dr. Dobb's Journal, May, pp. 152 - 157
|
||||
|
||||
class RandomR250
|
||||
{
|
||||
public:
|
||||
RandomR250(PxI32 s);
|
||||
|
||||
void setSeed(PxI32 s);
|
||||
PxU32 randI();
|
||||
PxReal randUnit();
|
||||
|
||||
PxReal rand(PxReal lower, PxReal upper)
|
||||
{
|
||||
return lower + randUnit() * (upper - lower);
|
||||
}
|
||||
|
||||
private:
|
||||
PxU32 mBuffer[250];
|
||||
PxI32 mIndex;
|
||||
};
|
||||
|
||||
void SetSeed(PxU32 seed);
|
||||
PxU32 Rand();
|
||||
|
||||
PX_INLINE PxF32 Rand(PxF32 a,PxF32 b)
|
||||
{
|
||||
const PxF32 r = static_cast<PxF32>(Rand())/(static_cast<PxF32>(TEST_MAX_RAND));
|
||||
return r*(b-a) + a;
|
||||
}
|
||||
|
||||
PX_INLINE PxF32 RandLegacy(PxF32 a,PxF32 b)
|
||||
{
|
||||
const PxF32 r = static_cast<PxF32>(Rand())/(static_cast<PxF32>(0x7fff)+1.0f);
|
||||
return r*(b-a) + a;
|
||||
}
|
||||
|
||||
//returns numbers from [a, b-1]
|
||||
PX_INLINE PxI32 Rand(PxI32 a,PxI32 b)
|
||||
{
|
||||
return a + static_cast<PxI32>(Rand()%(b-a));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
60
physx/samples/pxtoolkit/include/PxTkStream.h
Normal file
60
physx/samples/pxtoolkit/include/PxTkStream.h
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#ifndef PX_TOOLKIT_STREAM_H
|
||||
#define PX_TOOLKIT_STREAM_H
|
||||
|
||||
#include "extensions/PxDefaultStreams.h"
|
||||
|
||||
#include "cooking/PxCooking.h"
|
||||
namespace physx
|
||||
{
|
||||
class PxTriangleMesh;
|
||||
class PxConvexMesh;
|
||||
class PxPhysics;
|
||||
class PxCooking;
|
||||
class PxTriangleMeshDesc;
|
||||
}
|
||||
|
||||
namespace PxToolkit
|
||||
{
|
||||
using namespace physx;
|
||||
|
||||
// temporarily located here
|
||||
physx::PxTriangleMesh* createTriangleMesh32(physx::PxPhysics& physics, physx::PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, const PxU32* indices32, PxU32 triCount, bool insert = false);
|
||||
physx::PxConvexMesh* createConvexMesh(physx::PxPhysics& physics, physx::PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags);
|
||||
physx::PxConvexMesh* createConvexMeshSafe(physx::PxPhysics& physics, physx::PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags, PxU32 vLimit = 256);
|
||||
|
||||
//this function is for MultiMaterial and MultiMaterialTerrain
|
||||
physx::PxTriangleMesh* createTriangleMesh32(physx::PxPhysics& physics, physx::PxCooking& cooking, physx::PxTriangleMeshDesc* meshDesc, bool insert = false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
34
physx/samples/pxtoolkit/include/PxToolkit.h
Normal file
34
physx/samples/pxtoolkit/include/PxToolkit.h
Normal file
@ -0,0 +1,34 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "PxTkRandom.h"
|
||||
#include "PxTkFPS.h"
|
||||
#include "PxTkStream.h"
|
||||
#include "PxTkBmpLoader.h"
|
||||
#include "PxTkMatrixUtils.h"
|
||||
200
physx/samples/pxtoolkit/src/PxTkBmpLoader.cpp
Normal file
200
physx/samples/pxtoolkit/src/PxTkBmpLoader.cpp
Normal file
@ -0,0 +1,200 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include "PxTkBmpLoader.h"
|
||||
#include "PxTkFile.h"
|
||||
|
||||
|
||||
using namespace PxToolkit;
|
||||
|
||||
#define MAKETWOCC(a,b) ( (static_cast<char>(a)) | ((static_cast<char>(b))<< 8) )
|
||||
|
||||
static bool isBigEndian() { int i = 1; return *(reinterpret_cast<char*>(&i))==0; }
|
||||
|
||||
static unsigned short endianSwap(unsigned short nValue)
|
||||
{
|
||||
return (((nValue>> 8)) | (nValue << 8));
|
||||
|
||||
}
|
||||
|
||||
static unsigned int endianSwap(unsigned int i)
|
||||
{
|
||||
unsigned char b1, b2, b3, b4;
|
||||
|
||||
b1 = i & 255;
|
||||
b2 = ( i >> 8 ) & 255;
|
||||
b3 = ( i>>16 ) & 255;
|
||||
b4 = ( i>>24 ) & 255;
|
||||
|
||||
return (static_cast<unsigned int>(b1) << 24) + (static_cast<unsigned int>(b2) << 16) + (static_cast<unsigned int>(b3) << 8) + b4;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
struct BMPHEADER {
|
||||
unsigned short Type;
|
||||
unsigned int Size;
|
||||
unsigned short Reserved1;
|
||||
unsigned short Reserved2;
|
||||
unsigned int OffBits;
|
||||
};
|
||||
|
||||
// Only Win3.0 BMPINFO (see later for OS/2)
|
||||
struct BMPINFO {
|
||||
unsigned int Size;
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
unsigned short Planes;
|
||||
unsigned short BitCount;
|
||||
unsigned int Compression;
|
||||
unsigned int SizeImage;
|
||||
unsigned int XPelsPerMeter;
|
||||
unsigned int YPelsPerMeter;
|
||||
unsigned int ClrUsed;
|
||||
unsigned int ClrImportant;
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
// Compression Type
|
||||
#define BI_RGB 0L
|
||||
#define BI_RLE8 1L
|
||||
#define BI_RLE4 2L
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
BmpLoader::BmpLoader() :
|
||||
mWidth (0),
|
||||
mHeight (0),
|
||||
mRGB (NULL),
|
||||
mHasAlpha (false)
|
||||
{
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
BmpLoader::~BmpLoader()
|
||||
{
|
||||
if (mRGB) free(mRGB);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
bool BmpLoader::loadBmp(PxFileHandle f)
|
||||
{
|
||||
if (!f) return false;
|
||||
|
||||
if (mRGB) {
|
||||
free(mRGB);
|
||||
mRGB = NULL;
|
||||
}
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
|
||||
size_t num;
|
||||
BMPHEADER header;
|
||||
num = fread(&header, 1, sizeof(BMPHEADER), f);
|
||||
if(isBigEndian()) header.Type = endianSwap(header.Type);
|
||||
if (num != sizeof(BMPHEADER)) { fclose(f); return false; }
|
||||
if (header.Type != MAKETWOCC('B','M')) { fclose(f); return false; }
|
||||
|
||||
BMPINFO info;
|
||||
num = fread(&info, 1, sizeof(BMPINFO), f);
|
||||
if (num != sizeof(BMPINFO)) { fclose(f); return false; }
|
||||
if(isBigEndian()) info.Size = endianSwap(info.Size);
|
||||
if(isBigEndian()) info.BitCount = endianSwap(info.BitCount);
|
||||
if(isBigEndian()) info.Compression = endianSwap(info.Compression);
|
||||
if(isBigEndian()) info.Width = endianSwap(info.Width);
|
||||
if(isBigEndian()) info.Height = endianSwap(info.Height);
|
||||
|
||||
if (info.Size != sizeof(BMPINFO)) { fclose(f); return false; }
|
||||
if (info.BitCount != 24 && info.BitCount != 32) { fclose(f); return false; }
|
||||
if (info.Compression != BI_RGB) { fclose(f); return false; }
|
||||
|
||||
mWidth = info.Width;
|
||||
mHeight = info.Height;
|
||||
|
||||
int bytesPerPixel = 0;
|
||||
if(info.BitCount == 24)
|
||||
{
|
||||
mHasAlpha = false;
|
||||
bytesPerPixel = 3;
|
||||
}
|
||||
else if(info.BitCount == 32)
|
||||
{
|
||||
mHasAlpha = true;
|
||||
bytesPerPixel = 4;
|
||||
}
|
||||
else assert(0);
|
||||
|
||||
mRGB = static_cast<unsigned char*>(malloc(mWidth * mHeight * bytesPerPixel));
|
||||
|
||||
int lineLen = (((info.Width * (info.BitCount>>3)) + 3)>>2)<<2;
|
||||
unsigned char* line = static_cast<unsigned char*>(malloc(lineLen));
|
||||
|
||||
for(int i = info.Height-1; i >= 0; i--)
|
||||
{
|
||||
num = fread(line, 1, static_cast<size_t>(lineLen), f);
|
||||
if (num != static_cast<size_t>(lineLen))
|
||||
{
|
||||
fclose(f);
|
||||
free(line);
|
||||
return false;
|
||||
}
|
||||
unsigned char* src = line;
|
||||
unsigned char* dest = mRGB + i*info.Width*bytesPerPixel;
|
||||
for(unsigned int j = 0; j < info.Width; j++)
|
||||
{
|
||||
unsigned char b = *src++;
|
||||
unsigned char g = *src++;
|
||||
unsigned char r = *src++;
|
||||
unsigned char a = mHasAlpha ? *src++ : 0;
|
||||
*dest++ = r;
|
||||
*dest++ = g;
|
||||
*dest++ = b;
|
||||
if(mHasAlpha)
|
||||
*dest++ = a;
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
bool BmpLoader::loadBmp(const char *filename)
|
||||
{
|
||||
PxFileHandle f = NULL;
|
||||
PxToolkit::fopen_s(&f, filename, "rb");
|
||||
bool ret = loadBmp(f);
|
||||
if(f) fclose(f);
|
||||
return ret;
|
||||
}
|
||||
69
physx/samples/pxtoolkit/src/PxTkFPS.cpp
Normal file
69
physx/samples/pxtoolkit/src/PxTkFPS.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "PxTkFPS.h"
|
||||
|
||||
using namespace PxToolkit;
|
||||
|
||||
FPS::FPS()
|
||||
{
|
||||
mFrames = 0;
|
||||
mFrames2 = 0;
|
||||
mFPS = 0.0f;
|
||||
mInstantFPS = 0.0f;
|
||||
}
|
||||
|
||||
FPS::~FPS()
|
||||
{
|
||||
}
|
||||
|
||||
void FPS::update()
|
||||
{
|
||||
// Keep track of the time lapse and frame count
|
||||
mFrames++;
|
||||
mFrames2++;
|
||||
|
||||
// Instant frame rate
|
||||
PxReal Delta = PxReal(mTimer2.peekElapsedSeconds());
|
||||
if(Delta > 0.01f)
|
||||
{
|
||||
mInstantFPS = PxReal(mFrames2) / Delta;
|
||||
mTimer2.getElapsedSeconds();
|
||||
mFrames2 = 0;
|
||||
}
|
||||
|
||||
// Update the frame rate once per second
|
||||
Delta = PxReal(mTimer.peekElapsedSeconds());
|
||||
if(Delta > 1.0f)
|
||||
{
|
||||
mFPS = PxReal(mFrames) / Delta;
|
||||
mTimer.getElapsedSeconds();
|
||||
mFrames = 0;
|
||||
}
|
||||
}
|
||||
89
physx/samples/pxtoolkit/src/PxTkMatrixUtils.cpp
Normal file
89
physx/samples/pxtoolkit/src/PxTkMatrixUtils.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "PxTkMatrixUtils.h"
|
||||
|
||||
using namespace PxToolkit;
|
||||
|
||||
void PxToolkit::setRotX(PxMat33& m, PxReal angle)
|
||||
{
|
||||
m = PxMat33(PxIdentity);
|
||||
|
||||
const PxReal cos = cosf(angle);
|
||||
const PxReal sin = sinf(angle);
|
||||
|
||||
m[1][1] = m[2][2] = cos;
|
||||
m[1][2] = sin;
|
||||
m[2][1] = -sin;
|
||||
}
|
||||
|
||||
void PxToolkit::setRotY(PxMat33& m, PxReal angle)
|
||||
{
|
||||
m = PxMat33(PxIdentity);
|
||||
|
||||
const PxReal cos = cosf(angle);
|
||||
const PxReal sin = sinf(angle);
|
||||
|
||||
m[0][0] = m[2][2] = cos;
|
||||
m[0][2] = -sin;
|
||||
m[2][0] = sin;
|
||||
}
|
||||
|
||||
void PxToolkit::setRotZ(PxMat33& m, PxReal angle)
|
||||
{
|
||||
m = PxMat33(PxIdentity);
|
||||
|
||||
const PxReal cos = cosf(angle);
|
||||
const PxReal sin = sinf(angle);
|
||||
|
||||
m[0][0] = m[1][1] = cos;
|
||||
m[0][1] = sin;
|
||||
m[1][0] = -sin;
|
||||
}
|
||||
|
||||
PxQuat PxToolkit::getRotXQuat(float angle)
|
||||
{
|
||||
PxMat33 m;
|
||||
setRotX(m, angle);
|
||||
return PxQuat(m);
|
||||
}
|
||||
|
||||
PxQuat PxToolkit::getRotYQuat(float angle)
|
||||
{
|
||||
PxMat33 m;
|
||||
setRotY(m, angle);
|
||||
return PxQuat(m);
|
||||
}
|
||||
|
||||
PxQuat PxToolkit::getRotZQuat(float angle)
|
||||
{
|
||||
PxMat33 m;
|
||||
setRotZ(m, angle);
|
||||
return PxQuat(m);
|
||||
}
|
||||
141
physx/samples/pxtoolkit/src/PxTkRandom.cpp
Normal file
141
physx/samples/pxtoolkit/src/PxTkRandom.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "PxTkRandom.h"
|
||||
#include "foundation/PxQuat.h"
|
||||
|
||||
using namespace physx;
|
||||
using namespace PxToolkit;
|
||||
|
||||
static RandomR250 gRandomR250(0x95d6739b);
|
||||
|
||||
PxVec3 BasicRandom::unitRandomPt()
|
||||
{
|
||||
PxVec3 v;
|
||||
do
|
||||
{
|
||||
v.x = randomFloat();
|
||||
v.y = randomFloat();
|
||||
v.z = randomFloat();
|
||||
}
|
||||
while(v.normalize()<1e-6f);
|
||||
return v;
|
||||
}
|
||||
|
||||
PxQuat BasicRandom::unitRandomQuat()
|
||||
{
|
||||
PxQuat v;
|
||||
do
|
||||
{
|
||||
v.x = randomFloat();
|
||||
v.y = randomFloat();
|
||||
v.z = randomFloat();
|
||||
v.w = randomFloat();
|
||||
}
|
||||
while(v.normalize()<1e-6f);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
void BasicRandom::unitRandomPt(PxVec3& v)
|
||||
{
|
||||
v = unitRandomPt();
|
||||
}
|
||||
void BasicRandom::unitRandomQuat(PxQuat& v)
|
||||
{
|
||||
v = unitRandomQuat();
|
||||
}
|
||||
|
||||
|
||||
void PxToolkit::SetSeed(PxU32 seed)
|
||||
{
|
||||
gRandomR250.setSeed(seed);
|
||||
}
|
||||
|
||||
PxU32 PxToolkit::Rand()
|
||||
{
|
||||
return gRandomR250.randI() & TEST_MAX_RAND;
|
||||
}
|
||||
|
||||
|
||||
RandomR250::RandomR250(PxI32 s)
|
||||
{
|
||||
setSeed(s);
|
||||
}
|
||||
|
||||
void RandomR250::setSeed(PxI32 s)
|
||||
{
|
||||
BasicRandom lcg(s);
|
||||
mIndex = 0;
|
||||
|
||||
PxI32 j;
|
||||
for (j = 0; j < 250; j++) // fill r250 buffer with bit values
|
||||
mBuffer[j] = lcg.randomize();
|
||||
|
||||
for (j = 0; j < 250; j++) // set some MSBs to 1
|
||||
if ( lcg.randomize() > 0x40000000L )
|
||||
mBuffer[j] |= 0x80000000L;
|
||||
|
||||
PxU32 msb = 0x80000000; // turn on diagonal bit
|
||||
PxU32 mask = 0xffffffff; // turn off the leftmost bits
|
||||
|
||||
for (j = 0; j < 32; j++)
|
||||
{
|
||||
const PxI32 k = 7 * j + 3; // select a word to operate on
|
||||
mBuffer[k] &= mask; // turn off bits left of the diagonal
|
||||
mBuffer[k] |= msb; // turn on the diagonal bit
|
||||
mask >>= 1;
|
||||
msb >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
PxU32 RandomR250::randI()
|
||||
{
|
||||
PxI32 j;
|
||||
|
||||
// wrap pointer around
|
||||
if ( mIndex >= 147 ) j = mIndex - 147;
|
||||
else j = mIndex + 103;
|
||||
|
||||
const PxU32 new_rand = mBuffer[ mIndex ] ^ mBuffer[ j ];
|
||||
mBuffer[ mIndex ] = new_rand;
|
||||
|
||||
// increment pointer for next time
|
||||
if ( mIndex >= 249 ) mIndex = 0;
|
||||
else mIndex++;
|
||||
|
||||
return new_rand >> 1;
|
||||
}
|
||||
|
||||
PxReal RandomR250::randUnit()
|
||||
{
|
||||
PxU32 mask = (1<<23)-1;
|
||||
return PxF32(randI()&(mask))/PxF32(mask);
|
||||
}
|
||||
149
physx/samples/pxtoolkit/src/PxTkStream.cpp
Normal file
149
physx/samples/pxtoolkit/src/PxTkStream.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of NVIDIA CORPORATION nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
|
||||
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
|
||||
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
|
||||
|
||||
#include "PxTkStream.h"
|
||||
#include "foundation/PxAssert.h"
|
||||
#include "PxTkFile.h"
|
||||
#include "PxTkNamespaceMangle.h"
|
||||
#include "PsIntrinsics.h"
|
||||
#include "foundation/PxMath.h"
|
||||
#include "PxPhysics.h"
|
||||
#include "geometry/PxConvexMesh.h"
|
||||
#include "cooking/PxCooking.h"
|
||||
#include "foundation/PxBounds3.h"
|
||||
#include "extensions/PxDefaultStreams.h"
|
||||
|
||||
using namespace PxToolkit;
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PxTriangleMesh* PxToolkit::createTriangleMesh32(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, const PxU32* indices32, PxU32 triCount, bool insert)
|
||||
{
|
||||
PxTriangleMeshDesc meshDesc;
|
||||
meshDesc.points.count = vertCount;
|
||||
meshDesc.points.stride = sizeof(PxVec3);
|
||||
meshDesc.points.data = verts;
|
||||
|
||||
meshDesc.triangles.count = triCount;
|
||||
meshDesc.triangles.stride = 3*sizeof(PxU32);
|
||||
meshDesc.triangles.data = indices32;
|
||||
|
||||
if(!insert)
|
||||
{
|
||||
PxDefaultMemoryOutputStream writeBuffer;
|
||||
bool status = cooking.cookTriangleMesh(meshDesc, writeBuffer);
|
||||
if(!status)
|
||||
return NULL;
|
||||
|
||||
PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
|
||||
return physics.createTriangleMesh(readBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cooking.createTriangleMesh(meshDesc,physics.getPhysicsInsertionCallback());
|
||||
}
|
||||
}
|
||||
|
||||
PxTriangleMesh* PxToolkit::createTriangleMesh32(PxPhysics& physics, PxCooking& cooking, PxTriangleMeshDesc* meshDesc, bool insert)
|
||||
{
|
||||
if(!insert)
|
||||
{
|
||||
PxDefaultMemoryOutputStream writeBuffer;
|
||||
bool status = cooking.cookTriangleMesh(*meshDesc, writeBuffer);
|
||||
if(!status)
|
||||
return NULL;
|
||||
|
||||
PxDefaultMemoryInputData readBuffer(writeBuffer.getData(), writeBuffer.getSize());
|
||||
return physics.createTriangleMesh(readBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cooking.createTriangleMesh(*meshDesc,physics.getPhysicsInsertionCallback());
|
||||
}
|
||||
}
|
||||
|
||||
PxConvexMesh* PxToolkit::createConvexMesh(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags)
|
||||
{
|
||||
PxConvexMeshDesc convexDesc;
|
||||
convexDesc.points.count = vertCount;
|
||||
convexDesc.points.stride = sizeof(PxVec3);
|
||||
convexDesc.points.data = verts;
|
||||
convexDesc.flags = flags;
|
||||
return cooking.createConvexMesh(convexDesc, physics.getPhysicsInsertionCallback());
|
||||
}
|
||||
|
||||
PxConvexMesh* PxToolkit::createConvexMeshSafe(PxPhysics& physics, PxCooking& cooking, const PxVec3* verts, PxU32 vertCount, PxConvexFlags flags, PxU32 vLimit)
|
||||
{
|
||||
PxConvexMeshDesc convexDesc;
|
||||
convexDesc.points.count = vertCount;
|
||||
convexDesc.points.stride = sizeof(PxVec3);
|
||||
convexDesc.points.data = verts;
|
||||
convexDesc.flags = flags;
|
||||
convexDesc.vertexLimit = vLimit;
|
||||
|
||||
PxDefaultMemoryOutputStream buf;
|
||||
bool retVal = cooking.cookConvexMesh(convexDesc, buf);
|
||||
if(!retVal)
|
||||
{
|
||||
// create AABB
|
||||
PxBounds3 aabb;
|
||||
aabb.setEmpty();
|
||||
for (PxU32 i = 0; i < vertCount; i++)
|
||||
{
|
||||
aabb.include(verts[i]);
|
||||
}
|
||||
|
||||
PxVec3 aabbVerts[8];
|
||||
aabbVerts[0] = PxVec3(aabb.minimum.x,aabb.minimum.y,aabb.minimum.z);
|
||||
aabbVerts[1] = PxVec3(aabb.maximum.x,aabb.minimum.y,aabb.minimum.z);
|
||||
aabbVerts[2] = PxVec3(aabb.maximum.x,aabb.maximum.y,aabb.minimum.z);
|
||||
aabbVerts[3] = PxVec3(aabb.minimum.x,aabb.maximum.y,aabb.minimum.z);
|
||||
|
||||
aabbVerts[4] = PxVec3(aabb.minimum.x,aabb.minimum.y,aabb.maximum.z);
|
||||
aabbVerts[5] = PxVec3(aabb.maximum.x,aabb.minimum.y,aabb.maximum.z);
|
||||
aabbVerts[6] = PxVec3(aabb.maximum.x,aabb.maximum.y,aabb.maximum.z);
|
||||
aabbVerts[7] = PxVec3(aabb.minimum.x,aabb.maximum.y,aabb.maximum.z);
|
||||
|
||||
convexDesc.points.count = 8;
|
||||
convexDesc.points.stride = sizeof(PxVec3);
|
||||
convexDesc.points.data = &aabbVerts[0];
|
||||
convexDesc.flags = flags;
|
||||
|
||||
retVal = cooking.cookConvexMesh(convexDesc, buf);
|
||||
}
|
||||
|
||||
if(!retVal)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PxDefaultMemoryInputData input(buf.getData(), buf.getSize());
|
||||
return physics.createConvexMesh(input);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user