Example #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));
        }
Example #2
0
        public void ToVectors(ref idVec3 forward, ref idVec3 right, ref idVec3 up)
        {
            float sr, sp, sy, cr, cp, cy;

            idMath.SinCos(DEG2RAD(yaw), out sy, out cy);
            idMath.SinCos(DEG2RAD(pitch), out sp, out cp);
            idMath.SinCos(DEG2RAD(roll), out sr, out cr);
            if (forward != null)
            {
                forward.Set(cp * cy, cp * sy, -sp);
            }
            if (right != null)
            {
                right.Set(-sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp);
            }
            if (up != null)
            {
                up.Set(cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp);
            }
        }
Example #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));
        }
 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);
 }
 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);
 }
 public void ToVectors(ref idVec3 forward, ref idVec3 right, ref idVec3 up)
 {
     float sr, sp, sy, cr, cp, cy;
     idMath.SinCos(DEG2RAD(yaw), out sy, out cy);
     idMath.SinCos(DEG2RAD(pitch), out sp, out cp);
     idMath.SinCos(DEG2RAD(roll), out sr, out cr);
     if (forward != null) forward.Set(cp * cy, cp * sy, -sp);
     if (right != null) right.Set(-sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp);
     if (up != null) up.Set(cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp);
 }
 static void UnpackColor(uint color, ref idVec3 unpackedColor)
 {
     unpackedColor.Set(((color >> 0) & 255) * (1.0f / 255.0f),
         ((color >> 8) & 255) * (1.0f / 255.0f),
         ((color >> 16) & 255) * (1.0f / 255.0f));
 }