Example #1
0
    /// <summary>
    /// The Unity Update() method.
    /// </summary>
    public void Update()
    {
        UpdateApplicationLifecycle();

        //move the person indicator according to positionn
        //Vector3 currentARPosition = Frame.Pose.position;
        Pose resultPose;

        PoseDataSource.GetDataFromSource(mDriver.poseSource, out resultPose);
        Vector3 currentARPosition = resultPose.position;

        if (!Tracking)
        {
            Tracking = true;
            //PrevARPosePosition = Frame.Pose.position;
            //PoseDataSource.GetDataFromSource(mDriver.poseSource, out resultPose);
            currentARPosition = resultPose.position;
            //PrevARPosePosition = mDriver.originPose.position;
        }
        //Remember the previous position so we can apply deltas
        Vector3 deltaPosition = currentARPosition - PrevARPosePosition;

        PrevARPosePosition = currentARPosition;

        // The initial forward vector of the sphere must be aligned with the initial camera direction in the XZ plane.
        // We apply translation only in the XZ plane.
        this.transform.Translate(deltaPosition.x, 0.0f, deltaPosition.z);
        // Set the pose rotation to be used in the CameraFollow script
        //Follower.targetRot = Frame.Pose.rotation;

        mMapController.targetRot = resultPose.rotation;
    }
Example #2
0
    protected override void OnUpdate()
    {
        var localInput    = GetSingleton <CommandTargetComponent>().targetEntity;
        var entityManager = EntityManager;

        if (localInput == Entity.Null)
        {
            var localPlayerId = GetSingleton <NetworkIdComponent>().Value;
            Entities.WithStructuralChanges().WithNone <PilotInput>().ForEach((Entity ent, ref PilotData pilot) =>
            {
                if (pilot.PlayerId == localPlayerId)
                {
                    UnityEngine.Debug.Log("Adding input buffer");
                    pilot.clientHasAuthority = true;
                    entityManager.AddBuffer <PilotInput>(ent);
                    entityManager.SetComponentData(GetSingletonEntity <CommandTargetComponent>(), new CommandTargetComponent {
                        targetEntity = ent
                    });
                }
            }).Run();

            return;
        }
        //Debug.Log("updateing input");
        var input = default(PilotInput);

        input.tick = World.GetExistingSystem <ClientSimulationSystemGroup>().ServerTick;
        PoseDataSource.GetDataFromSource(TrackedPoseDriver.TrackedPose.Center, out Pose head);
        PoseDataSource.GetDataFromSource(TrackedPoseDriver.TrackedPose.LeftPose, out Pose leftHand);
        PoseDataSource.GetDataFromSource(TrackedPoseDriver.TrackedPose.RightPose, out Pose rightHand);

        input.head = new PilotInput.Transform
        {
            positon  = head.position,
            rotation = head.rotation
        };
        input.leftHand = new PilotInput.Transform
        {
            positon  = leftHand.position,
            rotation = leftHand.rotation
        };
        input.rightHand = new PilotInput.Transform
        {
            positon  = rightHand.position,
            rotation = rightHand.rotation
        };

        var inputBuffer = EntityManager.GetBuffer <PilotInput>(localInput);

        inputBuffer.AddCommandData(input);
    }
    public override PoseDataFlags GetPoseFromProvider(out Pose output)
    {
        Pose HeadPose;

        if (PoseDataSource.GetDataFromSource(TrackedPoseDriver.TrackedPose.Head, out HeadPose) == PoseDataFlags.NoData)
        {
            output = LastPose;
            return(PoseDataFlags.NoData);
        }

        output.rotation = HeadPose.rotation;

        float Distance = Vector2.Distance(new Vector2(HeadPose.position.x, HeadPose.position.z), new Vector2(LastPose.position.x, LastPose.position.z));

        // climbing - snap to head pos
        if (m_PlayerClimb.Climbing)
        {
            output.position = HeadPose.position;
        }
        // beyond distance - correct it
        else
        {
            Vector3 LastPoseNewHeadHeightPosition    = new Vector3(LastPose.position.x, HeadPose.position.y, LastPose.position.z);
            Vector3 LastPoseFollowPositionAdjustment = (followDistance * (LastPoseNewHeadHeightPosition - HeadPose.position).normalized);
            Vector3 MoveTowardsCenterAdjustment      = (HeadPose.position - LastPoseNewHeadHeightPosition).normalized * 0.005f;

            if (Distance > followDistance && !m_PlayerWalk.moving)
            {
                output.position = HeadPose.position + LastPoseFollowPositionAdjustment;
            }
            else if (Distance > followDistance && m_PlayerWalk.moving)
            {
                output.position = HeadPose.position + LastPoseFollowPositionAdjustment + MoveTowardsCenterAdjustment;
            }
            else if (m_PlayerWalk.moving)
            {
                output.position = LastPoseNewHeadHeightPosition + MoveTowardsCenterAdjustment;
            }
            else
            {
                output.position = LastPoseNewHeadHeightPosition;
            }
        }

        LastPose = output;
        return(PoseDataFlags.Position | PoseDataFlags.Rotation);
    }