Jump to content

  • Log In with Google      Sign In   
  • Create Account


Detect collision only with a shape (No physics)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 19 November 2012 - 01:02 AM

I am loading a mesh, this mesh will be invisible, so I want to only detect collision with it, other meshes should be able to intersect with it, the only purpose is to detect collision.

I'm able to detect collision but the mesh is treated as physical mesh and other meshes can't intersect with it.

How do I make the mesh intersectable? I want to ONLY detect collision

Here is the code I'm using:
btConvexHullShape* invisibleShape = new btConvexHullShape((btScalar*)btVertices, numVertices, sizeof(btVector3));
btAlignedObjectArray<btCollisionShape*> collisionShapes;
collisionShapes.push_back(invisibleShape);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0.0f,0.0f,0.0f));
btScalar mass(.0);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);

 

if (isDynamic)
    invisibleShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,invisibleShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);



Sponsor:

#2 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 19 November 2012 - 02:26 AM

Resolved after using the flag btRigidBody::CF_NO_CONTACT_RESPONSE, now I want to exclude the mesh from raycasting, how can I do that?

#3 Ashaman73   Crossbones+   -  Reputation: 6691

Like
0Likes
Like

Posted 19 November 2012 - 04:37 AM

Take a look at btGhostObject .

#4 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 19 November 2012 - 06:29 AM

How can I load a sphere into btGhostObject?

#5 Ashaman73   Crossbones+   -  Reputation: 6691

Like
0Likes
Like

Posted 19 November 2012 - 07:44 AM

btGhostOjbect inherits, like btRigidBody, from btCollisionObject, therefore you can set a collision shape the same way as when using a btRigidBody.

#6 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 19 November 2012 - 04:03 PM

I know that, but usually I initialize btRigidBody by giving information about the mesh, such as the radius if it's a sphere, how can I make the following sphere btGhostOjbect?
btSphereShape *sphere = new btSphereShape(500.0f);


#7 xexuxjy   Members   -  Reputation: 561

Like
1Likes
Like

Posted 22 November 2012 - 07:36 AM

as both btGhostObject and btRigidBody derive from btCollisionObject you can just do :

btSphereShape *sphere = new btSphereShape(500.0f);
btGhostObject* ghost = new btGhostObject();
ghost->setCollisionShape(sphere);

(which you could also do on the rigid body rather than setting the collision shape in the btRigidBodyConstructionInfo and passing that to the btRigidBody ctor.

make sure you do all this before adding it to the collisionWorld though.

#8 Medo3337   Members   -  Reputation: 665

Like
0Likes
Like

Posted 25 November 2012 - 01:31 PM

Thanks!

Edited by Medo3337, 25 November 2012 - 01:33 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS