void	btContinuousDynamicsWorld::updateTemporalAabbs(btScalar timeStep)
{

	btVector3 temporalAabbMin,temporalAabbMax;

	for ( int i=0;i<m_collisionObjects.size();i++)
	{
		btCollisionObject* colObj = m_collisionObjects[i];
		
		btRigidBody* body = btRigidBody::upcast(colObj);
		if (body)
		{
			body->getCollisionShape()->getAabb(m_collisionObjects[i]->getWorldTransform(),temporalAabbMin,temporalAabbMax);
			const btVector3& linvel = body->getLinearVelocity();

			//make the AABB temporal
			btScalar temporalAabbMaxx = temporalAabbMax.getX();
			btScalar temporalAabbMaxy = temporalAabbMax.getY();
			btScalar temporalAabbMaxz = temporalAabbMax.getZ();
			btScalar temporalAabbMinx = temporalAabbMin.getX();
			btScalar temporalAabbMiny = temporalAabbMin.getY();
			btScalar temporalAabbMinz = temporalAabbMin.getZ();

			// add linear motion
			btVector3 linMotion = linvel*timeStep;
		
			if (linMotion.x() > 0.f)
				temporalAabbMaxx += linMotion.x(); 
			else
				temporalAabbMinx += linMotion.x();
			if (linMotion.y() > 0.f)
				temporalAabbMaxy += linMotion.y(); 
			else
				temporalAabbMiny += linMotion.y();
			if (linMotion.z() > 0.f)
				temporalAabbMaxz += linMotion.z(); 
			else
				temporalAabbMinz += linMotion.z();

			//add conservative angular motion
			btScalar angularMotion(0);// = angvel.length() * GetAngularMotionDisc() * timeStep;
			btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
			temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
			temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);

			temporalAabbMin -= angularMotion3d;
			temporalAabbMax += angularMotion3d;

			m_broadphasePairCache->setAabb(body->getBroadphaseHandle(),temporalAabbMin,temporalAabbMax,m_dispatcher1);
		}
	}

	//update aabb (of all moved objects)

	m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
	


}
void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
{
	//start with static aabb
	getAabb(curTrans,temporalAabbMin,temporalAabbMax);

	btScalar temporalAabbMaxx = temporalAabbMax.getX();
	btScalar temporalAabbMaxy = temporalAabbMax.getY();
	btScalar temporalAabbMaxz = temporalAabbMax.getZ();
	btScalar temporalAabbMinx = temporalAabbMin.getX();
	btScalar temporalAabbMiny = temporalAabbMin.getY();
	btScalar temporalAabbMinz = temporalAabbMin.getZ();

	// add linear motion
	btVector3 linMotion = linvel*timeStep;
	///@todo: simd would have a vector max/min operation, instead of per-element access
	if (linMotion.x() > btScalar(0.))
		temporalAabbMaxx += linMotion.x(); 
	else
		temporalAabbMinx += linMotion.x();
	if (linMotion.y() > btScalar(0.))
		temporalAabbMaxy += linMotion.y(); 
	else
		temporalAabbMiny += linMotion.y();
	if (linMotion.z() > btScalar(0.))
		temporalAabbMaxz += linMotion.z(); 
	else
		temporalAabbMinz += linMotion.z();

	//add conservative angular motion
	btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
	btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
	temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
	temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);

	temporalAabbMin -= angularMotion3d;
	temporalAabbMax += angularMotion3d;
}