BoundingBox CollisionShape::GetWorldBoundingBox() const { if (shape_ && node_) { // Use the rigid body's world transform if possible, as it may be different from the rendering transform RigidBody* body = GetComponent<RigidBody>(); Matrix3x4 worldTransform = body ? Matrix3x4(body->GetPosition(), body->GetRotation(), node_->GetWorldScale()) : node_->GetWorldTransform(); Vector3 worldPosition(worldTransform * position_); Quaternion worldRotation(worldTransform.Rotation() * rotation_); btTransform shapeWorldTransform(ToBtQuaternion(worldRotation), ToBtVector3(worldPosition)); btVector3 aabbMin, aabbMax; shape_->getAabb(shapeWorldTransform, aabbMin, aabbMax); return BoundingBox(ToVector3(aabbMin), ToVector3(aabbMax)); } else return BoundingBox(); }
AABBox<float> CollisionCompoundShape::toAABBox(const PhysicsTransform &physicsTransform) const { Point3<float> rotatedTranslation = physicsTransform.getOrientation().rotatePoint(Point3<float>(localizedShapes[0]->translation)); Point3<float> finalPosition = physicsTransform.getPosition().translate(rotatedTranslation.toVector()); PhysicsTransform shapeWorldTransform(finalPosition, physicsTransform.getOrientation()); AABBox<float> globalCompoundBox = localizedShapes[0]->shape->toAABBox(shapeWorldTransform); for(unsigned int i=1; i<localizedShapes.size(); ++i) { rotatedTranslation = physicsTransform.getOrientation().rotatePoint(Point3<float>(localizedShapes[i]->translation)); finalPosition = physicsTransform.getPosition().translate(rotatedTranslation.toVector()); shapeWorldTransform.setPosition(finalPosition); AABBox<float> compoundBox = localizedShapes[i]->shape->toAABBox(shapeWorldTransform); globalCompoundBox = globalCompoundBox.merge(compoundBox); } return globalCompoundBox; }