shift between Bullet world and Qt3D rendering system

mekid
Posts: 3
Joined: Thu May 31, 2012 8:46 am

shift between Bullet world and Qt3D rendering system

Post by mekid »

I have an issue,

My collision body do not fit in my QGLScenenode there is a shift. But they has the same initial 3D position.
How can i resolved this issue.


QGLAbstractScene *model = QGLAbstractScene::loadScene(":/ball.obj");
addNode(model->mainNode()->clone(this));
delete model;

btAlignedObjectArray<btVector3> verticesList;
foreach (QGLSceneNode *node, allChildren())
{
QGeometryData gmData = node->geometry();
if (gmData.vertices().isEmpty()) { continue; }
for (int i = 0; i<gmData.vertices().size(); i++)
{
btVector3 vertex(gmData.vertex(i).x(), gmData.vertex(i).y(), gmData.vertex(i).z());
verticesList.push_back(vertex);

}
break;
}

btCompoundShape *compoundShape = new btCompoundShape;
compoundShape->setUserPointer(this);

btConvexHullShape* shape = new btConvexHullShape(&(verticesList[0].getX()),verticesList.size());

// btMatrix3x3 bmatrix = btMatrix3x3(1, 0, 0,
// 0, 1, 0,
// 0, 0, 1);
// btTransform trans = btTransform(bmatrix, btVector3(-pos.x(), -pos.y(), -pos.z()));

btScalar mass = 0.000;
btVector3 inertia(0, 0, 0);
shape->calculateLocalInertia(mass,inertia);
btRigidBody::btRigidBodyConstructionInfo bodyCI(mass, this, shape, inertia);
m_Body = new btRigidBody(bodyCI);
m_Body->setUserPointer(this);
world->addRigidBody(m_Body);
DestroyerOfCities
Posts: 20
Joined: Fri Dec 10, 2010 3:39 am

Re: shift between Bullet world and Qt3D rendering system

Post by DestroyerOfCities »

Your description is pretty vague, are you saying that they start in the same position but then don't line up once they move?

Is the initial position 0, 0, 0? Can you isolate which axis the shift occurs on?

(Did you try -z?)
mekid
Posts: 3
Joined: Thu May 31, 2012 8:46 am

Re: shift between Bullet world and Qt3D rendering system

Post by mekid »

Sorry for the poverty of my explanations :(.

There is a shift for all the axes.

- When i create an object with initial position (0 0 0) collision and 3d object are line up.
But when the object moves there is a shift between them, the collision shape moves faster than my 3D object.
Ball *m_Ball = new Ball(m_DynamicsWorld, QVector3D(0.0f, 0.0f, 0.0f);

- When the object is created at none zero initial position ex(0 5 0) there is an initial shift between them. the shift increases when i move them.
Ball *m_Ball = new Ball(m_DynamicsWorld, QVector3D(0.0f, 5.0f, 0.0f);

When i print the world position and Qt3D position it's the same values


MyObject::MyObject(btDiscreteDynamicsWorld *world,
const QVector3D &pos,
const QQuaternion &quaternion,
QObject *parent)
: QGLSceneNode(parent),
m_World(world),
m_Body(0),
m_GameObjectType(UNKNOWN),
m_Pos(btTransform(btQuaternion(quaternion.x(),
quaternion.y(),
quaternion.z(),
quaternion.scalar()),
btVector3(pos.x(), pos.y(), pos.z())))
{

// If the game object does not have Bullet body (which would move
// QGLSceneNode) we set the position and orientation of QGLSceneNode
// initially here.
setPosition(pos);

QMatrix4x4 mat = localTransform();
mat.rotate(quaternion);
setLocalTransform(mat);
}

void MyObject::getWorldTransform(btTransform& worldTrans) const
{
worldTrans = m_Pos;
qDebug()<<"DEP POS: ("<<worldTrans.getOrigin().x()<<" "<<worldTrans.getOrigin().y()<<" "<<worldTrans.getOrigin().z()<<")";
}


void MyObject::setWorldTransform(const btTransform& worldTrans)
{
m_Pos = worldTrans;

float ftemp[16];
worldTrans.getOpenGLMatrix(ftemp);

// qDebug()<<"DEP POS: ("<<worldTrans.getOrigin().x()<<" "<<worldTrans.getOrigin().y()<<" "<<worldTrans.getOrigin().z()<<")";

QMatrix4x4 ntrans( ftemp[0], ftemp[4], ftemp[8], 0.0f,
ftemp[1], ftemp[5], ftemp[9], 0.0f,
ftemp[2], ftemp[6], ftemp[10], 0.0f,
0.0f, 0.0f, 0.0f, 1.0f );

setLocalTransform(ntrans);
setPosition(QVector3D(ftemp[12], ftemp[13], ftemp[14]));
}