Пример #1
0
        public idRotation ToRotation()
        {
            if (pitch == 0.0f)
            {
                if (yaw == 0.0f)
                {
                    return(new idRotation(idvec3.origin, new idVec3(-1.0f, 0.0f, 0.0f), roll));
                }
                if (roll == 0.0f)
                {
                    return(new idRotation(idVec3.origin, new idVec3(0.0f, 0.0f, -1.0f), yaw));
                }
            }
            else if (yaw == 0.0f && roll == 0.0f)
            {
                return(new idRotation(idVec3.origin, new idVec3(0.0f, -1.0f, 0.0f), pitch));
            }
            float sx, cx, sy, cy, sz, cz;

            idMath.SinCos(DEG2RAD(yaw) * 0.5f, out sz, out cz);
            idMath.SinCos(DEG2RAD(pitch) * 0.5f, out sy, out cy);
            idMath.SinCos(DEG2RAD(roll) * 0.5f, out sx, out cx);
            float sxcy = sx * cy;
            float cxcy = cx * cy;
            float sxsy = sx * sy;
            float cxsy = cx * sy;
            //
            idVec3 vec = new idVec3();

            vec.x = cxsy * sz - sxcy * cz;
            vec.y = -cxsy * cz - sxcy * sz;
            vec.z = sxsy * cz - cxcy * sz;
            float w     = cxcy * cz + sxsy * sz;
            float angle = idMath.ACos(w);

            if (angle == 0.0f)
            {
                vec.Set(0.0f, 0.0f, 1.0f);
            }
            else
            {
                //vec *= (1.0f / sin( angle ));
                vec.Normalize();
                vec.FixDegenerateNormal();
                angle *= 2.0f * idMath.M_RAD2DEG;
            }
            return(new idRotation(idVec3.origin, vec, angle));
        }
Пример #2
0
        public idRotation ToRotation()
        {
            idVec3 vec = new idVec3();

            vec.x = x;
            vec.y = y;
            vec.z = z;
            float angle = idMath.ACos(w);

            if (angle == 0.0f)
            {
                vec.Set(0.0f, 0.0f, 1.0f);
            }
            else
            {
                //vec *= (1.0f / sin( angle ));
                vec.Normalize();
                vec.FixDegenerateNormal();
                angle *= 2.0f * idMath.M_RAD2DEG;
            }
            return(new idRotation(idVec3.origin, vec, angle));
        }
Пример #3
0
 public idRotation ToRotation()
 {
     idVec3 vec = new idVec3();
     vec.x = x;
     vec.y = y;
     vec.z = z;
     float angle = idMath.ACos(w);
     if (angle == 0.0f)
     {
         vec.Set(0.0f, 0.0f, 1.0f);
     }
     else
     {
         //vec *= (1.0f / sin( angle ));
         vec.Normalize();
         vec.FixDegenerateNormal();
         angle *= 2.0f * idMath.M_RAD2DEG;
     }
     return new idRotation(idVec3.origin, vec, angle);
 }
Пример #4
0
 public idRotation ToRotation()
 {
     if (pitch == 0.0f)
     {
         if (yaw == 0.0f) return new idRotation(idvec3.origin, new idVec3(-1.0f, 0.0f, 0.0f), roll);
         if (roll == 0.0f) return new idRotation(idVec3.origin, new idVec3(0.0f, 0.0f, -1.0f), yaw);
     }
     else if (yaw == 0.0f && roll == 0.0f) return new idRotation(idVec3.origin, new idVec3(0.0f, -1.0f, 0.0f), pitch);
     float sx, cx, sy, cy, sz, cz;
     idMath.SinCos(DEG2RAD(yaw) * 0.5f, out sz, out cz);
     idMath.SinCos(DEG2RAD(pitch) * 0.5f, out sy, out cy);
     idMath.SinCos(DEG2RAD(roll) * 0.5f, out sx, out cx);
     float sxcy = sx * cy;
     float cxcy = cx * cy;
     float sxsy = sx * sy;
     float cxsy = cx * sy;
     //
     idVec3 vec = new idVec3();
     vec.x = cxsy * sz - sxcy * cz;
     vec.y = -cxsy * cz - sxcy * sz;
     vec.z = sxsy * cz - cxcy * sz;
     float w = cxcy * cz + sxsy * sz;
     float angle = idMath.ACos(w);
     if (angle == 0.0f)
         vec.Set(0.0f, 0.0f, 1.0f);
     else
     {
         //vec *= (1.0f / sin( angle ));
         vec.Normalize();
         vec.FixDegenerateNormal();
         angle *= 2.0f * idMath.M_RAD2DEG;
     }
     return new idRotation(idVec3.origin, vec, angle);
 }