Example #1
0
 private static agx.SPDMatrix3x3 GetInertiaTensor(DefaultAndUserValueVector3 diagonal,
                                                  DefaultAndUserValueVector3 offDiagonal)
 {
     if (diagonal == null || offDiagonal == null)
     {
         throw new ArgumentNullException();
     }
     if (diagonal.UseDefault)
     {
         throw new Exception("Don't use GetInertiatensor with non-user defined diagonal.");
     }
     return(GetInertiaTensor(diagonal.UserValue, offDiagonal));
 }
Example #2
0
        private static agx.SPDMatrix3x3 GetInertiaTensor(Vector3 diagonal,
                                                         DefaultAndUserValueVector3 offDiagonal)
        {
            var inertia = new agx.SPDMatrix3x3(diagonal.ToVec3());

            // Off-diagonal elements are by default 0 when the user
            // has specified the diagonal.
            if (!offDiagonal.UseDefault)
            {
                inertia.set(offDiagonal.UserValue[0], 0, 1);
                inertia.set(offDiagonal.UserValue[1], 0, 2);
                inertia.set(offDiagonal.UserValue[2], 1, 2);
            }
            return(inertia);
        }
Example #3
0
        public bool IsValid(object value)
        {
            Type type = value.GetType();

            if (type == typeof(Vector4))
            {
                return(IsValid((Vector4)value));
            }
            else if (type == typeof(Vector3))
            {
                return(IsValid((Vector3)value));
            }
            else if (type == typeof(Vector2))
            {
                return(IsValid((Vector2)value));
            }
            else if (type == typeof(DefaultAndUserValueFloat))
            {
                DefaultAndUserValueFloat val = (DefaultAndUserValueFloat)value;
                return(val.Value > 0 || (m_acceptZero && val.Value == 0));
            }
            else if (type == typeof(DefaultAndUserValueVector3))
            {
                DefaultAndUserValueVector3 val = (DefaultAndUserValueVector3)value;
                return(IsValid((Vector3)val.Value));
            }
            else if (type == typeof(int))
            {
                return((int)value > 0 || (m_acceptZero && (int)value == 0));
            }
            else if (value is IComparable)
            {
                int returnCheck = m_acceptZero ? -1 : 0;
                // CompareTo returns 0 if the values are equal.
                return((value as IComparable).CompareTo(0.0f) > returnCheck);
            }
            else if (type == typeof(float))
            {
                return((float)value > 0 || (m_acceptZero && (float)value == 0));
            }
            else if (type == typeof(double))
            {
                return((double)value > 0 || (m_acceptZero && (double)value == 0));
            }
            return(true);
        }