How to determine the collision between two objects in ogrebullet

Source: Internet
Author: User

When I made my demo, there was such a problem: the character jumped up, how did I determine when it was implemented, and the problem of landing? I didn't find the relevant solution in ogrebullet, I can only use the bullet collision callback function here. The following is my practice. If there is any better method, please let me know. Thank you here.

// OgreBulletDynamics: DynamicsWorld * mWorld;

// MyInternalTickCallback is a callback function typedef void (* btInternalTickCallback) (btDynamicsWorld * world, btScalar timeStep );

 

MWorld-> getBulletDynamicsWorld ()-> setInternalTickCallback (myInternalTickCallback );

 

Void myInternalTickCallback (btDynamicsWorld * world, btScalar timeStep)
{
// Obtain the collision pair, that is, the collision of two objects produces a collision pair.
Int numManifolds = world-> getDispatcher ()-> getNumManifolds ();
For (int I = 0; I <numManifolds; I ++)
{
// Obtain index I and other collision pairs

BtPersistentManifold * contactManifold = world-> getDispatcher ()-> getManifoldByIndexInternal (I );
// Obtain the collision objects in the Collision Center
BtCollisionObject * obA = static_cast <btCollisionObject *> (contactManifold-> getBody0 ());
BtCollisionObject * obB = static_cast <btCollisionObject *> (contactManifold-> getBody1 ());

Int numContacts = contactManifold-> getNumContacts (); // multiple collision points may exist.

// Obtain the information set by the user to the collision object.

// You can add

// Std: string * rname = new std: string ("StaticTrimeshtest ");
// RigidStaticBody-> getBulletRigidBody ()-> setUserPointer (rname );

Std: string * s1 = static_cast <std: string *> (obA-> getUserPointer ());
Std: string * s2 = static_cast <std: string *> (obB-> getUserPointer ());

// Check whether s1 and s2 are the information we need. Note that if an object does not set user information, s1 or s2

// It will be a null pointer.

If (numContacts> 0 & s1 & s2)

{

// You can make a judgment here.

}

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.