| 12 | #include "Engine/Core/Random.h" |
| 13 | |
| 14 | struct GeometryTriangle |
| 15 | { |
| 16 | Vector3 Vertex; |
| 17 | Vector3 Vector1; |
| 18 | Vector3 Vector2; |
| 19 | Vector3 Normal; |
| 20 | Real Area; |
| 21 | |
| 22 | GeometryTriangle(const bool isDeterminantPositive, const Vector3& v0, const Vector3& v1, const Vector3& v2) |
| 23 | { |
| 24 | Vertex = v0; |
| 25 | Vector1 = v1 - Vertex; |
| 26 | Vector2 = v2 - Vertex; |
| 27 | |
| 28 | Normal = isDeterminantPositive ? Vector1 ^ Vector2 : Vector2 ^ Vector1; |
| 29 | const Real normalLength = Normal.Length(); |
| 30 | Area = normalLength * 0.5f; |
| 31 | if (normalLength > ZeroTolerance) |
| 32 | { |
| 33 | Normal /= normalLength; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void GetRandomPoint(Vector3& result) const |
| 38 | { |
| 39 | float x = Random::Rand(); |
| 40 | float y = Random::Rand(); |
| 41 | if (x + y > 1.0f) |
| 42 | { |
| 43 | x = 1.0f - x; |
| 44 | y = 1.0f - y; |
| 45 | } |
| 46 | result = Vertex + x * Vector1 + y * Vector2; |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | template<> |
| 51 | struct TIsPODType<GeometryTriangle> |