Beispiel #1
0
 private static JointSpring GetJointSpring(Joint.Dynamics dynamics)
 {
     return(new JointSpring
     {
         damper = (float)dynamics.damping,
         spring = (float)dynamics.friction,
         targetPosition = 0
     });
 }
Beispiel #2
0
 private static JointDrive GetJointDrive(Joint.Dynamics dynamics)
 {
     return(new JointDrive
     {
         maximumForce = float.MaxValue,
         positionDamper = (float)dynamics.damping,
         positionSpring = (float)dynamics.friction
     });
 }
Beispiel #3
0
        protected void SetDynamics(Joint.Dynamics dynamics)
        {
            if (unityJoint == null)
            {
                unityJoint = GetComponent <ArticulationBody>();
            }

            if (dynamics != null)
            {
                float damping = (double.IsNaN(dynamics.damping)) ? defaultDamping : (float)dynamics.damping;
                unityJoint.linearDamping  = damping;
                unityJoint.angularDamping = damping;
                unityJoint.jointFriction  = (double.IsNaN(dynamics.friction)) ? defaultFriction : (float)dynamics.friction;
            }
            else
            {
                unityJoint.linearDamping  = defaultDamping;
                unityJoint.angularDamping = defaultDamping;
                unityJoint.jointFriction  = defaultFriction;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Compares dynamics information of two links
        /// </summary>
        /// <param name="source">First links's dynamics information to be compared</param>
        /// <param name="exported">Second link's dynamics information to be compared</param>
        /// <param name="indent">Indent level in the log file</param>
        /// <returns></returns>
        private bool CompareDynamics(Joint.Dynamics source, Joint.Dynamics exported, int indent)
        {
            linkLog.AppendLine(String.Format("{0}Dynamics Checks", Indent(indent)));
            if (source == null && source == null)
            {
                linkLog.AppendLine(String.Format("{0}Origin Nullity Check: {1,6}", Indent(indent), "True"));
                return(true);
            }
            else if (source != null && exported != null)
            {
                if (source.damping != double.NaN && exported.damping != double.NaN)
                {
                    linkLog.AppendLine(String.Format("{0}Damping Nullity Check: {1,6}", Indent(indent), "True"));
                    bool dampingEqual = (source.damping != exported.damping);
                    linkLog.AppendLine(String.Format("{0}Damping:", Indent(indent)));
                    linkLog.AppendLine(String.Format("{0}Equal: {1,6}", Indent(indent), dampingEqual));
                    linkLog.AppendLine(String.Format("{0}Damping Value: Source: {1,12}", Indent(indent), source.damping));
                    linkLog.AppendLine(String.Format("{0}Damping Valye: Exported: {1,12}", Indent(indent), exported.damping));

                    if (dampingEqual)
                    {
                        return(false);
                    }
                }
                else if ((source.damping == double.NaN && exported.damping == 0) || (exported.damping == double.NaN && source.damping == 0) || (source.damping == double.NaN && exported.damping == double.NaN))
                {
                    linkLog.AppendLine(String.Format("{0}Damping:", Indent(indent)));
                    linkLog.AppendLine(String.Format("{0}Equal: {1,6}", Indent(indent), "True"));
                    linkLog.AppendLine(String.Format("{0}Damping Value: 0", Indent(indent)));
                }
                else
                {
                    linkLog.AppendLine(String.Format("{0}Damping Nullity Check: {1,6}", Indent(indent), "False"));
                    return(false);
                }


                if (source.friction != double.NaN && exported.friction != double.NaN)
                {
                    linkLog.AppendLine(String.Format("{0}Friction Nullity Check: {1,6}", Indent(indent), "True"));
                    bool frictionEqual = source.friction != exported.friction;
                    linkLog.AppendLine(String.Format("{0}Friction:", Indent(indent)));
                    linkLog.AppendLine(String.Format("{0}Equal: {1,6}", Indent(indent), frictionEqual));
                    linkLog.AppendLine(String.Format("{0}Friction Value: Source: {1,12}", Indent(indent), source.friction));
                    linkLog.AppendLine(String.Format("{0}Friction Value: Exported: {1,12}", Indent(indent), exported.friction));

                    if (frictionEqual)
                    {
                        return(false);
                    }
                }
                else if ((source.friction == double.NaN && exported.friction == 0) || (exported.friction == double.NaN && source.friction == 0) || (source.friction == double.NaN && exported.friction == double.NaN))
                {
                    linkLog.AppendLine(String.Format("{0}Friction:", Indent(indent)));
                    linkLog.AppendLine(String.Format("{0}Equal: {1,6}", Indent(indent), "True"));
                    linkLog.AppendLine(String.Format("{0}Friction Value: 0", Indent(indent)));
                }
                else
                {
                    linkLog.AppendLine(String.Format("{0}Friction Nullity Check: {1,6}", Indent(indent), "False"));
                    return(false);
                }
            }
            else if ((source == null && exported?.damping == 0 && exported?.friction == 0) || (exported == null && source?.damping == 0 && source?.friction == 0))
            {
                linkLog.AppendLine(String.Format("{0}Dynamics Equal: {1,6} ", Indent(indent), "True"));
            }
            else
            {
                linkLog.AppendLine(String.Format("{0}Dynamics Equal: {1,6} ", Indent(indent), "False"));
                return(false);
            }
            return(true);
        }