Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Jun 04, 2012 2:54 pm 
Offline

Joined: Thu May 31, 2012 8:46 am
Posts: 3
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);


Top
 Profile  
 
PostPosted: Tue Jun 05, 2012 12:12 am 
Offline

Joined: Fri Dec 10, 2010 3:39 am
Posts: 15
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?)


Top
 Profile  
 
PostPosted: Tue Jun 05, 2012 1:27 pm 
Offline

Joined: Thu May 31, 2012 8:46 am
Posts: 3
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]));
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group