66#define _NBL_BUILTIN_HLSL_SHAPES_TRIANGLE_INCLUDED_
77
88#include <nbl/builtin/hlsl/cpp_compat.hlsl>
9+ #include <nbl/builtin/hlsl/tgmath.hlsl>
10+ #include <nbl/builtin/hlsl/numbers.hlsl>
911
1012namespace nbl
1113{
@@ -17,22 +19,22 @@ namespace shapes
1719namespace util
1820{
1921 template <typename float_t>
20- vector <float_t, 3 > GetAngleWeight ( const vector <float_t, 3 >& e1, const vector <float_t, 3 >& e2, const vector <float_t, 3 >& e3)
22+ vector <float_t, 3 > compInternalAngle ( NBL_CONST_REF_ARG ( vector <float_t, 3 >) e1, NBL_CONST_REF_ARG ( vector <float_t, 3 >) e2, NBL_CONST_REF_ARG ( vector <float_t, 3 >) e3)
2123 {
2224 // Calculate this triangle's weight for each of its three m_vertices
2325 // start by calculating the lengths of its sides
24- const float_t a = dot (e1, e1);
25- const float_t asqrt = sqrt (a);
26- const float_t b = dot (e2, e2);
27- const float_t bsqrt = sqrt (b);
28- const float_t c = dot (e3, e3);
29- const float_t csqrt = sqrt (c);
26+ const float_t a = hlsl:: dot (e1, e1);
27+ const float_t asqrt = hlsl:: sqrt (a);
28+ const float_t b = hlsl:: dot (e2, e2);
29+ const float_t bsqrt = hlsl:: sqrt (b);
30+ const float_t c = hlsl:: dot (e3, e3);
31+ const float_t csqrt = hlsl:: sqrt (c);
3032
33+ const float_t angle1 = hlsl::acos ((b + c - a) / (2.f * bsqrt * csqrt));
34+ const float_t angle2 = hlsl::acos ((-b + c + a) / (2.f * asqrt * csqrt));
35+ const float_t angle3 = hlsl::numbers::pi<float_t> - (angle1 + angle2);
3136 // use them to find the angle at each vertex
32- return vector <float_t, 3 >(
33- acosf ((b + c - a) / (2.f * bsqrt * csqrt)),
34- acosf ((-b + c + a) / (2.f * asqrt * csqrt)),
35- acosf ((b - c + a) / (2.f * bsqrt * asqrt)));
37+ return vector <float_t, 3 >(angle1, angle2, angle3);
3638 }
3739}
3840
0 commit comments