Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Fri Jun 16, 2017 8:53 am 
Offline

Joined: Thu Jun 15, 2017 9:32 am
Posts: 7
Hi!

I have a spaceship an cubes. I am adding those to the dynamicsWorld like so:
Code:
#define BIT(x) (1<<(x))
enum collisiontypes {
   COL_NOTHING = 0, //<Collide with nothing
   COL_GROUND = BIT(0), //<Collide with ground
   COL_WALL = BIT(1), //<Collide with walls
   COL_CUBE = BIT(2), //<Collide with powerups
   COL_SHIP = BIT(3) //<Collide with ship
};

int shipCollidesWith = COL_WALL | COL_CUBE;
int wallCollidesWith = COL_SHIP;
int cubeCollidesWith = COL_SHIP;
int groundCollidesWith = COL_NOTHING;

Code:
colShapeCube = new btBoxShape(btVector3(edge_length, edge_length, edge_length));
Physics::addCollisionShape(colShapeCube, px, py, pz, mass, COL_CUBE, cubeCollidesWith);
Code:

btRigidBody* Physics::addCollisionShape(btCollisionShape* colShape, float px, float py, float pz, float mass, int group, int mask)
{
   btTransform startTransform;
   startTransform.setIdentity();

   btScalar tMass(mass);

   //rigidbody is dynamic if and only if mass is non zero, otherwise static
   bool isDynamic = (tMass != 0.f);

   btVector3 localInertia(0, 0, 0);
   if (isDynamic)
      colShape->calculateLocalInertia(tMass, localInertia);

   startTransform.setOrigin(btVector3(px, py, pz));

   //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
   btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
   btRigidBody::btRigidBodyConstructionInfo rbInfo(tMass, myMotionState, colShape, localInertia);
   btRigidBody* body = new btRigidBody(rbInfo);
   dynamicsWorld->addRigidBody(body,group,mask);
   //collision
   return body;
}


Now i want to check for collisions between the ship and the cube. Currently I am iterating over manifolds (wich does not seem to work perfectly yet because sometimes my ship collides even though there is nothing to collide with). How can I read the group/mask to see if it collided with a cube? Or is there generally a better way to do this?

Thanks in advance!

Cheers


Top
 Profile  
 
PostPosted: Fri Jun 16, 2017 9:11 am 
Offline

Joined: Thu Jun 15, 2017 9:32 am
Posts: 7
Ok, never mind... it already works. I am quite new to this. If I change the shipCollidesWith variable, no collisions are detected.

But still there is still the problem that the collision is detected way too early and I have no idea why..


Top
 Profile  
 
PostPosted: Fri Jun 16, 2017 12:26 pm 
Offline

Joined: Thu Mar 24, 2016 10:22 am
Posts: 34
Location: France
Hi,

What do you mean by "too early" ?


Top
 Profile  
 
PostPosted: Sat Jun 17, 2017 4:10 pm 
Offline

Joined: Thu Jun 15, 2017 9:32 am
Posts: 7
S1L3nCe wrote:
Hi,

What do you mean by "too early" ?


The problem can be seen in the picture. This is already a collision and I don't know why.. The collision is happening with the cactus. Cubes are working fine -> collision with spaceship only detected when actually collided.
Any ideas?

Cheers


Attachments:
File comment: early collision
collision.png
collision.png [ 654.84 KiB | Viewed 429 times ]
Top
 Profile  
 
PostPosted: Mon Jun 19, 2017 7:31 am 
Offline

Joined: Thu Mar 24, 2016 10:22 am
Posts: 34
Location: France
I remember having this issue when I tried to scaling my world. All was good except this kind of problem with collision.
Otherwise it could be your draw who is smaller than real size.

As cube vs Spaceship works well, a good way to know if problem come from Cactus shape could be to replace it with a boxShape and try if your problem persists


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Yahoo [Bot] and 21 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