AABBox<float> CollisionConvexHullShape::toAABBox(const PhysicsTransform &physicsTransform) const { if(!lastTransform.equals(physicsTransform)) { const Quaternion<float> &orientation = physicsTransform.getOrientation(); Point3<float> min(std::numeric_limits<float>::max(), std::numeric_limits<float>::max(), std::numeric_limits<float>::max()); Point3<float> max(-std::numeric_limits<float>::max(), -std::numeric_limits<float>::max(), -std::numeric_limits<float>::max()); const std::vector<Point3<float>> &convexHullShapePoints = convexHullShape->getPoints(); for (const auto &convexHullShapePoint : convexHullShapePoints) { const Point3<float> point = orientation.rotatePoint(convexHullShapePoint); min.X = std::min(min.X, point.X); min.Y = std::min(min.Y, point.Y); min.Z = std::min(min.Z, point.Z); max.X = std::max(max.X, point.X); max.Y = std::max(max.Y, point.Y); max.Z = std::max(max.Z, point.Z); } const Point3<float> &position = physicsTransform.getPosition(); lastAABBox = AABBox<float>(min + position, max + position); lastTransform = physicsTransform; } return lastAABBox; }
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; }