Exemplo n.º 1
0
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_speed           = (source as TargetSpeedController).m_speed;
            m_lockAtZeroSpeed = (source as TargetSpeedController).m_lockAtZeroSpeed;
        }
Exemplo n.º 2
0
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_frictionCoefficient         = (source as FrictionController).m_frictionCoefficient;
            m_nonLinearDirectSolveEnabled = (source as FrictionController).m_nonLinearDirectSolveEnabled;
        }
        /// <summary>
        /// Takes this legacy elementary constraint, creates a new instance (added to gameObject) and
        /// copies all values/objects to the new instance.
        /// </summary>
        /// <param name="gameObject">Game object to add the new version of the elementary constraint to.</param>
        /// <returns>New added elementary constraint instance.</returns>
        public ElementaryConstraint FromLegacy(GameObject gameObject)
        {
            ElementaryConstraint target = gameObject.AddComponent(GetType()) as ElementaryConstraint;

            target.Construct(this);

            return(target);
        }
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_voltage            = (source as ElectricMotorController).m_voltage;
            m_armatureResistance = (source as ElectricMotorController).m_armatureResistance;
            m_torqueConstant     = (source as ElectricMotorController).m_torqueConstant;
        }
 protected virtual void Construct(ElementaryConstraint source)
 {
     m_nativeName = source.m_nativeName;
     m_enable     = source.m_enable;
     m_rowData    = new ElementaryConstraintRowData[source.NumRows];
     for (int i = 0; i < source.NumRows; ++i)
     {
         m_rowData[i] = new ElementaryConstraintRowData(this, source.m_rowData[i]);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create instance given temporary native elementary constraint.
        /// </summary>
        /// <param name="tmpEc">Temporary elementary constraint.</param>
        /// <returns>New instance, as similar as possible, to the given native elementary constraint.</returns>
        public static ElementaryConstraint Create(GameObject gameObject, agx.ElementaryConstraint tmpEc)
        {
            if (tmpEc == null)
            {
                return(null);
            }

            ElementaryConstraint elementaryConstraint = null;

            // It's possible to know the type of controllers. We're basically not
            // interested in knowing the type of the ordinary ones.
            Type controllerType = null;

            if (agx.RangeController.safeCast(tmpEc) != null)
            {
                controllerType = agx.RangeController.safeCast(tmpEc).GetType();
            }
            else if (agx.TargetSpeedController.safeCast(tmpEc) != null)
            {
                controllerType = agx.TargetSpeedController.safeCast(tmpEc).GetType();
            }
            else if (agx.LockController.safeCast(tmpEc) != null)
            {
                controllerType = agx.LockController.safeCast(tmpEc).GetType();
            }
            else if (agx.ScrewController.safeCast(tmpEc) != null)
            {
                controllerType = agx.ScrewController.safeCast(tmpEc).GetType();
            }
            else if (agx.ElectricMotorController.safeCast(tmpEc) != null)
            {
                controllerType = agx.ElectricMotorController.safeCast(tmpEc).GetType();
            }
            else if (agx.FrictionController.safeCast(tmpEc) != null)
            {
                controllerType = agx.FrictionController.safeCast(tmpEc).GetType();
            }

            // This is a controller, instantiate the controller.
            if (controllerType != null)
            {
                elementaryConstraint = gameObject.AddComponent(Type.GetType("AGXUnity." + controllerType.Name)) as ElementaryConstraint;
            }
            // This is an ordinary elementary constraint.
            else
            {
                elementaryConstraint = gameObject.AddComponent <ElementaryConstraint>();
            }

            // Copies data from the native instance.
            elementaryConstraint.Construct(tmpEc);

            return(elementaryConstraint);
        }
 /// <summary>
 /// Construct given elementary constraint, row in the elementary constraint and (optional)
 /// a native instance to copy default values from.
 /// </summary>
 /// <param name="elementaryConstraint">Elementary constraint this row data belongs to.</param>
 /// <param name="row">Row index in the elementary constraint.</param>
 /// <param name="tmpEc">Temporary native instance to copy default values from.</param>
 public ElementaryConstraintRowData(ElementaryConstraint elementaryConstraint, int row, agx.ElementaryConstraint tmpEc = null)
 {
     m_elementaryConstraint = elementaryConstraint;
     m_row = row;
     if (tmpEc != null)
     {
         m_compliance = Convert.ToSingle(tmpEc.getCompliance(RowUInt));
         m_damping    = Convert.ToSingle(tmpEc.getDamping(RowUInt));
         m_forceRange = new RangeReal(tmpEc.getForceRange(RowUInt));
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Construct given elementary constraint, row in the elementary constraint and (optional)
 /// a native instance to copy default values from.
 /// </summary>
 /// <param name="elementaryConstraint">Elementary constraint this row data belongs to.</param>
 /// <param name="row">Row index in the elementary constraint.</param>
 /// <param name="tmpEc">Temporary native instance to copy default values from.</param>
 public ElementaryConstraintRowData(ElementaryConstraint elementaryConstraint, int row, agx.ElementaryConstraint tmpEc = null)
 {
     m_elementaryConstraint = elementaryConstraint;
     m_row = row;
     if (tmpEc != null)
     {
         m_compliance = Convert.ToSingle(tmpEc.getCompliance(RowUInt));
         // AGX Dynamics damping is optimized for 60 Hz simulations. Assuming
         // a fixed update of 50 Hz in Unity we scale the damping by 60 / 50 = 1.2
         // to transform the damping to 50 Hz.
         m_damping    = 1.2f * Convert.ToSingle(tmpEc.getDamping(RowUInt));
         m_forceRange = new RangeReal(tmpEc.getForceRange(RowUInt));
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Patches primary and secondary elementary constraints to the current version of AGX.
        /// </summary>
        /// <param name="native">If given, the native configuration may be used.</param>
        /// <returns>True if modification were applied - otherwise false.</returns>
        public bool VerifyImplementation()
        {
            if (Type == ConstraintType.Hinge)
            {
                var swing = m_elementaryConstraints.FirstOrDefault(ec => ec.NativeName == "SW");
                // Already created with swing - hinge is up to date.
                if (swing != null)
                {
                    return(false);
                }

                var ecUn = m_elementaryConstraints.FirstOrDefault(ec => ec.NativeName == "D1_UN");
                var ecVn = m_elementaryConstraints.FirstOrDefault(ec => ec.NativeName == "D1_VN");
                // Not swing nor dot1's - this is an unknown configuration.
                if (ecUn == null || ecVn == null)
                {
                    Debug.LogWarning("Trying to patch hinge but the elementary constraint configuration is undefined.", this);
                    return(false);
                }

                using (var nativeHinge = new TemporaryNative(NativeType)) {
                    swing = ElementaryConstraint.Create(gameObject, nativeHinge.Instance.getElementaryConstraintGivenName("SW"));
                }

                if (swing == null)
                {
                    Debug.LogWarning("Unable to find elementary constraint \"SW\" in native hinge implementation.", this);
                    return(false);
                }

                swing.Enable = ecUn.Enable || ecVn.Enable;
                swing.RowData[0].CopyFrom(ecUn.RowData[0]);
                swing.RowData[1].CopyFrom(ecVn.RowData[0]);

                m_elementaryConstraints.Insert(m_elementaryConstraints.IndexOf(ecUn), swing);
                m_elementaryConstraints.Remove(ecUn);
                m_elementaryConstraints.Remove(ecVn);

                DestroyImmediate(ecUn);
                DestroyImmediate(ecVn);

                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Internal method which constructs this constraint given elementary constraints
        /// in the native instance. Throws if an elementary constraint fails to initialize.
        /// </summary>
        /// <param name="native">Native instance.</param>
        /// <param name="onObjectCreated">Optional callback when elementary constraint has been created.</param>
        public void TryAddElementaryConstraints(agx.Constraint native,
                                                Action <UnityEngine.Object> onObjectCreated = null)
        {
            if (native == null)
            {
                throw new ArgumentNullException("native", "Native constraint is null.");
            }

            m_elementaryConstraints.Clear();

            for (uint i = 0; i < native.getNumElementaryConstraints(); ++i)
            {
                if (native.getElementaryConstraint(i).getName() == "")
                {
                    throw new Exception("Native elementary constraint doesn't have a name.");
                }

                var ec = ElementaryConstraint.Create(gameObject, native.getElementaryConstraint(i));
                if (ec == null)
                {
                    throw new Exception("Failed to configure elementary constraint with name: " + native.getElementaryConstraint(i).getName() + ".");
                }

                onObjectCreated?.Invoke(ec);

                m_elementaryConstraints.Add(ec);
            }

            for (uint i = 0; i < native.getNumSecondaryConstraints(); ++i)
            {
                if (native.getSecondaryConstraint(i).getName() == "")
                {
                    throw new Exception("Native secondary constraint doesn't have a name.");
                }

                var sc = ElementaryConstraint.Create(gameObject, native.getSecondaryConstraint(i));
                if (sc == null)
                {
                    throw new Exception("Failed to configure elementary controller constraint with name: " + native.getElementaryConstraint(i).getName() + ".");
                }

                onObjectCreated?.Invoke(sc);

                m_elementaryConstraints.Add(sc);
            }
        }
Exemplo n.º 11
0
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_position = (source as LockController).m_position;
        }
Exemplo n.º 12
0
 public void CopyFrom(ElementaryConstraint source)
 {
     Construct(source);
 }
Exemplo n.º 13
0
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_range = new RangeReal((source as RangeController).m_range);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Construct given elementary constraint and source instance.
 /// </summary>
 /// <param name="elementaryConstraint"></param>
 /// <param name="source"></param>
 public ElementaryConstraintRowData(ElementaryConstraint elementaryConstraint, ElementaryConstraintRowData source)
 {
     m_elementaryConstraint = elementaryConstraint;
     m_row = source.m_row;
     CopyFrom(source);
 }
Exemplo n.º 15
0
        protected override void Construct(ElementaryConstraint source)
        {
            base.Construct(source);

            m_lead = (source as ScrewController).m_lead;
        }