|
|
@@ -341,6 +341,7 @@ namespace bx
|
|
|
_result[2] = 1.0f / _a[2];
|
|
|
}
|
|
|
|
|
|
+ /// Calculate tangent frame from normal.
|
|
|
inline void vec3TangentFrame(const float* __restrict _n, float* __restrict _t, float* __restrict _b)
|
|
|
{
|
|
|
const float nx = _n[0];
|
|
|
@@ -365,6 +366,24 @@ namespace bx
|
|
|
bx::vec3Cross(_b, _n, _t);
|
|
|
}
|
|
|
|
|
|
+ /// Calculate tangent frame from normal and angle.
|
|
|
+ inline void vec3TangentFrame(const float* __restrict _n, float _angle, float* __restrict _t, float* __restrict _b)
|
|
|
+ {
|
|
|
+ const float nx = _n[0];
|
|
|
+ const float ny = _n[1];
|
|
|
+ const float nz = _n[2];
|
|
|
+
|
|
|
+ const float sa = fsin(_angle);
|
|
|
+ const float ca = fcos(_angle);
|
|
|
+ const float omca = 1.0f - ca;
|
|
|
+
|
|
|
+ _t[0] = omca * nx * nx + ca;
|
|
|
+ _t[1] = omca * nx * ny - nz * sa;
|
|
|
+ _t[2] = omca * nx * nz + ny * sa;
|
|
|
+
|
|
|
+ bx::vec3Cross(_b, _n, _t);
|
|
|
+ }
|
|
|
+
|
|
|
inline void quatIdentity(float* _result)
|
|
|
{
|
|
|
_result[0] = 0.0f;
|
|
|
@@ -574,6 +593,25 @@ namespace bx
|
|
|
_result[15] = 1.0f;
|
|
|
}
|
|
|
|
|
|
+ inline void mtxFromNormal(float* __restrict _result, const float* __restrict _normal, float _angle, float _scale, const float* __restrict _pos)
|
|
|
+ {
|
|
|
+ float tangent[3];
|
|
|
+ float bitangent[3];
|
|
|
+ vec3TangentFrame(_normal, _angle, tangent, bitangent);
|
|
|
+
|
|
|
+ vec3Mul(&_result[ 0], bitangent, _scale);
|
|
|
+ vec3Mul(&_result[ 4], _normal, _scale);
|
|
|
+ vec3Mul(&_result[ 8], tangent, _scale);
|
|
|
+
|
|
|
+ _result[ 3] = 0.0f;
|
|
|
+ _result[ 7] = 0.0f;
|
|
|
+ _result[11] = 0.0f;
|
|
|
+ _result[12] = _pos[0];
|
|
|
+ _result[13] = _pos[1];
|
|
|
+ _result[14] = _pos[2];
|
|
|
+ _result[15] = 1.0f;
|
|
|
+ }
|
|
|
+
|
|
|
inline void mtxQuat(float* __restrict _result, const float* __restrict _quat)
|
|
|
{
|
|
|
const float x = _quat[0];
|