Beispiel #1
0
    public void Run()
    {
        UpdateCurrentUserState();
        CalculateStateChanges();

        // BACK UP IN CASE UNITY TRIGGERS FAILED TO COMMUNICATE RESET (Can happen in high speed simulations)
        if (resetter != null && !inReset && resetter.IsUserOutOfBounds())
        {
            Debug.LogWarning("Reset Aid Helped!");
            OnResetTrigger();
        }

        if (inReset)
        {
            if (resetter != null)
            {
                resetter.ApplyResetting();
                //Debug.LogWarning("Reset Calledddd!");
            }
        }
        else
        {
            if (redirector != null)
            {
                redirector.ApplyRedirection();
                //Debug.LogWarning("Redirection Calledddd!");
            }
        }

        this.simulationManager.statisticsLogger.UpdateStats();

        UpdatePreviousUserState();

        UpdateBodyPose();
    }
    //public string CheckCurrentStatus(RedirectedUnit[] otherUnits)
    //{
    //    List<Object2D> otherUsers = GetUsers(otherUnits);

    //    if (status == "WALL_RESET")
    //    {
    //        if (!resetter.NeedWallReset(realUser, realSpace))
    //        {
    //            status = "IDLE";
    //            resetter.NeedWallReset(realUser, realSpace);
    //        }
    //    }
    //    else if (status == "USER_RESET")
    //    {
    //        if (!resetter.NeedUserReset(realUser, otherUsers))
    //            status = "IDLE";
    //    }
    //    else if (status == "IDLE")
    //    {
    //        if (resetter.NeedWallReset(realUser, realSpace))
    //        {
    //            resultData.AddWallReset();
    //            status = "WALL_RESET";
    //        }
    //        else if (resetter.NeedUserReset(realUser, otherUsers))
    //        {
    //            resultData.AddUserReset();
    //            status = "USER_RESET";
    //        }
    //        else if (!GetEpisode().IsNotEnd())
    //            status = "END";
    //    }

    //    return status;
    //}

    //public void Simulation(RedirectedUnit[] otherUnits)
    //{
    //    string currentStatus = CheckCurrentStatus(otherUnits);

    //    switch (currentStatus)
    //    {
    //        case "IDLE":
    //            Move();
    //            break;
    //        case "WALL_RESET":
    //            ApplyWallReset();
    //            break;
    //        case "USER_RESET":
    //            ApplyUserReset();
    //            break;
    //        default:
    //            break;
    //    }
    //}

    //public void ApplyUserReset()
    //{
    //    resetter.ApplyReset(realUser, virtualUser, realSpace,"User"); // 필요하면 User Reset과 Wall Reset의 방법을 다르게 만들 수 있도록 이런 식으로 구현
    //}

    //public void ApplyWallReset()
    //{
    //    resetter.ApplyReset(realUser, virtualUser, realSpace,"Wall");
    //}

    public void Move()
    {
        (Vector2 deltaPosition, float deltaRotation) = controller.VirtualMove(realUser, virtualUser, virtualSpace);         // 가상 유저를 이동 (시뮬레이션)
        (Redirector.GainType type, float degree)     = redirector.ApplyRedirection(realUser, deltaPosition, deltaRotation); // 왜곡시킬 값을 계산
        controller.RealMove(realUser, type, degree);                                                                        // 실제 유저를 이동

        resultData.setGains(type, redirector.GetApplidedGain(type));
        resultData.AddElapsedTime(Time.fixedDeltaTime);
    }
Beispiel #3
0
    void LateUpdate()
    {
        //Debug.Log("Hi im starting to Late update");
        simulatedTime += 1.0f / targetFPS;

        //if (MOVEMENT_CONTROLLER == MovementController.AutoPilot)
        //    simulatedWalker.WalkUpdate();

        UpdateCurrentUserState();
        CalculateStateChanges();

        // BACK UP IN CASE UNITY TRIGGERS FAILED TO COMMUNICATE RESET (Can happen in high speed simulations)
        if (resetter != null && !inReset && resetter.IsUserOutOfBounds())
        {
            Debug.LogWarning("Reset Aid Helped!");
            OnResetTrigger();
        }

        if (inReset)
        {
            if (resetter != null)
            {
                resetter.ApplyResetting();
            }
        }
        else
        {
            if (redirector != null)
            {
                //Debug.Log("Hi im about to apply redirection");
                redirector.ApplyRedirection();
                //Debug.Log("Hi i just applied redirection");
            }
        }

        statisticsLogger.UpdateStats();

        UpdatePreviousUserState();

        UpdateBodyPose();
        //Debug.Log("Hi im finishing ");
    }
Beispiel #4
0
    protected virtual void LateUpdate()
    {
        simulatedTime += 1.0f / targetFPS;

        //if (MOVEMENT_CONTROLLER == MovementController.AutoPilot)
        //    simulatedWalker.WalkUpdate();

        UpdateCurrentUserState();
        CalculateStateChanges();

        // BACK UP IN CASE UNITY TRIGGERS FAILED TO COMMUNICATE RESET (Can happen in high speed simulations)
        if (resetter != null && !inReset && resetter.IsUserOutOfBounds())
        {
            //Debug.LogWarning("Reset Aid Helped!");
            OnResetTrigger();
        }

        if (inReset)
        {
            if (resetter != null)
            {
                resetter.ApplyResetting();
            }
        }
        else
        {
            if (redirector != null)
            {
                redirector.ApplyRedirection();
            }
        }

        statisticsLogger.UpdateStats();

        UpdatePreviousUserState();

        // DISABLED: What is the point of this function? Headfollower already does this
        //UpdateBodyPose();
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        TimerIncrease();
        CalculateDeltaPar();
        MovePlayer(player);
        //Apply Redirection
        switch (action)
        {
        case Redirector.ActionTaken.Zero: break;

        case Redirector.ActionTaken.PositiveRotation:
            redirector.ApplyRedirection(Redirector.RedirectorType.Rotation, player.transform, deltaDistance, deltaDiv, gain: redirector.rotateGainEnlarge);
            break;

        case Redirector.ActionTaken.NegativeRotation:
            redirector.ApplyRedirection(Redirector.RedirectorType.Rotation, player.transform, deltaDistance, deltaDiv, gain: redirector.rotateGainDecrease);
            break;

        case Redirector.ActionTaken.ClockwiseCurvature:
            redirector.ApplyRedirection(Redirector.RedirectorType.Curvature, player.transform, deltaDistance, deltaDiv, clockwise: true, radius: redirector.curvatureRadius);
            break;

        case Redirector.ActionTaken.CounterClockwiseCurvature:
            redirector.ApplyRedirection(Redirector.RedirectorType.Curvature, player.transform, deltaDistance, deltaDiv, clockwise: false, radius: redirector.curvatureRadius);
            break;

        default: break;
        }

        //velocity data record
        if ((timer - timerVelocity * velocityInterval) >= velocityInterval)
        {
            velocity = distance / velocityInterval;
            timerVelocity++;
            distance = 0;
        }

        //exponentially smoothed orientation
        if ((timerOrientation - timerOrientation * orientationInterval) >= orientationInterval)
        {
            //ExponentiallySmoothedSample(true);
        }
        else
        {
            //ExponentiallySmoothedSample(false);
        }

        //data record
        if ((timer - timeHorizon * timerDataRecord) >= timeHorizon)
        {
            data.velocity           = velocity;
            data.virtualOrientation = player.transform.eulerAngles.y;//没有使用指数平滑
            data.virtualPosition    = GeneralVector3.Vector3NoHeight(playerTransform.position);
            Vector3 originPoint = GeneralVector3.Vector3NoHeight(Corner4.position);
            //Debug.Log(originPoint);
            Vector3 xAxis = GeneralVector3.Vector3NoHeight(Corner3.position);
            //Debug.Log(xAxis);
            Vector3 zAxis = GeneralVector3.Vector3NoHeight(Corner1.position);
            //Debug.Log(zAxis);
            data.realPosition = GeneralVector3.GetRealPoint(originPoint, xAxis, zAxis, data.virtualPosition);
            //Debug.Log(data.realPosition);
            data.realOrientation = player.transform.eulerAngles.y - Center.rotation.eulerAngles.y;
            timerDataRecord++;
            WayPointsReal[] wayPointsReals = CalWayPoint2DCoor(wayPoint.wayPoints, playerTransform, wayPoint.wayPoints.Length, data.realOrientation, data.velocity * redirector.timeDepth * timeHorizon * 2, originPoint, xAxis, zAxis);
            //Debug.Log(data.realPosition);
            //Debug.Log(wayPointsReals[0].realPosition);
            action = redirector.MPCRedirect(data, wayPointsReals, redirector.timeDepth).action;
            Debug.Log(action);
        }
    }