Hello togehter.
I've got a realy irritating problem: I wrote a simple application with bullet and now tried to render the scene but something wierd happend. Everytime I read the position of an object I get the initial or the current position of the object. Or in other words it seems that there are two different objects, one at the initial position(static) and one at the current positon (moving around).
Has anyone a suggestion what my mistake is and/or can me say how to fix it?
rendering problems
-
- Posts: 17
- Joined: Fri Apr 03, 2009 9:12 am
Re: rendering problems
Am I really the only one who has this problem? Has no one an idea how I can fix this?
-
- Posts: 34
- Joined: Tue Mar 04, 2008 3:16 pm
Re: rendering problems
Seems like it. Perhaps you should provide some code.PolyFlo wrote:Am I really the only one who has this problem?
-
- Posts: 17
- Joined: Fri Apr 03, 2009 9:12 am
Re: rendering problems
Ok, I hope that helps. I am a newbie with Bullet, maybe i forgot something. I tried to 'copy' the Softbody Demo in my own application.
This is the cpp for the Softbody:
And the cpp for the rigid Bodys:
Here I initialise The Bullet world:
And here I make the objects:
Every step in the animation I call the step simulation with the elapsed time (like in the demo):
For the rendering I just call the render method for the objects.
I really hope someone can help me with that.
This is the cpp for the Softbody:
Code: Select all
#include "OGLSoftbody.h"
#include <Cube4MeshOrg.h>
//#include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
#include <BulletSoftBody/btSoftBodyHelpers.h>
OGLSoftbody::OGLSoftbody(btScalar mass, const btVector3 &initPos, btSoftBodyWorldInfo& worldInfo)
{
m_Softbody=btSoftBodyHelpers::CreateFromTriMesh(worldInfo,gVerticesCube4,
&gIndicesCube4[0][0],
CUBE4_NUM_TRIANGLES);
btSoftBody::Material* pm=m_Softbody->appendMaterial();
pm->m_kLST = 0.5;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
m_Softbody->generateBendingConstraints(2,pm);
m_Softbody->m_cfg.piterations = 2;
m_Softbody->m_cfg.kDF = 0.5;
m_Softbody->randomizeConstraints();
m_Softbody->setTotalMass(mass,true);
m_Softbody->translate(initPos);
file.Init("logDebug.txt");
counter = 0;
}
OGLSoftbody::~OGLSoftbody(void)
{
}
void OGLSoftbody::render(Rendermode mode, bool renderNormals, bool showAABB)
{
int numFace = m_Softbody->m_faces.size();
btVector3 test = m_Softbody->m_nodes[0].m_x;
file+string(file.itoa(counter++)+" X: "+file.ftoa(test.x())+" Y: "+file.ftoa(test.y())+" Z: "+file.ftoa(test.z()));
glPushMatrix();
glBegin(GL_TRIANGLES);
for (int i=0; i<numFace; i++)
{
btVector3 a = m_Softbody->m_faces[i].m_n[0]->m_x;
btVector3 b = m_Softbody->m_faces[i].m_n[1]->m_x;
btVector3 c = m_Softbody->m_faces[i].m_n[2]->m_x;
btVector3 dirab = b-a;
btVector3 dirac = c-a;
btVector3 normal = dirab.cross(dirac);
glNormal3f(normal.x(), normal.y(), normal.z());
glColor4f (255, 255, 0, 1.0f );
glVertex3f(a.x(), a.y(), a.z());
glVertex3f(b.x(), b.y(), b.z());
glVertex3f(c.x(), c.y(), c.z());
}
glEnd( );
glPopMatrix();
}
btSoftBody* OGLSoftbody::getSoftbody()
{
return m_Softbody;
}
Code: Select all
#include <BulletTestQuad.h>
BulletTestQuad::BulletTestQuad(btScalar mass, Vertex initPos, double kantenlaenge)
{
m_Kantenlaenge = kantenlaenge;
m_Mass = mass;
initBullet(initPos);
}
BulletTestQuad::~BulletTestQuad()
{
}
void BulletTestQuad::render(Rendermode mode, bool renderNormals, bool showAABB)
{
double X = m_MotionState->m_Pos.x();
double Y = m_MotionState->m_Pos.y();
double Z = m_MotionState->m_Pos.z();
glPushMatrix();
{
glColor3d(m_Color.x,m_Color.y,m_Color.z);
if(m_Mass<PERCESION)
{
btScalar m[16];
m_MotionState->m_PosInit.getOpenGLMatrix(m);
glMultMatrixf(m);
}
else
{
glTranslated(m_MotionState->m_Pos.x(),
m_MotionState->m_Pos.y(),
m_MotionState->m_Pos.z());
glRotated((m_MotionState->m_RotAngle)*(180/PI),
m_MotionState->m_RotAxis.x(),
m_MotionState->m_RotAxis.y(),
m_MotionState->m_RotAxis.z());
}
glutSolidCube(m_Kantenlaenge);
}
glPopMatrix();
}
btRigidBody* BulletTestQuad::getRigidBody()
{
return m_Body;
}
void BulletTestQuad::initBullet(Vertex initPos)
{
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(initPos.x,initPos.y,initPos.z));
m_MotionState = new QtTetraMotionState(transform);
m_Shape = new btBoxShape(btVector3(btScalar(m_Kantenlaenge/2.0),
btScalar(m_Kantenlaenge/2.0),
btScalar(m_Kantenlaenge/2.0)));
btVector3 localInertia(0,0,0);
if (m_Mass>PERCESION)
{
m_Shape->calculateLocalInertia(m_Mass,localInertia);
}
btRigidBody::btRigidBodyConstructionInfo rbInfo(m_Mass,m_MotionState,m_Shape,localInertia);
m_Body = new btRigidBody(rbInfo);
return;
}
void BulletTestQuad::setColor(Vertex color)
{
m_Color = color;
}
Code: Select all
void GlWidget::initBullet()
{
//Soft Body Dynamics
m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_softBodyWorldInfo.m_dispatcher = m_dispatcher;
btVector3 worldAabbMin(-1000,-1000,-1000);
btVector3 worldAabbMax(1000,1000,1000);
m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
m_softBodyWorldInfo.m_broadphase = m_broadphase;
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver();
m_solver = solver;
btDiscreteDynamicsWorld* world = new btSoftRigidDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld = world;
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
btVector3 gravity(0,-60,0);
m_dynamicsWorld->setGravity(gravity);
m_softBodyWorldInfo.m_gravity = gravity;
}
Code: Select all
void GlWidget::initRenderObjects()
{
OGLSoftbody* soft = new OGLSoftbody(100,btVector3(0,0,0),m_softBodyWorldInfo);
BulletTestQuad* wuerfel = new BulletTestQuad(50.0f, Vertex(0,6,0),1.0);
wuerfel->setColor(Vertex(1.0,0,0));
BulletTestQuad* wuerfel2 = new BulletTestQuad(0.5f, Vertex(-0.6,4,0),1.0);
wuerfel2->setColor(Vertex(1.0,0,0));
BulletTestQuad* boden = new BulletTestQuad(0.0f, Vertex(0,-15.0,0),20.0);
boden->setColor(Vertex(0.25,0.25,0.25));
renderObjects.push_back(dynamic_cast<OGLRenderObject*>(wuerfel));
renderObjects.push_back(dynamic_cast<OGLRenderObject*>(wuerfel2));
renderObjects.push_back(dynamic_cast<OGLRenderObject*>(boden));
renderObjects.push_back(dynamic_cast<OGLRenderObject*>(soft));
this->m_dynamicsWorld->addRigidBody(wuerfel->getRigidBody());
this->m_dynamicsWorld->addRigidBody(wuerfel2->getRigidBody());
this->m_dynamicsWorld->addRigidBody(boden->getRigidBody());
((btSoftRigidDynamicsWorld*)m_dynamicsWorld)->addSoftBody(soft->getSoftbody());
}
Code: Select all
float ms = getDeltaTimeMicroseconds();
///step the simulation
if (m_dynamicsWorld)
{
m_dynamicsWorld->stepSimulation(ms);//ms / 1000000.f
}
I really hope someone can help me with that.
-
- Posts: 34
- Joined: Tue Mar 04, 2008 3:16 pm
Re: rendering problems
What is QtTetraMotionState?
-
- Posts: 17
- Joined: Fri Apr 03, 2009 9:12 am
Re: rendering problems
Oh, sorry, I forgot that. This is the MotionState I wrote. But I tested it also with the default one but the mistake was still there.
Code: Select all
#include "QtTetraMotionState.h"
QtTetraMotionState::QtTetraMotionState(const btTransform &initialpos)
{
m_PosInit = initialpos;
m_RotAngle = 0.0;
m_RotAxis = btVector3(1,0,0);
}
QtTetraMotionState::~QtTetraMotionState()
{
}
void QtTetraMotionState::getWorldTransform(btTransform &worldTrans)const
{
worldTrans = m_PosInit;
}
void QtTetraMotionState::setWorldTransform(const btTransform &worldTrans)
{
m_PosInit = worldTrans;
btQuaternion rot = worldTrans.getRotation();
m_RotAngle = rot.getAngle();
m_RotAxis = rot.getAxis();
m_Pos = worldTrans.getOrigin();
return;
}
-
- Posts: 17
- Joined: Fri Apr 03, 2009 9:12 am
Re: rendering problems
Ok, I solved the problem.
QT called my init-method two times. This seems to confuse Bullet. Now everything is working fine
QT called my init-method two times. This seems to confuse Bullet. Now everything is working fine