RotatedTranslatedShapeTest.cpp 1.4 KB

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