RotatedTranslatedShapeTest.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <TestFramework.h>
  4. #include <Tests/Shapes/RotatedTranslatedShapeTest.h>
  5. #include <Jolt/Physics/Collision/Shape/ConvexHullShape.h>
  6. #include <Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h>
  7. #include <Jolt/Physics/Body/BodyCreationSettings.h>
  8. #include <Layers.h>
  9. JPH_IMPLEMENT_RTTI_VIRTUAL(RotatedTranslatedShapeTest)
  10. {
  11. JPH_ADD_BASE_CLASS(RotatedTranslatedShapeTest, Test)
  12. }
  13. void RotatedTranslatedShapeTest::Initialize()
  14. {
  15. // Floor
  16. CreateFloor();
  17. // Create a cone centered on the origin with the point pointing upwards
  18. Array<Vec3> points;
  19. points.push_back(Vec3(0, 2.5f, 0));
  20. for (float a = 0; a < DegreesToRadians(360); a += DegreesToRadians(36))
  21. points.push_back(Vec3(Sin(a), -2.5f, Cos(a)));
  22. Ref<ConvexHullShapeSettings> convex_hull = new ConvexHullShapeSettings(points);
  23. // Offset and rotate so that the cone is upside down on its point
  24. Ref<RotatedTranslatedShapeSettings> rot_trans = new RotatedTranslatedShapeSettings(Vec3(0, 2.5f, 0), Quat::sRotation(Vec3::sAxisX(), JPH_PI), convex_hull);
  25. // Place at 0 so that the point touches the floor
  26. Body &body = *mBodyInterface->CreateBody(BodyCreationSettings(rot_trans, Vec3::sZero(), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING));
  27. mBodyInterface->AddBody(body.GetID(), EActivation::Activate);
  28. }