vphysics_bullet/Physics_FluidController.cpp
static btVector3 calculateBuoyantCenter(btRigidBody *pBody, btVector3 &planePos, btVector3 &planeNorm) {
	btVector3 center(0, 0, 0);

	btVector3 relPlanePos = pBody->getWorldTransform().inverse() * planePos;
	btVector3 relNorm = quatRotate(pBody->getWorldTransform().getRotation().inverse(), planeNorm);

	btCollisionShape *pShape = pBody->getCollisionShape();
	if (pShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
		btCompoundShape *pCompound = (btCompoundShape *)pShape;
		for (int i = 0; i < pCompound->getNumChildShapes(); i++) {
			btCollisionShape *pChild = pCompound->getChildShape(i);
			if (pChild->getShapeType() == CONVEX_HULL_SHAPE_PROXYTYPE) {
				center += calcConvexCenter((btConvexHullShape *)pChild, relPlanePos, relNorm);
			}
		}

		if (pCompound->getNumChildShapes() > 0)
			center /= static_cast<btScalar>(pCompound->getNumChildShapes());
	}

	return center;
}
// Find the object's center of buoyancy
// This would be the center of all submerged points
// You can bisect the object by the plane of the water surface to get all points
// submerged, then calculate the center of all those points
// planePos: World space plane position
// planeNorm: World space plane normal
Find the object's center of buoyancy
This would be the center of all submerged points
You can bisect the object by the plane of the water surface to get all points
submerged, then calculate the center of all those points
planePos: World space plane position
planeNorm: World space plane normal
Find the object ' s center of buoyancy This would be the center of all submerged points You can bisect the object by the plane of the water surface to get all points submerged then calculate the center of all those points planePos : World space plane position planeNorm : World space plane normal
static btVector3 calculateBuoyantCenter(btRigidBody *pBody, btVector3 &planePos, btVector3 &planeNorm) {
	btVector3 center(0, 0, 0);
	btVector3 relPlanePos = pBody->getWorldTransform().inverse() * planePos;
	btVector3 relNorm = quatRotate(pBody->getWorldTransform().getRotation().inverse(), planeNorm);
	btCollisionShape *pShape = pBody->getCollisionShape();
	if (pShape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
		btCompoundShape *pCompound = (btCompoundShape *)pShape;
		for (int i = 0; i < pCompound->getNumChildShapes(); i++) {
			btCollisionShape *pChild = pCompound->getChildShape(i);
			if (pChild->getShapeType() == CONVEX_HULL_SHAPE_PROXYTYPE) {
				center += calcConvexCenter((btConvexHullShape *)pChild, relPlanePos, relNorm);
			}
		}
		if (pCompound->getNumChildShapes() > 0)
			center /= static_cast<btScalar>(pCompound->getNumChildShapes());
	}
	return center;
}
static btVector3 calculateBuoyantCenter ( btRigidBody * pBody , btVector3 & planePos , btVector3 & planeNorm ) { btVector3 center ( 0 , 0 , 0 ) ; btVector3 relPlanePos = pBody -> getWorldTransform ( ) . inverse ( ) * planePos ; btVector3 relNorm = quatRotate ( pBody -> getWorldTransform ( ) . getRotation ( ) . inverse ( ) , planeNorm ) ; btCollisionShape * pShape = pBody -> getCollisionShape ( ) ; if ( pShape -> getShapeType ( ) == COMPOUND_SHAPE_PROXYTYPE ) { btCompoundShape * pCompound = ( btCompoundShape * ) pShape ; for ( int i = 0 ; i < pCompound -> getNumChildShapes ( ) ; i ++ ) { btCollisionShape * pChild = pCompound -> getChildShape ( i ) ; if ( pChild -> getShapeType ( ) == CONVEX_HULL_SHAPE_PROXYTYPE ) { center += calcConvexCenter ( ( btConvexHullShape * ) pChild , relPlanePos , relNorm ) ; } } if ( pCompound -> getNumChildShapes ( ) > 0 ) center /= static_cast < btScalar > ( pCompound -> getNumChildShapes ( ) ) ; } return center ; }
Find the object's center of buoyancy
This would be the center of all submerged points
You can bisect the object by the plane of the water surface to get all points
submerged, then calculate the center of all those points
planePos: World space plane position
planeNorm: World space plane normal
Find the object ' s center of buoyancy This would be the center of all submerged points You can bisect the object by the plane of the water surface to get all points submerged then calculate the center of all those points planePos : World space plane position planeNorm : World space plane normal