Example #1
0
        public void Normalize()
        {
            float inverseLength = MathHelpers.ISqrt(X * X + Y * Y + Z * Z + W * W);

            X *= inverseLength;
            Y *= inverseLength;
            Z *= inverseLength;
            W *= inverseLength;
        }
Example #2
0
        public void Normalize()
        {
            if (!IsValid())
            {
                _w = 0;
                _v = new Vector3(0f, 0f, 0f);
            }
            var inverseLength = MathHelpers.ISqrt(_v.x * _v.x + _v.y * _v.y + _v.z * _v.z + _w * _w);

            _v *= inverseLength;
            _w *= inverseLength;
        }
Example #3
0
        public void ClampLength(float maxLength)
        {
            float sqrLength = LengthSquared;

            if (sqrLength > (maxLength * maxLength))
            {
                var scale = maxLength * MathHelpers.ISqrt(sqrLength);
                X *= scale;
                Y *= scale;
                Z *= scale;
            }
        }
Example #4
0
        public void NormalizeSafe()
        {
            float d = W * W + V.X * V.X + V.Y * V.Y + V.Z * V.Z;

            if (d > 1e-8f)
            {
                d  = MathHelpers.ISqrt(d);
                W *= d; V.X *= d; V.Y *= d; V.Z *= d;
            }
            else
            {
                SetIdentity();
            }
        }
Example #5
0
        public void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection)
        {
            float dot = fromDirection.x * toDirection.x + fromDirection.y * toDirection.y + fromDirection.z * toDirection.z + 1.0f;

            if (dot > 0.0001f)
            {
                float vx = fromDirection.y * toDirection.z - fromDirection.z * toDirection.y;
                float vy = fromDirection.z * toDirection.x - fromDirection.x * toDirection.z;
                float vz = fromDirection.x * toDirection.y - fromDirection.y * toDirection.x;
                float d  = MathHelpers.ISqrt(dot * dot + vx * vx + vy * vy + vz * vz);
                _w   = dot * d;
                _v.x = vx * d;
                _v.y = vy * d;
                _v.z = vz * d;
                return;
            }
            w = 0;
            v = fromDirection.Orthogonal.Normalized;
        }
Example #6
0
        public void Normalize()
        {
            float d = MathHelpers.ISqrt(W * W + V.X * V.X + V.Y * V.Y + V.Z * V.Z);

            W *= d; V.X *= d; V.Y *= d; V.Z *= d;
        }
Example #7
0
        public void Normalize()
        {
            float fInvLen = MathHelpers.ISqrt(X * X + Y * Y + Z * Z);

            X *= fInvLen; Y *= fInvLen; Z *= fInvLen;
        }