2015-04-16 16:55:32 +00:00
|
|
|
/*
|
|
|
|
Bullet Continuous Collision Detection and Physics Library
|
|
|
|
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied warranty.
|
|
|
|
In no event will the authors be held liable for any damages arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it freely,
|
|
|
|
subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Collision Radius
|
|
|
|
#define COLLISION_RADIUS 0.0f
|
|
|
|
|
|
|
|
#include "BenchmarkDemo.h"
|
|
|
|
|
|
|
|
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
|
|
|
#include "btBulletDynamicsCommon.h"
|
2018-09-23 21:17:31 +00:00
|
|
|
#include <stdio.h> //printf debugging
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "TaruData.h"
|
2018-11-02 17:13:08 +00:00
|
|
|
#include "HaltonData.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
#include "landscapeData.h"
|
|
|
|
#include "BulletCollision/BroadphaseCollision/btDbvtBroadphase.h"
|
|
|
|
|
|
|
|
#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
|
|
|
|
|
|
|
|
#include "LinearMath/btAlignedObjectArray.h"
|
|
|
|
#include "LinearMath/btTransform.h"
|
|
|
|
|
|
|
|
class btDynamicsWorld;
|
|
|
|
|
|
|
|
#define NUMRAYS 500
|
2016-09-27 07:01:45 +00:00
|
|
|
#define USE_PARALLEL_RAYCASTS 1
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
class btRigidBody;
|
|
|
|
class btBroadphaseInterface;
|
|
|
|
class btCollisionShape;
|
|
|
|
class btOverlappingPairCache;
|
|
|
|
class btCollisionDispatcher;
|
|
|
|
class btConstraintSolver;
|
|
|
|
struct btCollisionAlgorithmCreateFunc;
|
|
|
|
class btDefaultCollisionConfiguration;
|
|
|
|
|
2016-11-07 20:08:02 +00:00
|
|
|
#include "../MultiThreadedDemo/CommonRigidBodyMTBase.h"
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-11-07 20:08:02 +00:00
|
|
|
class BenchmarkDemo : public CommonRigidBodyMTBase
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
//keep the collision shapes, for deletion/cleanup
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btAlignedObjectArray<class RagDoll*> m_ragdolls;
|
|
|
|
|
|
|
|
int m_benchmark;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
void myinit()
|
|
|
|
{
|
|
|
|
//??
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCameraDistance(btScalar dist)
|
|
|
|
{
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
void createTest1();
|
|
|
|
void createTest2();
|
|
|
|
void createTest3();
|
|
|
|
void createTest4();
|
|
|
|
void createTest5();
|
|
|
|
void createTest6();
|
|
|
|
void createTest7();
|
2018-11-02 17:13:08 +00:00
|
|
|
void createTest8();
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
void createWall(const btVector3& offsetPosition, int stackSize, const btVector3& boxSize);
|
|
|
|
void createPyramid(const btVector3& offsetPosition, int stackSize, const btVector3& boxSize);
|
|
|
|
void createTowerCircle(const btVector3& offsetPosition, int stackSize, int rotSize, const btVector3& boxSize);
|
2015-04-16 16:55:32 +00:00
|
|
|
void createLargeMeshBody();
|
|
|
|
|
|
|
|
class SpuBatchRaycaster* m_batchRaycaster;
|
|
|
|
class btThreadSupportInterface* m_batchRaycasterThreadSupport;
|
|
|
|
|
|
|
|
void castRays();
|
|
|
|
void initRays();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
public:
|
2015-04-16 16:55:32 +00:00
|
|
|
BenchmarkDemo(struct GUIHelperInterface* helper, int benchmark)
|
2018-09-23 21:17:31 +00:00
|
|
|
: CommonRigidBodyMTBase(helper),
|
|
|
|
m_benchmark(benchmark)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~BenchmarkDemo()
|
|
|
|
{
|
|
|
|
exitPhysics();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
void initPhysics();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void exitPhysics();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
void stepSimulation(float deltaTime);
|
|
|
|
|
2015-05-03 17:46:22 +00:00
|
|
|
void resetCamera()
|
|
|
|
{
|
|
|
|
float dist = 120;
|
2017-06-01 22:30:37 +00:00
|
|
|
float pitch = -35;
|
|
|
|
float yaw = 52;
|
2018-09-23 21:17:31 +00:00
|
|
|
float targetPos[3] = {0, 10.46, 0};
|
|
|
|
m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
|
2015-05-03 17:46:22 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class btRaycastBar2
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
btVector3 source[NUMRAYS];
|
|
|
|
btVector3 dest[NUMRAYS];
|
|
|
|
btVector3 direction[NUMRAYS];
|
|
|
|
btVector3 hit[NUMRAYS];
|
|
|
|
btVector3 normal[NUMRAYS];
|
2015-05-03 17:56:39 +00:00
|
|
|
struct GUIHelperInterface* m_guiHelper;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
int frame_counter;
|
|
|
|
int ms;
|
|
|
|
int sum_ms;
|
|
|
|
int sum_ms_samples;
|
|
|
|
int min_ms;
|
|
|
|
int max_ms;
|
|
|
|
|
|
|
|
#ifdef USE_BT_CLOCK
|
|
|
|
btClock frame_timer;
|
2018-09-23 21:17:31 +00:00
|
|
|
#endif //USE_BT_CLOCK
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
btScalar dx;
|
|
|
|
btScalar min_x;
|
|
|
|
btScalar max_x;
|
|
|
|
btScalar max_y;
|
|
|
|
btScalar sign;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btRaycastBar2()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-05-03 17:56:39 +00:00
|
|
|
m_guiHelper = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
ms = 0;
|
|
|
|
max_ms = 0;
|
|
|
|
min_ms = 9999;
|
|
|
|
sum_ms_samples = 0;
|
|
|
|
sum_ms = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btRaycastBar2(btScalar ray_length, btScalar z, btScalar max_y, struct GUIHelperInterface* guiHelper)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-05-03 17:56:39 +00:00
|
|
|
m_guiHelper = guiHelper;
|
2015-04-16 16:55:32 +00:00
|
|
|
frame_counter = 0;
|
|
|
|
ms = 0;
|
|
|
|
max_ms = 0;
|
|
|
|
min_ms = 9999;
|
|
|
|
sum_ms_samples = 0;
|
|
|
|
sum_ms = 0;
|
|
|
|
dx = 10.0;
|
|
|
|
min_x = 0;
|
|
|
|
max_x = 0;
|
|
|
|
this->max_y = max_y;
|
|
|
|
sign = 1.0;
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar dalpha = 2 * SIMD_2_PI / NUMRAYS;
|
2015-04-16 16:55:32 +00:00
|
|
|
for (int i = 0; i < NUMRAYS; i++)
|
|
|
|
{
|
|
|
|
btScalar alpha = dalpha * i;
|
2018-09-23 21:17:31 +00:00
|
|
|
// rotate around by alpha degrees y
|
2015-04-16 16:55:32 +00:00
|
|
|
btQuaternion q(btVector3(0.0, 1.0, 0.0), alpha);
|
|
|
|
direction[i] = btVector3(1.0, 0.0, 0.0);
|
2018-09-23 21:17:31 +00:00
|
|
|
direction[i] = quatRotate(q, direction[i]);
|
2015-04-16 16:55:32 +00:00
|
|
|
direction[i] = direction[i] * ray_length;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
source[i] = btVector3(min_x, max_y, z);
|
|
|
|
dest[i] = source[i] + direction[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
dest[i][1] = -1000;
|
2015-04-16 16:55:32 +00:00
|
|
|
normal[i] = btVector3(1.0, 0.0, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void move(btScalar dt)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (dt > btScalar(1.0 / 60.0))
|
|
|
|
dt = btScalar(1.0 / 60.0);
|
2015-04-16 16:55:32 +00:00
|
|
|
for (int i = 0; i < NUMRAYS; i++)
|
|
|
|
{
|
|
|
|
source[i][0] += dx * dt * sign;
|
|
|
|
dest[i][0] += dx * dt * sign;
|
|
|
|
}
|
|
|
|
if (source[0][0] < min_x)
|
|
|
|
sign = 1.0;
|
|
|
|
else if (source[0][0] > max_x)
|
|
|
|
sign = -1.0;
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void castRays(btCollisionWorld* cw, int iBegin, int iEnd)
|
|
|
|
{
|
|
|
|
for (int i = iBegin; i < iEnd; ++i)
|
|
|
|
{
|
2016-09-27 07:01:45 +00:00
|
|
|
btCollisionWorld::ClosestRayResultCallback cb(source[i], dest[i]);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2017-01-31 18:14:00 +00:00
|
|
|
{
|
|
|
|
BT_PROFILE("cw->rayTest");
|
|
|
|
cw->rayTest(source[i], dest[i], cb);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
if (cb.hasHit())
|
2016-09-27 07:01:45 +00:00
|
|
|
{
|
|
|
|
hit[i] = cb.m_hitPointWorld;
|
|
|
|
normal[i] = cb.m_hitNormalWorld;
|
2018-09-23 21:17:31 +00:00
|
|
|
normal[i].normalize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-27 07:01:45 +00:00
|
|
|
hit[i] = dest[i];
|
|
|
|
normal[i] = btVector3(1.0, 0.0, 0.0);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-27 07:01:45 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
struct CastRaysLoopBody : public btIParallelForBody
|
|
|
|
{
|
|
|
|
btCollisionWorld* mWorld;
|
2017-01-16 06:26:11 +00:00
|
|
|
btRaycastBar2* mRaycasts;
|
|
|
|
|
|
|
|
CastRaysLoopBody(btCollisionWorld* cw, btRaycastBar2* rb) : mWorld(cw), mRaycasts(rb) {}
|
2016-09-27 07:01:45 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void forLoop(int iBegin, int iEnd) const
|
|
|
|
{
|
|
|
|
mRaycasts->castRays(mWorld, iBegin, iEnd);
|
|
|
|
}
|
|
|
|
};
|
2016-09-27 07:01:45 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void cast(btCollisionWorld* cw, bool multiThreading = false)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2017-01-31 18:14:00 +00:00
|
|
|
BT_PROFILE("cast");
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifdef USE_BT_CLOCK
|
2018-09-23 21:17:31 +00:00
|
|
|
frame_timer.reset();
|
|
|
|
#endif //USE_BT_CLOCK
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
#ifdef BATCH_RAYCASTER
|
|
|
|
if (!gBatchRaycaster)
|
|
|
|
return;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
gBatchRaycaster->clearRays();
|
2015-04-16 16:55:32 +00:00
|
|
|
for (int i = 0; i < NUMRAYS; i++)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
gBatchRaycaster->addRay(source[i], dest[i]);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
gBatchRaycaster->performBatchRaycast();
|
|
|
|
for (int i = 0; i < gBatchRaycaster->getNumRays(); i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
const SpuRaycastTaskWorkUnitOut& out = (*gBatchRaycaster)[i];
|
|
|
|
hit[i].setInterpolate3(source[i], dest[i], out.hitFraction);
|
|
|
|
normal[i] = out.hitNormal;
|
|
|
|
normal[i].normalize();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
#else
|
2016-09-27 07:01:45 +00:00
|
|
|
#if USE_PARALLEL_RAYCASTS
|
2018-09-23 21:17:31 +00:00
|
|
|
if (multiThreading)
|
|
|
|
{
|
|
|
|
CastRaysLoopBody rayLooper(cw, this);
|
|
|
|
int grainSize = 20; // number of raycasts per task
|
|
|
|
btParallelFor(0, NUMRAYS, grainSize, rayLooper);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // USE_PARALLEL_RAYCASTS
|
|
|
|
{
|
|
|
|
// single threaded
|
|
|
|
castRays(cw, 0, NUMRAYS);
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
#ifdef USE_BT_CLOCK
|
2018-09-23 21:17:31 +00:00
|
|
|
ms += frame_timer.getTimeMilliseconds();
|
|
|
|
#endif //USE_BT_CLOCK
|
2015-04-16 16:55:32 +00:00
|
|
|
frame_counter++;
|
|
|
|
if (frame_counter > 50)
|
|
|
|
{
|
|
|
|
min_ms = ms < min_ms ? ms : min_ms;
|
|
|
|
max_ms = ms > max_ms ? ms : max_ms;
|
|
|
|
sum_ms += ms;
|
|
|
|
sum_ms_samples++;
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar mean_ms = (btScalar)sum_ms / (btScalar)sum_ms_samples;
|
2015-04-16 16:55:32 +00:00
|
|
|
printf("%d rays in %d ms %d %d %f\n", NUMRAYS * frame_counter, ms, min_ms, max_ms, mean_ms);
|
|
|
|
ms = 0;
|
|
|
|
frame_counter = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void draw()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2015-05-03 17:56:39 +00:00
|
|
|
if (m_guiHelper)
|
|
|
|
{
|
|
|
|
btAlignedObjectArray<unsigned int> indices;
|
2015-05-03 18:10:12 +00:00
|
|
|
btAlignedObjectArray<btVector3FloatData> points;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
float lineColor[4] = {1, 0.4, .4, 1};
|
|
|
|
|
2015-05-03 17:56:39 +00:00
|
|
|
for (int i = 0; i < NUMRAYS; i++)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3FloatData s, h;
|
|
|
|
for (int w = 0; w < 4; w++)
|
2015-05-03 18:10:12 +00:00
|
|
|
{
|
|
|
|
s.m_floats[w] = source[i][w];
|
|
|
|
h.m_floats[w] = hit[i][w];
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-05-03 18:10:12 +00:00
|
|
|
points.push_back(s);
|
|
|
|
points.push_back(h);
|
2015-05-03 17:56:39 +00:00
|
|
|
indices.push_back(indices.size());
|
|
|
|
indices.push_back(indices.size());
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_guiHelper->getRenderInterface()->drawLines(&points[0].m_floats[0], lineColor, points.size(), sizeof(btVector3FloatData), &indices[0], indices.size(), 1);
|
2015-05-03 17:56:39 +00:00
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static btRaycastBar2 raycastBar;
|
|
|
|
|
|
|
|
void BenchmarkDemo::stepSimulation(float deltaTime)
|
|
|
|
{
|
|
|
|
if (m_dynamicsWorld)
|
|
|
|
{
|
|
|
|
m_dynamicsWorld->stepSimulation(deltaTime);
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
if (m_benchmark == 7)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
castRays();
|
|
|
|
|
|
|
|
raycastBar.draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::initPhysics()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
m_guiHelper->setUpAxis(1);
|
|
|
|
|
|
|
|
setCameraDistance(btScalar(100.));
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
createEmptyDynamicsWorld();
|
2016-09-27 07:01:45 +00:00
|
|
|
/////collision configuration contains default setup for memory, collision setup
|
|
|
|
//btDefaultCollisionConstructionInfo cci;
|
|
|
|
//cci.m_defaultMaxPersistentManifoldPoolSize = 32768;
|
|
|
|
//m_collisionConfiguration = new btDefaultCollisionConfiguration(cci);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
/////use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
|
|
|
|
//m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
|
|
|
//
|
|
|
|
//m_dispatcher->setDispatcherFlags(btCollisionDispatcher::CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
/////the maximum size of the collision world. Make sure objects stay within these boundaries
|
|
|
|
/////Don't make the world AABB size too large, it will harm simulation quality and performance
|
|
|
|
//btVector3 worldAabbMin(-1000,-1000,-1000);
|
|
|
|
//btVector3 worldAabbMax(1000,1000,1000);
|
|
|
|
//
|
|
|
|
//btHashedOverlappingPairCache* pairCache = new btHashedOverlappingPairCache();
|
|
|
|
//m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,3500,pairCache);
|
2018-09-23 21:17:31 +00:00
|
|
|
// m_broadphase = new btSimpleBroadphase();
|
|
|
|
// m_broadphase = new btDbvtBroadphase();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
|
2016-09-27 07:01:45 +00:00
|
|
|
//btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
//m_solver = sol;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2016-09-27 07:01:45 +00:00
|
|
|
//btDiscreteDynamicsWorld* dynamicsWorld;
|
|
|
|
//m_dynamicsWorld = dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
///the following 3 lines increase the performance dramatically, with a little bit of loss of quality
|
2018-09-23 21:17:31 +00:00
|
|
|
m_dynamicsWorld->getSolverInfo().m_solverMode |= SOLVER_ENABLE_FRICTION_DIRECTION_CACHING; //don't recalculate friction values each frame
|
|
|
|
m_dynamicsWorld->getSolverInfo().m_numIterations = 5; //few solver iterations
|
2015-04-16 16:55:32 +00:00
|
|
|
//m_defaultContactProcessingThreshold = 0.f;//used when creating bodies: body->setContactProcessingThreshold(...);
|
2015-05-03 18:45:30 +00:00
|
|
|
m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
m_dynamicsWorld->setGravity(btVector3(0, -10, 0));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
if (m_benchmark < 5)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
///create a few basic rigid bodies
|
2018-09-23 21:17:31 +00:00
|
|
|
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(250.), btScalar(50.), btScalar(250.)));
|
|
|
|
// btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),0);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
m_collisionShapes.push_back(groundShape);
|
|
|
|
|
|
|
|
btTransform groundTransform;
|
|
|
|
groundTransform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
groundTransform.setOrigin(btVector3(0, -50, 0));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//We can also use DemoApplication::createRigidBody, but for clarity it is provided here:
|
|
|
|
{
|
|
|
|
btScalar mass(0.);
|
|
|
|
|
|
|
|
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
|
|
|
bool isDynamic = (mass != 0.f);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
if (isDynamic)
|
2018-09-23 21:17:31 +00:00
|
|
|
groundShape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
|
|
|
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
2018-09-23 21:17:31 +00:00
|
|
|
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, groundShape, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
btRigidBody* body = new btRigidBody(rbInfo);
|
|
|
|
|
|
|
|
//add the body to the dynamics world
|
|
|
|
m_dynamicsWorld->addRigidBody(body);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_benchmark)
|
|
|
|
{
|
|
|
|
case 1:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
createTest1();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
case 2:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
createTest2();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
case 3:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
createTest3();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
case 4:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
createTest4();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
case 5:
|
2018-09-23 21:17:31 +00:00
|
|
|
{
|
|
|
|
createTest5();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
createTest6();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
createTest7();
|
|
|
|
break;
|
|
|
|
}
|
2018-11-02 17:13:08 +00:00
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
createTest8();
|
|
|
|
break;
|
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
default:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
}
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_guiHelper->autogenerateGraphicsObjects(m_dynamicsWorld);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest1()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
// 3000
|
|
|
|
int size = 8;
|
|
|
|
const float cubeSize = 1.0f;
|
|
|
|
float spacing = cubeSize;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 pos(0.0f, cubeSize * 2, 0.f);
|
2015-04-16 16:55:32 +00:00
|
|
|
float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* blockShape = new btBoxShape(btVector3(cubeSize - COLLISION_RADIUS, cubeSize - COLLISION_RADIUS, cubeSize - COLLISION_RADIUS));
|
|
|
|
btVector3 localInertia(0, 0, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
float mass = 2.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
blockShape->calculateLocalInertia(mass, localInertia);
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < 47; k++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < size; j++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
|
|
|
|
|
|
|
|
trans.setOrigin(pos);
|
|
|
|
btRigidBody* cmbody;
|
2018-09-23 21:17:31 +00:00
|
|
|
cmbody = createRigidBody(mass, trans, blockShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
offset -= 0.05f * spacing * (size - 1);
|
|
|
|
// spacing *= 1.01f;
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[1] += (cubeSize * 2.0f + spacing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Pyramid 3
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createWall(const btVector3& offsetPosition, int stackSize, const btVector3& boxSize)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0] - COLLISION_RADIUS, boxSize[1] - COLLISION_RADIUS, boxSize[2] - COLLISION_RADIUS));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
float mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
blockShape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
// btScalar diffX = boxSize[0] * 1.0f;
|
|
|
|
btScalar diffY = boxSize[1] * 1.0f;
|
|
|
|
btScalar diffZ = boxSize[2] * 1.0f;
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar offset = -stackSize * (diffZ * 2.0f) * 0.5f;
|
2015-04-16 16:55:32 +00:00
|
|
|
btVector3 pos(0.0f, diffY, 0.0f);
|
|
|
|
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
while (stackSize)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < stackSize; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offset + (float)i * (diffZ * 2.0f);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
trans.setOrigin(offsetPosition + pos);
|
|
|
|
createRigidBody(mass, trans, blockShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
offset += diffZ;
|
|
|
|
pos[1] += (diffY * 2.0f);
|
|
|
|
stackSize--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createPyramid(const btVector3& offsetPosition, int stackSize, const btVector3& boxSize)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
btScalar space = 0.0001f;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
btVector3 pos(0.0f, boxSize[1], 0.0f);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0] - COLLISION_RADIUS, boxSize[1] - COLLISION_RADIUS, boxSize[2] - COLLISION_RADIUS));
|
2015-04-16 16:55:32 +00:00
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
|
|
|
btScalar mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
blockShape->calculateLocalInertia(mass, localInertia);
|
|
|
|
|
|
|
|
btScalar diffX = boxSize[0] * 1.02f;
|
|
|
|
btScalar diffY = boxSize[1] * 1.02f;
|
|
|
|
btScalar diffZ = boxSize[2] * 1.02f;
|
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
btScalar offsetX = -stackSize * (diffX * 2.0f + space) * 0.5f;
|
|
|
|
btScalar offsetZ = -stackSize * (diffZ * 2.0f + space) * 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
while (stackSize)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < stackSize; j++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offsetZ + (float)j * (diffZ * 2.0f + space);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < stackSize; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offsetX + (float)i * (diffX * 2.0f + space);
|
|
|
|
trans.setOrigin(offsetPosition + pos);
|
2018-09-23 21:17:31 +00:00
|
|
|
this->createRigidBody(mass, trans, blockShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
offsetX += diffX;
|
|
|
|
offsetZ += diffZ;
|
|
|
|
pos[1] += (diffY * 2.0f + space);
|
|
|
|
stackSize--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
const btVector3 rotate(const btQuaternion& quat, const btVector3& vec)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float tmpX, tmpY, tmpZ, tmpW;
|
|
|
|
tmpX = (((quat.getW() * vec.getX()) + (quat.getY() * vec.getZ())) - (quat.getZ() * vec.getY()));
|
|
|
|
tmpY = (((quat.getW() * vec.getY()) + (quat.getZ() * vec.getX())) - (quat.getX() * vec.getZ()));
|
|
|
|
tmpZ = (((quat.getW() * vec.getZ()) + (quat.getX() * vec.getY())) - (quat.getY() * vec.getX()));
|
|
|
|
tmpW = (((quat.getX() * vec.getX()) + (quat.getY() * vec.getY())) + (quat.getZ() * vec.getZ()));
|
|
|
|
return btVector3(
|
|
|
|
((((tmpW * quat.getX()) + (tmpX * quat.getW())) - (tmpY * quat.getZ())) + (tmpZ * quat.getY())),
|
|
|
|
((((tmpW * quat.getY()) + (tmpY * quat.getW())) - (tmpZ * quat.getX())) + (tmpX * quat.getZ())),
|
|
|
|
((((tmpW * quat.getZ()) + (tmpZ * quat.getW())) - (tmpX * quat.getY())) + (tmpY * quat.getX())));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTowerCircle(const btVector3& offsetPosition, int stackSize, int rotSize, const btVector3& boxSize)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btBoxShape* blockShape = new btBoxShape(btVector3(boxSize[0] - COLLISION_RADIUS, boxSize[1] - COLLISION_RADIUS, boxSize[2] - COLLISION_RADIUS));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
|
|
|
float mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
blockShape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
float radius = 1.3f * rotSize * boxSize[0] / SIMD_PI;
|
|
|
|
|
|
|
|
// create active boxes
|
2018-09-23 21:17:31 +00:00
|
|
|
btQuaternion rotY(0, 1, 0, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
float posY = boxSize[1];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < stackSize; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < rotSize; j++)
|
|
|
|
{
|
|
|
|
trans.setOrigin(offsetPosition + rotate(rotY, btVector3(0.0f, posY, radius)));
|
2015-04-16 16:55:32 +00:00
|
|
|
trans.setRotation(rotY);
|
2018-09-23 21:17:31 +00:00
|
|
|
createRigidBody(mass, trans, blockShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
rotY *= btQuaternion(btVector3(0, 1, 0), SIMD_PI / (rotSize * btScalar(0.5)));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
posY += boxSize[1] * 2.0f;
|
2018-09-23 21:17:31 +00:00
|
|
|
rotY *= btQuaternion(btVector3(0, 1, 0), SIMD_PI / (float)rotSize);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest2()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
setCameraDistance(btScalar(50.));
|
|
|
|
const float cubeSize = 1.0f;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
createPyramid(btVector3(-20.0f, 0.0f, 0.0f), 12, btVector3(cubeSize, cubeSize, cubeSize));
|
|
|
|
createWall(btVector3(-2.0f, 0.0f, 0.0f), 12, btVector3(cubeSize, cubeSize, cubeSize));
|
|
|
|
createWall(btVector3(4.0f, 0.0f, 0.0f), 12, btVector3(cubeSize, cubeSize, cubeSize));
|
|
|
|
createWall(btVector3(10.0f, 0.0f, 0.0f), 12, btVector3(cubeSize, cubeSize, cubeSize));
|
|
|
|
createTowerCircle(btVector3(25.0f, 0.0f, 0.0f), 8, 24, btVector3(cubeSize, cubeSize, cubeSize));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enrico: Shouldn't these three variables be real constants and not defines?
|
|
|
|
|
|
|
|
#ifndef M_PI
|
2018-09-23 21:17:31 +00:00
|
|
|
#define M_PI btScalar(3.14159265358979323846)
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI_2
|
2018-09-23 21:17:31 +00:00
|
|
|
#define M_PI_2 btScalar(1.57079632679489661923)
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef M_PI_4
|
2018-09-23 21:17:31 +00:00
|
|
|
#define M_PI_4 btScalar(0.785398163397448309616)
|
2015-04-16 16:55:32 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class RagDoll
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
BODYPART_PELVIS = 0,
|
|
|
|
BODYPART_SPINE,
|
|
|
|
BODYPART_HEAD,
|
|
|
|
|
|
|
|
BODYPART_LEFT_UPPER_LEG,
|
|
|
|
BODYPART_LEFT_LOWER_LEG,
|
|
|
|
|
|
|
|
BODYPART_RIGHT_UPPER_LEG,
|
|
|
|
BODYPART_RIGHT_LOWER_LEG,
|
|
|
|
|
|
|
|
BODYPART_LEFT_UPPER_ARM,
|
|
|
|
BODYPART_LEFT_LOWER_ARM,
|
|
|
|
|
|
|
|
BODYPART_RIGHT_UPPER_ARM,
|
|
|
|
BODYPART_RIGHT_LOWER_ARM,
|
|
|
|
|
|
|
|
BODYPART_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
JOINT_PELVIS_SPINE = 0,
|
|
|
|
JOINT_SPINE_HEAD,
|
|
|
|
|
|
|
|
JOINT_LEFT_HIP,
|
|
|
|
JOINT_LEFT_KNEE,
|
|
|
|
|
|
|
|
JOINT_RIGHT_HIP,
|
|
|
|
JOINT_RIGHT_KNEE,
|
|
|
|
|
|
|
|
JOINT_LEFT_SHOULDER,
|
|
|
|
JOINT_LEFT_ELBOW,
|
|
|
|
|
|
|
|
JOINT_RIGHT_SHOULDER,
|
|
|
|
JOINT_RIGHT_ELBOW,
|
|
|
|
|
|
|
|
JOINT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
btDynamicsWorld* m_ownerWorld;
|
|
|
|
btCollisionShape* m_shapes[BODYPART_COUNT];
|
|
|
|
btRigidBody* m_bodies[BODYPART_COUNT];
|
|
|
|
btTypedConstraint* m_joints[JOINT_COUNT];
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btRigidBody* createRigidBody(btScalar mass, const btTransform& startTransform, btCollisionShape* shape)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
bool isDynamic = (mass != 0.f);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
2015-04-16 16:55:32 +00:00
|
|
|
if (isDynamic)
|
2018-09-23 21:17:31 +00:00
|
|
|
shape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, myMotionState, shape, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
btRigidBody* body = new btRigidBody(rbInfo);
|
|
|
|
|
|
|
|
m_ownerWorld->addRigidBody(body);
|
|
|
|
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2018-09-23 21:17:31 +00:00
|
|
|
RagDoll(btDynamicsWorld* ownerWorld, const btVector3& positionOffset, btScalar scale)
|
|
|
|
: m_ownerWorld(ownerWorld)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
// Setup the geometry
|
2018-09-23 21:17:31 +00:00
|
|
|
m_shapes[BODYPART_PELVIS] = new btCapsuleShape(btScalar(0.15) * scale, btScalar(0.20) * scale);
|
|
|
|
m_shapes[BODYPART_SPINE] = new btCapsuleShape(btScalar(0.15) * scale, btScalar(0.28) * scale);
|
|
|
|
m_shapes[BODYPART_HEAD] = new btCapsuleShape(btScalar(0.10) * scale, btScalar(0.05) * scale);
|
|
|
|
m_shapes[BODYPART_LEFT_UPPER_LEG] = new btCapsuleShape(btScalar(0.07) * scale, btScalar(0.45) * scale);
|
|
|
|
m_shapes[BODYPART_LEFT_LOWER_LEG] = new btCapsuleShape(btScalar(0.05) * scale, btScalar(0.37) * scale);
|
|
|
|
m_shapes[BODYPART_RIGHT_UPPER_LEG] = new btCapsuleShape(btScalar(0.07) * scale, btScalar(0.45) * scale);
|
|
|
|
m_shapes[BODYPART_RIGHT_LOWER_LEG] = new btCapsuleShape(btScalar(0.05) * scale, btScalar(0.37) * scale);
|
|
|
|
m_shapes[BODYPART_LEFT_UPPER_ARM] = new btCapsuleShape(btScalar(0.05) * scale, btScalar(0.33) * scale);
|
|
|
|
m_shapes[BODYPART_LEFT_LOWER_ARM] = new btCapsuleShape(btScalar(0.04) * scale, btScalar(0.25) * scale);
|
|
|
|
m_shapes[BODYPART_RIGHT_UPPER_ARM] = new btCapsuleShape(btScalar(0.05) * scale, btScalar(0.33) * scale);
|
|
|
|
m_shapes[BODYPART_RIGHT_LOWER_ARM] = new btCapsuleShape(btScalar(0.04) * scale, btScalar(0.25) * scale);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
// Setup all the rigid bodies
|
2018-09-23 21:17:31 +00:00
|
|
|
btTransform offset;
|
|
|
|
offset.setIdentity();
|
2015-04-16 16:55:32 +00:00
|
|
|
offset.setOrigin(positionOffset);
|
|
|
|
|
|
|
|
btTransform transform;
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.), btScalar(1.), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_PELVIS] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_PELVIS]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.), btScalar(1.2), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_SPINE] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_SPINE]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.), btScalar(1.6), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_HEAD] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_HEAD]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(-0.18), btScalar(0.65), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_LEFT_UPPER_LEG] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_LEFT_UPPER_LEG]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(-0.18), btScalar(0.2), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_LEFT_LOWER_LEG] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_LEFT_LOWER_LEG]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.18), btScalar(0.65), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_RIGHT_UPPER_LEG] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_RIGHT_UPPER_LEG]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.18), btScalar(0.2), btScalar(0.)));
|
|
|
|
m_bodies[BODYPART_RIGHT_LOWER_LEG] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_RIGHT_LOWER_LEG]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(-0.35), btScalar(1.45), btScalar(0.)));
|
|
|
|
transform.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
m_bodies[BODYPART_LEFT_UPPER_ARM] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_LEFT_UPPER_ARM]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(-0.7), btScalar(1.45), btScalar(0.)));
|
|
|
|
transform.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
m_bodies[BODYPART_LEFT_LOWER_ARM] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_LEFT_LOWER_ARM]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.35), btScalar(1.45), btScalar(0.)));
|
|
|
|
transform.getBasis().setEulerZYX(0, 0, -M_PI_2);
|
|
|
|
m_bodies[BODYPART_RIGHT_UPPER_ARM] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_RIGHT_UPPER_ARM]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
transform.setIdentity();
|
2018-09-23 21:17:31 +00:00
|
|
|
transform.setOrigin(scale * btVector3(btScalar(0.7), btScalar(1.45), btScalar(0.)));
|
|
|
|
transform.getBasis().setEulerZYX(0, 0, -M_PI_2);
|
|
|
|
m_bodies[BODYPART_RIGHT_LOWER_ARM] = createRigidBody(btScalar(1.), offset * transform, m_shapes[BODYPART_RIGHT_LOWER_ARM]);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
// Setup some damping on the m_bodies
|
|
|
|
for (int i = 0; i < BODYPART_COUNT; ++i)
|
|
|
|
{
|
|
|
|
m_bodies[i]->setDamping(btScalar(0.05), btScalar(0.85));
|
|
|
|
m_bodies[i]->setDeactivationTime(btScalar(0.8));
|
|
|
|
m_bodies[i]->setSleepingThresholds(btScalar(1.6), btScalar(2.5));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now setup the constraints
|
|
|
|
btHingeConstraint* hingeC;
|
|
|
|
btConeTwistConstraint* coneC;
|
|
|
|
|
|
|
|
btTransform localA, localB;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.15), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.15), btScalar(0.)));
|
|
|
|
hingeC = new btHingeConstraint(*m_bodies[BODYPART_PELVIS], *m_bodies[BODYPART_SPINE], localA, localB);
|
2015-04-16 16:55:32 +00:00
|
|
|
hingeC->setLimit(btScalar(-M_PI_4), btScalar(M_PI_2));
|
|
|
|
m_joints[JOINT_PELVIS_SPINE] = hingeC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_PELVIS_SPINE], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.30), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.14), btScalar(0.)));
|
2015-04-16 16:55:32 +00:00
|
|
|
coneC = new btConeTwistConstraint(*m_bodies[BODYPART_SPINE], *m_bodies[BODYPART_HEAD], localA, localB);
|
|
|
|
coneC->setLimit(M_PI_4, M_PI_4, M_PI_2);
|
|
|
|
m_joints[JOINT_SPINE_HEAD] = coneC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_SPINE_HEAD], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, 0, -M_PI_4 * 5);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(-0.18), btScalar(-0.10), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, 0, -M_PI_4 * 5);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.225), btScalar(0.)));
|
2015-04-16 16:55:32 +00:00
|
|
|
coneC = new btConeTwistConstraint(*m_bodies[BODYPART_PELVIS], *m_bodies[BODYPART_LEFT_UPPER_LEG], localA, localB);
|
|
|
|
coneC->setLimit(M_PI_4, M_PI_4, 0);
|
|
|
|
m_joints[JOINT_LEFT_HIP] = coneC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_HIP], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.225), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.185), btScalar(0.)));
|
|
|
|
hingeC = new btHingeConstraint(*m_bodies[BODYPART_LEFT_UPPER_LEG], *m_bodies[BODYPART_LEFT_LOWER_LEG], localA, localB);
|
2015-04-16 16:55:32 +00:00
|
|
|
hingeC->setLimit(btScalar(0), btScalar(M_PI_2));
|
|
|
|
m_joints[JOINT_LEFT_KNEE] = hingeC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_KNEE], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, 0, M_PI_4);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.18), btScalar(-0.10), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, 0, M_PI_4);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.225), btScalar(0.)));
|
2015-04-16 16:55:32 +00:00
|
|
|
coneC = new btConeTwistConstraint(*m_bodies[BODYPART_PELVIS], *m_bodies[BODYPART_RIGHT_UPPER_LEG], localA, localB);
|
|
|
|
coneC->setLimit(M_PI_4, M_PI_4, 0);
|
|
|
|
m_joints[JOINT_RIGHT_HIP] = coneC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_RIGHT_HIP], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.225), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.185), btScalar(0.)));
|
|
|
|
hingeC = new btHingeConstraint(*m_bodies[BODYPART_RIGHT_UPPER_LEG], *m_bodies[BODYPART_RIGHT_LOWER_LEG], localA, localB);
|
2015-04-16 16:55:32 +00:00
|
|
|
hingeC->setLimit(btScalar(0), btScalar(M_PI_2));
|
|
|
|
m_joints[JOINT_RIGHT_KNEE] = hingeC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_RIGHT_KNEE], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, 0, M_PI);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(-0.2), btScalar(0.15), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.18), btScalar(0.)));
|
2015-04-16 16:55:32 +00:00
|
|
|
coneC = new btConeTwistConstraint(*m_bodies[BODYPART_SPINE], *m_bodies[BODYPART_LEFT_UPPER_ARM], localA, localB);
|
|
|
|
coneC->setLimit(M_PI_2, M_PI_2, 0);
|
|
|
|
m_joints[JOINT_LEFT_SHOULDER] = coneC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_SHOULDER], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.18), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.14), btScalar(0.)));
|
|
|
|
hingeC = new btHingeConstraint(*m_bodies[BODYPART_LEFT_UPPER_ARM], *m_bodies[BODYPART_LEFT_LOWER_ARM], localA, localB);
|
2015-04-16 16:55:32 +00:00
|
|
|
hingeC->setLimit(btScalar(-M_PI_2), btScalar(0));
|
|
|
|
m_joints[JOINT_LEFT_ELBOW] = hingeC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_LEFT_ELBOW], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, 0, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.2), btScalar(0.15), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, 0, M_PI_2);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.18), btScalar(0.)));
|
2015-04-16 16:55:32 +00:00
|
|
|
coneC = new btConeTwistConstraint(*m_bodies[BODYPART_SPINE], *m_bodies[BODYPART_RIGHT_UPPER_ARM], localA, localB);
|
|
|
|
coneC->setLimit(M_PI_2, M_PI_2, 0);
|
|
|
|
m_joints[JOINT_RIGHT_SHOULDER] = coneC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_RIGHT_SHOULDER], true);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
localA.setIdentity();
|
|
|
|
localB.setIdentity();
|
|
|
|
localA.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localA.setOrigin(scale * btVector3(btScalar(0.), btScalar(0.18), btScalar(0.)));
|
|
|
|
localB.getBasis().setEulerZYX(0, M_PI_2, 0);
|
|
|
|
localB.setOrigin(scale * btVector3(btScalar(0.), btScalar(-0.14), btScalar(0.)));
|
|
|
|
hingeC = new btHingeConstraint(*m_bodies[BODYPART_RIGHT_UPPER_ARM], *m_bodies[BODYPART_RIGHT_LOWER_ARM], localA, localB);
|
2015-04-16 16:55:32 +00:00
|
|
|
hingeC->setLimit(btScalar(-M_PI_2), btScalar(0));
|
|
|
|
m_joints[JOINT_RIGHT_ELBOW] = hingeC;
|
|
|
|
m_ownerWorld->addConstraint(m_joints[JOINT_RIGHT_ELBOW], true);
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
virtual ~RagDoll()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Remove all constraints
|
2018-09-23 21:17:31 +00:00
|
|
|
for (i = 0; i < JOINT_COUNT; ++i)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
m_ownerWorld->removeConstraint(m_joints[i]);
|
2018-09-23 21:17:31 +00:00
|
|
|
delete m_joints[i];
|
|
|
|
m_joints[i] = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all bodies and shapes
|
2018-09-23 21:17:31 +00:00
|
|
|
for (i = 0; i < BODYPART_COUNT; ++i)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
m_ownerWorld->removeRigidBody(m_bodies[i]);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
delete m_bodies[i]->getMotionState();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
delete m_bodies[i];
|
|
|
|
m_bodies[i] = 0;
|
|
|
|
delete m_shapes[i];
|
|
|
|
m_shapes[i] = 0;
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest3()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
setCameraDistance(btScalar(50.));
|
|
|
|
|
|
|
|
int size = 16;
|
|
|
|
|
|
|
|
float sizeX = 1.f;
|
|
|
|
float sizeY = 1.f;
|
|
|
|
|
|
|
|
//int rc=0;
|
|
|
|
|
|
|
|
btScalar scale(3.5);
|
|
|
|
btVector3 pos(0.0f, sizeY, 0.0f);
|
2018-09-23 21:17:31 +00:00
|
|
|
while (size)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
float offset = -size * (sizeX * 6.0f) * 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offset + (float)i * (sizeX * 6.0f);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
RagDoll* ragDoll = new RagDoll(m_dynamicsWorld, pos, scale);
|
|
|
|
m_ragdolls.push_back(ragDoll);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offset += sizeX;
|
|
|
|
pos[1] += (sizeY * 7.0f);
|
|
|
|
pos[2] -= sizeX * 2.0f;
|
|
|
|
size--;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest4()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
setCameraDistance(btScalar(50.));
|
|
|
|
|
|
|
|
int size = 8;
|
|
|
|
const float cubeSize = 1.5f;
|
|
|
|
float spacing = cubeSize;
|
|
|
|
btVector3 pos(0.0f, cubeSize * 2, 0.0f);
|
|
|
|
float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;
|
|
|
|
|
|
|
|
btConvexHullShape* convexHullShape = new btConvexHullShape();
|
|
|
|
|
|
|
|
btScalar scaling(1);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
convexHullShape->setLocalScaling(btVector3(scaling, scaling, scaling));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < TaruVtxCount; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 vtx(TaruVtx[i * 3], TaruVtx[i * 3 + 1], TaruVtx[i * 3 + 2]);
|
|
|
|
convexHullShape->addPoint(vtx * btScalar(1. / scaling));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//this will enable polyhedral contact clipping, better quality, slightly slower
|
2018-11-01 04:50:49 +00:00
|
|
|
convexHullShape->initializePolyhedralFeatures();
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
|
|
|
float mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
convexHullShape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < 15; k++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < size; j++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
|
|
|
|
trans.setOrigin(pos);
|
2018-09-23 21:17:31 +00:00
|
|
|
createRigidBody(mass, trans, convexHullShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
offset -= 0.05f * spacing * (size - 1);
|
2015-04-16 16:55:32 +00:00
|
|
|
spacing *= 1.01f;
|
|
|
|
pos[1] += (cubeSize * 2.0f + spacing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LargeMesh
|
|
|
|
|
|
|
|
int LandscapeVtxCount[] = {
|
|
|
|
Landscape01VtxCount,
|
|
|
|
Landscape02VtxCount,
|
|
|
|
Landscape03VtxCount,
|
|
|
|
Landscape04VtxCount,
|
|
|
|
Landscape05VtxCount,
|
|
|
|
Landscape06VtxCount,
|
|
|
|
Landscape07VtxCount,
|
|
|
|
Landscape08VtxCount,
|
|
|
|
};
|
|
|
|
|
|
|
|
int LandscapeIdxCount[] = {
|
|
|
|
Landscape01IdxCount,
|
|
|
|
Landscape02IdxCount,
|
|
|
|
Landscape03IdxCount,
|
|
|
|
Landscape04IdxCount,
|
|
|
|
Landscape05IdxCount,
|
|
|
|
Landscape06IdxCount,
|
|
|
|
Landscape07IdxCount,
|
|
|
|
Landscape08IdxCount,
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar* LandscapeVtx[] = {
|
2015-04-16 16:55:32 +00:00
|
|
|
Landscape01Vtx,
|
|
|
|
Landscape02Vtx,
|
|
|
|
Landscape03Vtx,
|
|
|
|
Landscape04Vtx,
|
|
|
|
Landscape05Vtx,
|
|
|
|
Landscape06Vtx,
|
|
|
|
Landscape07Vtx,
|
|
|
|
Landscape08Vtx,
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btScalar* LandscapeNml[] = {
|
2015-04-16 16:55:32 +00:00
|
|
|
Landscape01Nml,
|
|
|
|
Landscape02Nml,
|
|
|
|
Landscape03Nml,
|
|
|
|
Landscape04Nml,
|
|
|
|
Landscape05Nml,
|
|
|
|
Landscape06Nml,
|
|
|
|
Landscape07Nml,
|
|
|
|
Landscape08Nml,
|
|
|
|
};
|
|
|
|
|
|
|
|
btScalar* LandscapeTex[] = {
|
|
|
|
Landscape01Tex,
|
|
|
|
Landscape02Tex,
|
|
|
|
Landscape03Tex,
|
|
|
|
Landscape04Tex,
|
|
|
|
Landscape05Tex,
|
|
|
|
Landscape06Tex,
|
|
|
|
Landscape07Tex,
|
|
|
|
Landscape08Tex,
|
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned short* LandscapeIdx[] = {
|
2015-04-16 16:55:32 +00:00
|
|
|
Landscape01Idx,
|
|
|
|
Landscape02Idx,
|
|
|
|
Landscape03Idx,
|
|
|
|
Landscape04Idx,
|
|
|
|
Landscape05Idx,
|
|
|
|
Landscape06Idx,
|
|
|
|
Landscape07Idx,
|
|
|
|
Landscape08Idx,
|
|
|
|
};
|
|
|
|
|
|
|
|
void BenchmarkDemo::createLargeMeshBody()
|
|
|
|
{
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
btTriangleIndexVertexArray* meshInterface = new btTriangleIndexVertexArray();
|
|
|
|
btIndexedMesh part;
|
|
|
|
|
|
|
|
part.m_vertexBase = (const unsigned char*)LandscapeVtx[i];
|
|
|
|
part.m_vertexStride = sizeof(btScalar) * 3;
|
|
|
|
part.m_numVertices = LandscapeVtxCount[i];
|
|
|
|
part.m_triangleIndexBase = (const unsigned char*)LandscapeIdx[i];
|
2018-09-23 21:17:31 +00:00
|
|
|
part.m_triangleIndexStride = sizeof(short) * 3;
|
|
|
|
part.m_numTriangles = LandscapeIdxCount[i] / 3;
|
2015-04-16 16:55:32 +00:00
|
|
|
part.m_indexType = PHY_SHORT;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
meshInterface->addIndexedMesh(part, PHY_SHORT);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
bool useQuantizedAabbCompression = true;
|
|
|
|
btBvhTriangleMeshShape* trimeshShape = new btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression);
|
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
trans.setOrigin(btVector3(0, -25, 0));
|
2015-04-16 16:55:32 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btRigidBody* body = createRigidBody(0, trans, trimeshShape);
|
|
|
|
body->setFriction(btScalar(0.9));
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest5()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
setCameraDistance(btScalar(250.));
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 boxSize(1.5f, 1.5f, 1.5f);
|
2015-04-16 16:55:32 +00:00
|
|
|
float boxMass = 1.0f;
|
|
|
|
float sphereRadius = 1.5f;
|
|
|
|
float sphereMass = 1.0f;
|
|
|
|
float capsuleHalf = 2.0f;
|
|
|
|
float capsuleRadius = 1.0f;
|
|
|
|
float capsuleMass = 1.0f;
|
|
|
|
|
|
|
|
{
|
|
|
|
int size = 10;
|
|
|
|
int height = 10;
|
|
|
|
|
|
|
|
const float cubeSize = boxSize[0];
|
|
|
|
float spacing = 2.0f;
|
|
|
|
btVector3 pos(0.0f, 20.0f, 0.0f);
|
|
|
|
float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
2015-04-16 16:55:32 +00:00
|
|
|
int numBodies = 0;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int k = 0; k < height; k++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < size; j++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 bpos = btVector3(0, 25, 0) + btVector3(5.0f, 1.0f, 5.0f) * pos;
|
2015-04-16 16:55:32 +00:00
|
|
|
int idx = rand() % 9;
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
trans.setOrigin(bpos);
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
switch (idx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float r = 0.5f * (idx + 1);
|
|
|
|
btBoxShape* boxShape = new btBoxShape(boxSize * r);
|
|
|
|
createRigidBody(boxMass * r, trans, boxShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float r = 0.5f * (idx - 3 + 1);
|
|
|
|
btSphereShape* sphereShape = new btSphereShape(sphereRadius * r);
|
|
|
|
createRigidBody(sphereMass * r, trans, sphereShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
float r = 0.5f * (idx - 6 + 1);
|
|
|
|
btCapsuleShape* capsuleShape = new btCapsuleShape(capsuleRadius * r, capsuleHalf * r);
|
|
|
|
createRigidBody(capsuleMass * r, trans, capsuleShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
numBodies++;
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
offset -= 0.05f * spacing * (size - 1);
|
2015-04-16 16:55:32 +00:00
|
|
|
spacing *= 1.1f;
|
|
|
|
pos[1] += (cubeSize * 2.0f + spacing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createLargeMeshBody();
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest6()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
setCameraDistance(btScalar(250.));
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 boxSize(1.5f, 1.5f, 1.5f);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
btConvexHullShape* convexHullShape = new btConvexHullShape();
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < TaruVtxCount; i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 vtx(TaruVtx[i * 3], TaruVtx[i * 3 + 1], TaruVtx[i * 3 + 2]);
|
2015-04-16 16:55:32 +00:00
|
|
|
convexHullShape->addPoint(vtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
btTransform trans;
|
|
|
|
trans.setIdentity();
|
|
|
|
|
|
|
|
float mass = 1.f;
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 localInertia(0, 0, 0);
|
|
|
|
convexHullShape->calculateLocalInertia(mass, localInertia);
|
2015-04-16 16:55:32 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
int size = 10;
|
|
|
|
int height = 10;
|
|
|
|
|
|
|
|
const float cubeSize = boxSize[0];
|
|
|
|
float spacing = 2.0f;
|
|
|
|
btVector3 pos(0.0f, 20.0f, 0.0f);
|
|
|
|
float offset = -size * (cubeSize * 2.0f + spacing) * 0.5f;
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
for (int k = 0; k < height; k++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < size; j++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[2] = offset + (float)j * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2015-04-16 16:55:32 +00:00
|
|
|
pos[0] = offset + (float)i * (cubeSize * 2.0f + spacing);
|
2018-09-23 21:17:31 +00:00
|
|
|
btVector3 bpos = btVector3(0, 25, 0) + btVector3(5.0f, 1.0f, 5.0f) * pos;
|
2015-04-16 16:55:32 +00:00
|
|
|
trans.setOrigin(bpos);
|
2018-09-23 21:17:31 +00:00
|
|
|
|
|
|
|
createRigidBody(mass, trans, convexHullShape);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
offset -= 0.05f * spacing * (size - 1);
|
2015-04-16 16:55:32 +00:00
|
|
|
spacing *= 1.1f;
|
|
|
|
pos[1] += (cubeSize * 2.0f + spacing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createLargeMeshBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BenchmarkDemo::initRays()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
raycastBar = btRaycastBar2(2500.0, 0, 50.0, m_guiHelper);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BenchmarkDemo::castRays()
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
raycastBar.cast(m_dynamicsWorld, m_multithreadedWorld);
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::createTest7()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
createTest6();
|
|
|
|
setCameraDistance(btScalar(150.));
|
|
|
|
initRays();
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:13:08 +00:00
|
|
|
void BenchmarkDemo::createTest8()
|
|
|
|
{
|
|
|
|
float dist = 8;
|
|
|
|
float pitch = -15;
|
|
|
|
float yaw = 20;
|
|
|
|
float targetPos[3] = {0, 1, 0};
|
|
|
|
m_guiHelper->resetCamera(dist, yaw, pitch, targetPos[0], targetPos[1], targetPos[2]);
|
|
|
|
// Create a shape and rigid body for each Voronoi cell.
|
|
|
|
const float fallHeight = 3.5f;
|
|
|
|
for (int i=0; i<halton_numc; ++i)
|
|
|
|
{
|
|
|
|
btConvexHullShape* shp = new btConvexHullShape();
|
|
|
|
const float* verts = halton_verts[i];
|
|
|
|
const float* origin = halton_pos[i];
|
|
|
|
for (int v=0; v<halton_numv[i]; ++v)
|
|
|
|
{
|
|
|
|
btVector3 vtx(verts[0],verts[1],verts[2]);
|
|
|
|
shp->addPoint(vtx);
|
|
|
|
verts += 3;
|
|
|
|
}
|
|
|
|
shp->initializePolyhedralFeatures();
|
|
|
|
shp->setMargin(0.04f);
|
|
|
|
btTransform transform;
|
|
|
|
transform.setIdentity();
|
|
|
|
transform.setOrigin(btVector3(origin[0],origin[1]+fallHeight,origin[2]));
|
|
|
|
const float mass = halton_volu[i];
|
|
|
|
btVector3 inertia(0,0,0);
|
|
|
|
shp->calculateLocalInertia(mass, inertia);
|
|
|
|
btRigidBody::btRigidBodyConstructionInfo ci(mass, 0, shp, inertia);
|
|
|
|
ci.m_startWorldTransform = transform;
|
|
|
|
btRigidBody* body = new btRigidBody(ci);
|
|
|
|
body->setFriction(0.6f);
|
|
|
|
m_dynamicsWorld->addRigidBody(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
btContactSolverInfo& si = m_dynamicsWorld->getSolverInfo();
|
|
|
|
si.m_numIterations = 20;
|
|
|
|
si.m_erp = 0.8f;
|
|
|
|
si.m_erp2 = si.m_erp / 2;
|
|
|
|
si.m_globalCfm = 0.015f;
|
|
|
|
// Create a ground plane
|
|
|
|
btCollisionShape* groundplane = new btStaticPlaneShape(btVector3(0,1,0),0);
|
|
|
|
groundplane->setMargin(0.04f);
|
|
|
|
btRigidBody::btRigidBodyConstructionInfo rc(0.0f, 0, groundplane, btVector3(0,0,0));
|
|
|
|
btRigidBody* groundbody = new btRigidBody(rc);
|
|
|
|
m_dynamicsWorld->addRigidBody(groundbody);
|
|
|
|
#if 0
|
|
|
|
// Use SAT for slower, but better contact generation.
|
|
|
|
btDispatcherInfo& di = m_dynamicsWorld->getDispatchInfo();
|
|
|
|
di.m_enableSatConvex = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
void BenchmarkDemo::exitPhysics()
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
for (i = 0; i < m_ragdolls.size(); i++)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
|
|
|
RagDoll* doll = m_ragdolls[i];
|
|
|
|
delete doll;
|
|
|
|
}
|
|
|
|
m_ragdolls.clear();
|
|
|
|
|
2016-11-07 20:08:02 +00:00
|
|
|
CommonRigidBodyMTBase::exitPhysics();
|
2015-04-16 16:55:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
CommonExampleInterface* BenchmarkCreateFunc(struct CommonExampleOptions& options)
|
2015-04-16 16:55:32 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
return new BenchmarkDemo(options.m_guiHelper, options.m_option);
|
2017-06-01 22:30:37 +00:00
|
|
|
}
|