Physics Simulation Forum

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: check collision masks when collidingPosted: Fri Jun 16, 2017 8:53 am

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);
//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?

Cheers

Top

 Post subject: Re: check collision masks when collidingPosted: Fri Jun 16, 2017 9:11 am

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

 Post subject: Re: check collision masks when collidingPosted: Fri Jun 16, 2017 12:26 pm

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

What do you mean by "too early" ?

Top

 Post subject: Re: check collision masks when collidingPosted: Sat Jun 17, 2017 4:10 pm

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 [ 654.84 KiB | Viewed 622 times ]
Top

 Post subject: Re: check collision masks when collidingPosted: Mon Jun 19, 2017 7:31 am

Joined: Thu Mar 24, 2016 10:22 am
Posts: 38
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Google [Bot] and 14 guests

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

Search for:
 Jump to:  Select a forum ------------------ BULLET PHYSICS LIBRARY USERS    General Bullet Physics Support and Feedback    Release Announcements    Applications, Games, Demos or Movies using Bullet PHYSICS AUTHORING TOOLS, SERIALIZATION AND STANDARDS    Physics authoring tools, serialization, standards and related topics RESEARCH AND DEVELOPMENT IN COLLISION DETECTION & PHYSICS. Don't post Bullet support questions here!    Research and development discussion about Collision Detection and Physics Simulation    Links, Papers, Libraries, Demos, Movies, Comparisons       Non-technical forum and license/patent discussion    Career Opportunities