Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: use bullet in 2D
PostPosted: Sat Dec 13, 2008 5:10 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
Hi,

I am trying to use bullet in a 2D plane. I add btGImpactConvexDecompositionShape in a world (shape draw with hand).. And I wants to restricts shape to a 2D plane (X,Y movement and only Z axis rotation). I use latest 2.73SP1 bullet physics SDK. I have read "I want to constrain an object to two dimensional movement, skipping one of the cardinal axes" but it don't works ... there is no visible constraint.. I have read previous topic in forum . it seems there is a bug ? and I need to have lock axis with one value for min, and previous value + epsilon . But it's the same ? I don't understand why it's not working ? Is there a bug in SDK ?

Best regards,

kao


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Mon Dec 15, 2008 11:34 am 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
Hi,

I have worked a lot to find a solution... But It don't works. I am new to bullet. please help me ... all is working fine except that.

kaolite


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Mon Dec 15, 2008 1:28 pm 
Offline

Joined: Fri May 30, 2008 2:51 am
Posts: 508
Location: Ossining, New York
More information and code is probably needed


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Wed Dec 17, 2008 9:36 am 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
some information :

I init the bullet engine :
// Build the broadphase
int maxProxies=1024;
btVector3 worldAabbMin(-2000,-2000,-1000);
btVector3 worldAabbMax(2000,2000,1000);
m_broadphase=new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);// Sweep and Prune Standard algo

// Set up the collision configuration and dispatcher
m_collisionConfiguration=new btDefaultCollisionConfiguration();
m_dispatcher=new btCollisionDispatcher(m_collisionConfiguration); // btCollisionDispatcher : handle Convex-Concave and Convex-Convex Collision

// The actual physics solver
m_solver=new btSequentialImpulseConstraintSolver;

// The Dynamic world.
m_dynamicsWorld=new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0,-10,0));

// Ground
m_groundShape=new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState* groundMotionState=new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));

// Mass : Zero (static), shape : Plane , Inertial Tensor : Null
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,m_groundShape,btVector3(0,0,0));
m_groundRigidBody=new btRigidBody(groundRigidBodyCI);
dynamicsWorld()->addRigidBody(m_groundRigidBody);//,COL_GROUND,COL_SHAPE|COL_GROUND);

// Constraint to Z=0 plan
m_zerobody=new btRigidBody(0,NULL,NULL);
dynamicsWorld()->addRigidBody(m_zerobody);
m_zerobody->setActivationState(DISABLE_DEACTIVATION);

//register algorithm
btCollisionDispatcher * dispatcher=static_cast<btCollisionDispatcher*>(m_dynamicsWorld->getDispatcher());
btGImpactCollisionAlgorithm::registerAlgorithm(dispatcher);


// Then each time I add a shape to my engine :

btTriangleMesh *triangleMesh=new btTriangleMesh();
int i;
PointVert *tpoint1,*tpoint2,*tpoint3;
for(i=0;i<vectlist.count();i+=3)
{
tpoint1=vectlist.value(i);
tpoint2=vectlist.value(i+1);
tpoint3=vectlist.value(i+2);
triangleMesh->addTriangle(btVector3(tpoint1->val[0],tpoint1->val[1],tpoint1->val[2]),btVector3(tpoint2->val[0],tpoint2->val[1],tpoint2->val[2]),btVector3(tpoint3->val[0],tpoint3->val[1],tpoint3->val[2]));
}

// Create Shape
btConvexTriangleMeshShape* gimpact=new btConvexTriangleMeshShape(triangleMesh);
btShapeHull* triHull=new btShapeHull(gimpact);
btScalar margin=gimpact->getMargin();
triHull->buildHull(margin);

btConvexHullShape* simplifiedShape=new btConvexHullShape();
for (i=0;i<triHull->numVertices();i++)
{
simplifiedShape->addPoint(triHull->getVertexPointer()[i]);
}
m_physicShape=simplifiedShape;

// DELETE UNUSED SHAPE !!!!!! TO ADD !!!!!
delete gimpact;
delete triHull;

// Set Motion State
btMotionState* MotionState=new OgreMotionState(m_node);

// Create Rigid Body
btScalar mass=1000;
btScalar restitution=1;
btScalar friction=0;
btVector3 localInertia(0,0,0);
m_physicShape->calculateLocalInertia(mass,localInertia);
// Mass : mass, shape : , Inertial Tensor : Null
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass,MotionState,m_physicShape,localInertia);
m_rigidBody=new btRigidBody(rigidBodyCI);
m_rigidBody->setRestitution(restitution);
m_rigidBody->setFriction(friction);
m_rigidBody->setActivationState(DISABLE_DEACTIVATION);
layer()->dynamicsWorld()->addRigidBody(m_rigidBody);//,COL_SHAPE,COL_SHAPE|COL_GROUND);

// Constraint
m_constrict=new btGeneric6DofConstraint(*m_rigidBody,*layer()->zeroBody(),btTransform::getIdentity(),btTransform::getIdentity(),false);
// Use limit(axis, a, b) where a>b to disable limits on that axis
m_constrict->setLinearLowerLimit(btVector3(-2000,-2000,0.00001));
m_constrict->setLinearUpperLimit(btVector3(2000,2000,0));
m_constrict->setAngularLowerLimit(btVector3(0.00001,0.00001,0.00001));
m_constrict->setAngularUpperLimit(btVector3(0,0,0));
layer()->dynamicsWorld()->addConstraint(m_constrict,true);


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Wed Dec 17, 2008 6:10 pm 
Offline

Joined: Tue Oct 30, 2007 9:23 pm
Posts: 146
Code:
m_constrict->setLinearLowerLimit(btVector3(-2000,-2000,0.00001));
m_constrict->setLinearUpperLimit(btVector3(2000,2000,0));


Your lower limit on the Z axis is higher than the upper limit on that axis, which effectively disables limits on that axis at all

Gary (-;


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Thu Dec 18, 2008 4:12 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
sorry it was old code, I use this code without success:

m_constrict->setLinearLowerLimit(btVector3(1,1,0));
m_constrict->setLinearUpperLimit(btVector3(0,0,0));
m_constrict->setAngularLowerLimit(btVector3(0,0,1));
m_constrict->setAngularUpperLimit(btVector3(0,0,0));

I don't know what's to do... It seems that it's possible to constraint bullet in 2D.


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Thu Dec 18, 2008 6:41 pm 
Offline

Joined: Tue Oct 30, 2007 9:23 pm
Posts: 146
Well, FWIW I wrote that code snippet for constraining bullet to 2d, and it's working for me. I do note that you're using set{Linear,Angular}{Upper,Lower} limit, and that's not what I actually use. The code snippet I put on the wiki uses 6dof->setLimit, perhaps you could try that?

Gary (-;


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Thu Dec 18, 2008 6:46 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
thanks for the answer ... but I have tryed with your wiki add ... using setLimit ... but I have the same trouble


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Fri Dec 19, 2008 9:35 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
hello,
After loosing a lot of time trying to use bullet in 2D... It seems that it's better for me to change engine ... perhaps box2d is best for that...


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Mon Dec 22, 2008 9:39 am 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
I am back :).... after trying to using box2d, not working with triangle mesh,
Physx : no collision between triangle mesh....
I am back to Bullet, the winner .... triangle mesh with collision detection between triangle mesh....
but I don't know what's wrong to constraint to a 2D world ... I don't know if I do some mistake or if it's a bug in Bullet engine...

Best regards


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Wed Jan 14, 2009 8:45 pm 
Offline

Joined: Thu Aug 11, 2005 11:34 pm
Posts: 3
Did you find a solution to this? I've tried both the 2D constraint code from the Wiki and from the user manual without success.


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Wed Jan 14, 2009 10:18 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
No ... it's always not working. I have lost a lot of time on this without success. It seems that there is a bug in bullet or the wiki is wrong. I am not the only one.

kao


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Thu Jan 15, 2009 8:18 pm 
Offline

Joined: Fri May 11, 2007 7:06 am
Posts: 16
have you tried a simple cube/sphere?

seems like there was some tricks i had to do to get it work, but here's my relevant code:

Code:
dfCollisionShape *ZeroShape = NULL;
ZeroBody = new dfRigidBody(0.0f, NULL, ZeroShape);

dfTransform Rotation;
Rotation.setIdentity();
ZeroBody->setWorldTransform(Rotation);

....

Constraint = new dfGeneric6DofConstraint(*Body, *ZeroBody, dfTransform::getIdentity(), dfTransform::getIdentity(), false);
Constraint->setLimit(0, 0, 0);
Constraint->setLimit(1, 1, 0);
Constraint->setLimit(2, 1, 0);
Constraint->setLimit(3, 1, 0);
Constraint->setLimit(4, 1, 0);
Constraint->setLimit(5, 1, 0);

PhysicsWorld->addConstraint(Constraint, true);


...

// Update constraint
dfTransform ConstraintTransform(SkateTransform.getBasis(), Transform.getOrigin());
ZeroBody->setWorldTransform(ConstraintTransform);


This was for a skateboarding game, so i constrained it to the Y-Z plane instead of X, but it's all the same. I also had to update the position of the zerobody every frame, but this is only cause i was rotating the plane about the Y-Axis, so you shouldn't have to do this.


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Sat Jan 17, 2009 9:17 pm 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
I think it don't works when you try to restrict an object translation to one plane, and only one axis of rotation (a true 2D movement)


Top
 Profile  
 
 Post subject: Re: use bullet in 2D
PostPosted: Tue Jan 20, 2009 9:12 am 
Offline

Joined: Sat Dec 13, 2008 5:05 pm
Posts: 13
I have just retry with the last svn bullet. It seems better, but when two object collides they move on the Z axis (It's better because I have no more rotation the X and the Y axis ). I have the following constraint :

m_constrict->setLimit(0,1,0); // Disable X axis limits
m_constrict->setLimit(1,1,0); // Disable Y axis limits
m_constrict->setLimit(2,0,0); // Set the Z axis to always be equal to zero
m_constrict->setLimit(3,0,0); // Disable X rotational axes
m_constrict->setLimit(4,0,0); // Disable Y rotational axes
m_constrict->setLimit(5,1,0); // Uncap the rotational axes

hopes it help to fixe the issue ...:)


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 6 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