pair caching rigid body

marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

pair caching rigid body

Post by marios »

i was thinking about creating new colision object which would behave like simple rigid body but in every step simulation will store contact points which concern this body. It would be like hybryd btRigidBody and btGhostObject.

Why this may be needed to? Example: bullet(small rigidbody) from weapon has to be updated every physics tick to process bullet behavior, for example check if it not collide. If collide with eg wall, floor it must be destroyed, if colide with player - destroy bullet and decrease player hitpoints. To achive this we must to call contact test on this bullet to check collisions.

I make small test and simple create every physics tick 1000 contact tests(imagine 1000 bullets/granades etc on large world with many players it is not much), that took up to many time because of checking colisions/contact points once again (before computed while step simulation). That is the reason I would like to create new cachingRigidBody - to not calculate contact points once again, only iterate over existing, stored in body(like in ghost object) = to improve performance.

I need tips to create this. I looked on ghost object and i found btGhostPairCallback - code which add OverlappingPair to array, but i realy can't see where it is calling from, who add this pairs?
Kulik
Posts: 10
Joined: Sun Jul 18, 2010 1:19 am

Re: pair caching rigid body

Post by Kulik »

I think you will have some major problems fighting collision misses when simulating bullets via small rigid bodies because the bullet will have a very high speed (Bullet isn't good at simulating bullets ;-)). Grenades are definitely doable in bullet but I would do bullets by raycasting or ContinuousCollisionDetection (which from what I have read isn't ready yet). You could do a raycast query and perform actions on hit rigidbody (if it is a player, decrease it's hitpoints).
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

Re: pair caching rigid body

Post by marios »

Yes, i now that raycast is better for bullets. I called it wrong. I meant slow moving rigidbody which must now about itself collision. For example,granade or spaceship which fly(via applying forces) and if collide with player kills him, raycast can't be solution for that
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

Re: pair caching rigid body

Post by marios »

Ok, I have done that by way around, copying contacts every physics tick to vector in my wraper on btRigidBody after that i can look only on contacts that i am interested in (for specyfied body). This works lot faster than doing contact tests.

Code: Select all

	for (int i=0;i<PhysicsObjects.size();i++)
	PhysicsObjects.at(i)->clearContactPoints();

	for (int i=0;i<	dynamicsWorld->getDispatcher()->getNumManifolds();i++)
	{
		btPersistentManifold* contactManifold =  dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);

		auto obj1 = (static_cast<SceneObject *>(static_cast<btCollisionObject*>(contactManifold->getBody0())->getUserPointer()))->getPhysics();
		auto obj2 = (static_cast<SceneObject *>(static_cast<btCollisionObject*>(contactManifold->getBody1())->getUserPointer()))->getPhysics();
	
		if(obj1->needContactPoints())obj1->addContactPoint(contactManifold);
		if(obj2->needContactPoints())obj2->addContactPoint(contactManifold);
	}
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: pair caching rigid body

Post by razer »

You can use btCollisionWorld to simulate bullet by calling testRay or convexSweepTest.