Ejemplo n.º 1
0
    private void GrabInit(PhysicsBody body, Vector3 startPos, Vector3 grabPos, Rotation rot)
    {
        if (!body.IsValid())
        {
            return;
        }

        GrabEnd();

        grabbing     = true;
        heldBody     = body;
        holdDistance = Vector3.DistanceBetween(startPos, grabPos);
        holdDistance = holdDistance.Clamp(MinTargetDistance, MaxTargetDistance);

        heldRot = rot.Inverse * heldBody.Rotation;

        holdBody.Position = grabPos;
        holdBody.Rotation = heldBody.Rotation;

        velBody.Position = grabPos;
        velBody.Rotation = heldBody.Rotation;

        heldBody.Sleeping  = false;
        heldBody.AutoSleep = false;

        holdJoint = PhysicsJoint.CreateFixed(holdBody, heldBody.WorldPoint(grabPos));
        holdJoint.SpringLinear  = new PhysicsSpring(LinearFrequency, LinearDampingRatio);
        holdJoint.SpringAngular = new PhysicsSpring(AngularFrequency, AngularDampingRatio);

        velJoint = PhysicsJoint.CreateFixed(holdBody, velBody);
        velJoint.SpringLinear  = new PhysicsSpring(LinearFrequency, LinearDampingRatio);
        velJoint.SpringAngular = new PhysicsSpring(AngularFrequency, AngularDampingRatio);
    }
 public override void Create(EntityManager entityManager, GameObjectConversionSystem conversionSystem)
 {
     UpdateAuto();
     conversionSystem.World.GetOrCreateSystem <EndJointConversionSystem>().CreateJointEntity(
         this,
         GetConstrainedBodyPair(conversionSystem),
         PhysicsJoint.CreateFixed(
             new RigidTransform(OrientationLocal, PositionLocal),
             new RigidTransform(OrientationInConnectedEntity, PositionInConnectedEntity)
             )
         );
 }
Ejemplo n.º 3
0
        void ConvertFixedJoint(LegacyFixed joint)
        {
            var legacyWorldFromJointA = math.mul(
                new RigidTransform(joint.transform.rotation, joint.transform.position),
                new RigidTransform(quaternion.identity, joint.anchor)
                );

            RigidTransform worldFromBodyA  = Math.DecomposeRigidBodyTransform(joint.transform.localToWorldMatrix);
            var            connectedEntity = GetPrimaryEntity(joint.connectedBody);
            RigidTransform worldFromBodyB  = connectedEntity == Entity.Null
                ? RigidTransform.identity
                : Math.DecomposeRigidBodyTransform(joint.connectedBody.transform.localToWorldMatrix);

            var bodyAFromJoint = new BodyFrame(math.mul(math.inverse(worldFromBodyA), legacyWorldFromJointA));
            var bodyBFromJoint = new BodyFrame(math.mul(math.inverse(worldFromBodyB), legacyWorldFromJointA));

            var jointData = PhysicsJoint.CreateFixed(bodyAFromJoint, bodyBFromJoint);

            m_EndJointConversionSystem.CreateJointEntity(joint, GetConstrainedBodyPair(joint), jointData);
        }
Ejemplo n.º 4
0
    private void GrabStart(ModelEntity entity, PhysicsBody body, Vector3 grabPos, Rotation grabRot)
    {
        if (!body.IsValid())
        {
            return;
        }

        if (body.PhysicsGroup == null)
        {
            return;
        }

        if (IsBodyGrabbed(body))
        {
            return;
        }

        GrabEnd();

        HeldBody = body;
        HeldRot  = grabRot.Inverse * HeldBody.Rotation;

        holdBody.Position = grabPos;
        holdBody.Rotation = HeldBody.Rotation;

        HeldBody.Sleeping  = false;
        HeldBody.AutoSleep = false;

        holdJoint = PhysicsJoint.CreateFixed(holdBody, HeldBody.MassCenterPoint());
        holdJoint.SpringLinear  = new(LinearFrequency, LinearDampingRatio);
        holdJoint.SpringAngular = new(AngularFrequency, AngularDampingRatio);
        holdJoint.Strength      = HeldBody.Mass * BreakLinearForce;

        HeldEntity = entity;

        Client?.Pvs.Add(HeldEntity);
    }