Triangle.h 984 B

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