Esempio n. 1
0
    protected void inititializeTire(string name)
    {
        var sim = GetSimulation();

        Assert.IsNotNull(sim);

        var searchName = name + "Tire";
        var tire       = sim.getRigidBody(searchName);

        Assert.IsNotNull(tire, "Unable to find RigidBody: " + searchName);

        searchName = name + "Rim";
        var rim = sim.getRigidBody(searchName);

        Assert.IsNotNull(rim, "Unable to find RigidBody: " + searchName);

        // For each tire/rim there is a LockJoint that we added in Momentum just to keep the two together.
        // We need to disable that constraint
        searchName = "Lock" + name;
        var lockJoint = sim.getLockJoint(searchName);

        Assert.IsNotNull(lockJoint, "Unable to find LockJoint: " + searchName);
        lockJoint.setEnable(false);

        // Make sure orientation of the wheel is correct
        var m = new agx.AffineMatrix4x4(new agx.Quat(new agx.Vec3(0, 0, 1),
                                                     new agx.Vec3(0, 1, 0)),
                                        new agx.Vec3());

        // Create a tire model that connects the Tire with the Rim
        var tireModel = new agxModel.TwoBodyTire(tire, 1.0, rim, 0.5, m);

        m_tireModels.Add(tireModel);
        sim.add(tireModel);
    }
Esempio n. 2
0
        protected void inititializeTire()
        {
            if (!agx.Runtime.instance().isValid() || !agx.Runtime.instance().isModuleEnabled("AgX-Tires"))
            {
                Debug.LogError("This Component requires a valid license for the AGX Dynamics module: AgX-Tires");
            }


            clearTireModel();

            if (m_rimBody == null || m_tireBody == null || m_tireBody.GetInitialized <RigidBody>() == null || m_rimBody.GetInitialized <RigidBody>() == null)
            {
                return;
            }

            var tire = m_tireBody.GetInitialized <RigidBody>().Native;
            var rim  = m_rimBody.GetInitialized <RigidBody>().Native;

            if (tire == null || rim == null)
            {
                Debug.LogWarning("Two Tire Model requires two bodies, one for the tire and one for the rim");
                return;
            }
            // Make sure orientation of the wheel is correct
            var m = new agx.AffineMatrix4x4(new agx.Quat(new agx.Vec3(0, 0, 1), new agx.Vec3(0, 1, 0)), new agx.Vec3());

            // Create a tire model that connects the Tire with the Rim
            m_tireModel = new agxModel.TwoBodyTire(tire, 1.0, rim, 0.5, m);

            GetSimulation().add(m_tireModel);
        }
Esempio n. 3
0
 /// <summary>
 /// "Back" synchronize of transforms given the simulation has
 /// updated the transforms.
 /// </summary>
 protected virtual void SyncUnityTransform()
 {
     if (transform.parent == null && m_geometry != null)
     {
         agx.AffineMatrix4x4 t = m_geometry.getTransform();
         transform.position = t.getTranslate().ToHandedVector3();
         transform.rotation = t.getRotate().ToHandedQuaternion();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// The relative transform used between a rigid body and this shape.
        /// </summary>
        /// <returns>Relative transform between rigid body (parent) and this shape, in native format.</returns>
        public agx.AffineMatrix4x4 GetNativeRigidBodyOffset(RigidBody rb)
        {
            // If we're on the same level as the rigid body we have by
            // definition no offset to the body.
            if (rb == null || rb.gameObject == gameObject)
            {
                return(agx.AffineMatrix4x4.identity());
            }

            // Using the world position of the shape - which includes scaling etc.
            agx.AffineMatrix4x4 shapeInWorld = new agx.AffineMatrix4x4(transform.rotation.ToHandedQuat(), transform.position.ToHandedVec3());
            agx.AffineMatrix4x4 rbInWorld    = new agx.AffineMatrix4x4(rb.transform.rotation.ToHandedQuat(), rb.transform.position.ToHandedVec3());
            return(shapeInWorld * rbInWorld.inverse());
        }