add joint/constraint solver support (using CPU, Bullet 2.x solver), in combination with GPU contact solver
This commit is contained in:
28
demo/gpudemo/rigidbody/Bullet2GpuDemo.cpp
Normal file
28
demo/gpudemo/rigidbody/Bullet2GpuDemo.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "Bullet2GpuDemo.h"
|
||||
#include "../btGpuDynamicsWorld.h"
|
||||
#include "GpuRigidBodyDemoInternalData.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "gpu_rigidbody/host/btRigidBody.h"
|
||||
|
||||
void Bullet2GpuDemo::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
|
||||
// m_data->m_np = np;
|
||||
// m_data->m_bp = bp;
|
||||
// m_data->m_rigidBodyPipeline
|
||||
m_gpuDynamicsWorld = new btGpuDynamicsWorld(m_data->m_bp,m_data->m_np,m_data->m_rigidBodyPipeline);
|
||||
|
||||
btVector3 halfExtents(100,1,100);
|
||||
btBoxShape* boxShape = new btBoxShape(halfExtents);
|
||||
btVector3 localInertia;
|
||||
btScalar mass=1.f;
|
||||
boxShape->calculateLocalInertia(mass,localInertia);
|
||||
btRigidBody* body = new btRigidBody(mass,0,boxShape,localInertia);
|
||||
m_gpuDynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
void Bullet2GpuDemo::destroyScene()
|
||||
{
|
||||
delete m_gpuDynamicsWorld;
|
||||
m_gpuDynamicsWorld = 0;
|
||||
}
|
||||
31
demo/gpudemo/rigidbody/Bullet2GpuDemo.h
Normal file
31
demo/gpudemo/rigidbody/Bullet2GpuDemo.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef BULLET2_GPU_DEMO_H
|
||||
#define BULLET2_GPU_DEMO_H
|
||||
|
||||
#include "GpuRigidBodyDemo.h"
|
||||
|
||||
class Bullet2GpuDemo : public GpuRigidBodyDemo
|
||||
{
|
||||
protected:
|
||||
|
||||
class btGpuDynamicsWorld* m_gpuDynamicsWorld;
|
||||
|
||||
public:
|
||||
|
||||
Bullet2GpuDemo(){}
|
||||
virtual ~Bullet2GpuDemo(){}
|
||||
virtual const char* getName()
|
||||
{
|
||||
return "Bullet2Gpu";
|
||||
}
|
||||
|
||||
static GpuDemo* MyCreateFunc()
|
||||
{
|
||||
GpuDemo* demo = new Bullet2GpuDemo;
|
||||
return demo;
|
||||
}
|
||||
|
||||
virtual void setupScene(const ConstructionInfo& ci);
|
||||
virtual void destroyScene();
|
||||
};
|
||||
#endif //BULLET2_GPU_DEMO_H
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "gpu_rigidbody/host/b3Config.h"
|
||||
#include "GpuRigidBodyDemoInternalData.h"
|
||||
#include "../gwenUserInterface.h"
|
||||
|
||||
#include "Bullet3Dynamics/ConstraintSolver/b3Point2PointConstraint.h"
|
||||
|
||||
void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
@@ -83,6 +83,9 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
|
||||
|
||||
int curColor = 0;
|
||||
float scaling[4] = {1,1,1,1};
|
||||
int prevBody = -1;
|
||||
int insta = 0;
|
||||
|
||||
int colIndex = m_data->m_np->registerConvexHullShape(&vertices[0],strideInBytes,numVertices, scaling);
|
||||
//int colIndex = m_data->m_np->registerSphereShape(1);
|
||||
for (int i=0;i<ci.arraySizeX;i++)
|
||||
@@ -92,9 +95,12 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
|
||||
for (int k=0;k<ci.arraySizeZ;k++)
|
||||
{
|
||||
float mass = 1.f;
|
||||
|
||||
b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
|
||||
//b3Vector3 position(i*2.2,1+j*2.,k*2.2);
|
||||
if (j==0)//ci.arraySizeY-1)
|
||||
{
|
||||
//mass=0.f;
|
||||
}
|
||||
//b3Vector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
|
||||
b3Vector3 position(i*2.2,10+j*2.2,k*2.2);
|
||||
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
|
||||
@@ -105,6 +111,14 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index,false);
|
||||
|
||||
|
||||
if (prevBody>=0)
|
||||
{
|
||||
b3Point2PointConstraint* p2p = new b3Point2PointConstraint(pid,prevBody,b3Vector3(0,-1.1,0),b3Vector3(0,1.1,0));
|
||||
// m_data->m_rigidBodyPipeline->addConstraint(p2p);//,false);
|
||||
}
|
||||
prevBody = pid;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user