Пример #1
0
        public void Normalize()
        {
            double norm = Norm();

            Debug.Assert(!MU.floatEqualityTest(0.0f, (float)norm));             // norm should never be close to 0

            x = (float)(x / norm);
            y = (float)(y / norm);
            z = (float)(z / norm);
            w = (float)(w / norm);

            Debug.Assert(MU.floatEqualityTest(1.0f, (float)Norm()));    // must be normalized, safe

            MU.limitRange(-1.0f, ref w, 1.0f);

            MU.limitRange(-1.0f, ref x, 1.0f);
            MU.limitRange(-1.0f, ref y, 1.0f);
            MU.limitRange(-1.0f, ref z, 1.0f);
        }
Пример #2
0
        public void Normalize()
        {
            double len = Length();

            if (MU.floatEqualityTest(0.0f, (float)len))                         // if length is zero

            {
                x = 0.0f;
                y = 0.0f;
                z = 0.0f;
            }
            else                // normalize

            {
                x = (float)(x / len);
                y = (float)(y / len);
                z = (float)(z / len);

                zeroClamp();
            }
        }
Пример #3
0
        public void GetAxisAngle(ref Vector v, ref float angle)
        {
            double tempAngle;           // temp angle
            double scale;               // temp vars

            tempAngle = Math.Acos(w);

            //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            // Another version where scale is sqrt (x2 + y2 + z2)
            //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            scale = (float)Math.Sqrt(x * x + y * y + z * z);
            //	scale = (float)sin(temp_angle);

            Debug.Assert(0 <= tempAngle);                               // make sure angle is 0 - PI
            Debug.Assert(Math.PI >= tempAngle);

            if (MU.floatEqualityTest(0.0f, (float)scale))
            {   // angle is 0 or 360 so just simply set axis to 0,0,1 with angle 0
                angle = 0.0f;

                v.x = 0.0f;
                v.y = 0.0f;
                v.z = 1.0f;             // any axis will do
            }
            else
            {
                angle = (float)(tempAngle * 2.0);               // angle in radians

                v.x = (float)(x / scale);
                v.y = (float)(y / scale);
                v.z = (float)(z / scale);

                v.Normalize();

                Debug.Assert(0.0f <= angle);                    // make sure rotation around axis is 0 - 360
                Debug.Assert(2 * Math.PI >= angle);
                Debug.Assert(v.IsUnit());                       // make sure a unit axis comes up
            }
        }
Пример #4
0
 public bool IsUnit()
 {
     return(MU.floatEqualityTest(1.0f, (float)Length()));
 }
Пример #5
0
 public bool IsZero()
 {
     return(MU.floatEqualityTest(0.0f, (float)Length()));
 }