Triangle.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. JPH_NAMESPACE_BEGIN
  6. /// A simple triangle and its material
  7. class Triangle
  8. {
  9. public:
  10. JPH_OVERRIDE_NEW_DELETE
  11. /// Constructor
  12. Triangle() = default;
  13. Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3) : mV { inV1, inV2, inV3 } { }
  14. Triangle(const Float3 &inV1, const Float3 &inV2, const Float3 &inV3, uint32 inMaterialIndex) : Triangle(inV1, inV2, inV3) { mMaterialIndex = inMaterialIndex; }
  15. Triangle(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3) { inV1.StoreFloat3(&mV[0]); inV2.StoreFloat3(&mV[1]); inV3.StoreFloat3(&mV[2]); }
  16. /// Get center of triangle
  17. Vec3 GetCentroid() const
  18. {
  19. return (Vec3::sLoadFloat3Unsafe(mV[0]) + Vec3::sLoadFloat3Unsafe(mV[1]) + Vec3::sLoadFloat3Unsafe(mV[2])) * (1.0f / 3.0f);
  20. }
  21. /// Vertices
  22. Float3 mV[3];
  23. uint32 mMaterialIndex = 0; ///< Follows mV[3] so that we can read mV as 4 vectors
  24. };
  25. using TriangleList = Array<Triangle>;
  26. JPH_NAMESPACE_END