//public LongWalkEpisode(Space2D virtualSpace, int episodeLength) : base(virtualSpace, episodeLength) { }

    protected override void GenerateEpisode(Transform2D virtualUserTransform, Space2D virtualSpace)
    {
        float angle    = 0;
        float distance = 12.0f;

        Vector2 sampleForward = Utility.rotateVector2(virtualUserTransform.forward, angle);
        Vector2 userPosition  = virtualUserTransform.localPosition;

        currentTargetPosition = userPosition + sampleForward * distance;
    }
예제 #2
0
    public Vector2 GetTarget(Transform2D virtualUserTransform, Space2D virtualSpace)
    {
        if (!currentTargetPosition.HasValue)
        {
            GenerateEpisode(virtualUserTransform, virtualSpace);
            //InstaniateTarget();
        }

        return(currentTargetPosition.Value);
    }
예제 #3
0
    //public bool usePredefinedSpace;
    //public bool usePredefinedOrigin;
    //public Vector2 originPosition; // simulationManager local 2D 좌표계 기준
    //public float originRotation;
    //public Vector2 size; // n각형으로 일반화 어떻게 시키지?

    public Space2D GetSpace2D()
    {
        if (spaceInstance == null)
        {
            List <Object2D> obstacles = new List <Object2D>();
            foreach (ObjectSetting obstacleObject in obstacleObjects)
            {
                obstacles.Add(obstacleObject.GetObject());
            }

            Object2D space = spaceObject.GetObject();
            spaceInstance = new Space2D(space, obstacles);
        }

        return(spaceInstance);
    }
    public RedirectedUnit(Redirector redirector, Resetter resetter, SimulationController controller, Space2D realSpace, Space2D virtualSpace, Vector2 realStartPosition, Vector2 virtualStartPosition)
    {
        this.redirector   = redirector;
        this.resetter     = resetter;
        this.controller   = controller;
        this.realSpace    = realSpace;
        this.virtualSpace = virtualSpace;
        this.status       = "IDLE";

        resultData = new ResultData();
        resultData.setUnitID(totalID++);
        id = totalID;
        resultData.setEpisodeID(controller.GetEpisodeID());

        realUser    = new Circle2D(0.3f, realStartPosition, realSpace.space.transform); // TODO: 알아서 형변환 되게끔 수정
        virtualUser = new Circle2D(0.3f, virtualStartPosition, virtualSpace.space.transform);
    }
예제 #5
0
    public RedirectedUnit GetUnit(Space2D realSpace, Space2D virtualSpace)
    {
        if (unitInstance == null)
        {
            if (useRandomStart)
            {
                //float boundX = simulationSetting.realSpaceSetting.size.x / 2 - 1.5f;
                //float boundY = simulationSetting.realSpaceSetting.size.y / 2 - 1.5f;
                //float x = Random.Range(-boundX, boundX);
                //float y = Random.Range(-boundY, boundY);
                //realStartPosition = new Vector2(x, y);
            }

            unitInstance = new RedirectedUnit(GetRedirector(), GetRestter(), GetController(), realSpace, virtualSpace, realStartPosition, virtualStartPosition);
        }

        return(unitInstance);
    }
예제 #6
0
    //public RandomEpisode(Space2D virtualSpace, int episodeLength) : base(virtualSpace, episodeLength) { }

    protected override void GenerateEpisode(Transform2D virtualUserTransform, Space2D virtualSpace)
    {
        Vector2 samplingPosition = Vector2.zero;
        Vector2 userPosition     = virtualUserTransform.localPosition;

        do
        {
            float angle    = Utility.sampleUniform(-180.0f, 180.0f);
            float distance = Utility.sampleUniform(2.0f, 5.0f);

            Vector2 sampleForward = Matrix3x3.CreateRotation(angle) * virtualUserTransform.forward;
            //Vector3 sampleForward = Quaternion.AngleAxis(angle, Vector3.up) * simulationController.GetUserVirtualTransform().forward;

            samplingPosition = userPosition + sampleForward * distance; // local 좌표계에서 절대 위치 기준
        } while (!virtualSpace.IsInside(samplingPosition, 0.1f));       // while (!virtualSpace.IsReallyInside(userPosition, samplingPosition));

        currentTargetPosition = samplingPosition;
    }
    public override string ApplyReset(Object2D realUser, Object2D virtualUser, Space2D realSpace, string resetType)
    {
        if (isFirst)
        {
            realTargetRotation    = Matrix3x3.CreateRotation(targetAngle) * realUser.transform.forward;
            virtualTargetRotation = Matrix3x3.CreateRotation(ratio * targetAngle) * virtualUser.transform.forward;
            isFirst = false;
        }

        float realAngle = Vector2.SignedAngle(realUser.transform.forward, realTargetRotation);

        if (Mathf.Abs(realAngle) >= epsilonRotation)
        {
            realUser.Rotate(rotationSpeed * Time.deltaTime);
            virtualUser.Rotate(ratio * rotationSpeed * Time.deltaTime);
        }
        else
        {
            Utility.SyncDirection(virtualUser, realUser, virtualTargetRotation, realTargetRotation);

            switch (resetType)
            {
            case "Wall":
                while (NeedWallReset(realUser, realSpace))
                {
                    CalculationErrorAdjustment(realUser.transform, resetType, (Polygon2D)realSpace.space);
                }
                break;

            case "User":
                break;
            }

            if (realUser.gameObject != null)
            {
                realUser.gameObject.transform.position = Utility.Cast2Dto3D(realUser.transform.position);
            }

            isFirst = true;
            return("DONE");
        }

        return("NOT_YET");
    }
예제 #8
0
    Space2D realSpace, virtualSpace;            // 실제 공간과 가상 공간에 대한 정보를 담은 변수

    //private StreamWriter writer;

    public void GenerateSpaces()
    {
        realSpace    = simulationSetting.realSpaceSetting.GetSpace2D();
        virtualSpace = simulationSetting.virtualSpaceSetting.GetSpace2D();
    }
 protected override void GenerateEpisode(Transform2D virtualUserTransform, Space2D virtualSpace)
 {
     currentTargetPosition = targetPositionList[currentEpisodeIndex];
 }
    public (Vector2, float) VirtualMove(Object2D realUser, Object2D virtualUser, Space2D virtualSpace)
    {
        Transform2D virtualUserTransform = virtualUser.transform;

        if (!initializing)
        {
            ResetCurrentState(virtualUserTransform);
            initializing = false;
        }

        if (episode.IsNotEnd())
        {
            if (isFirst)
            {
                isFirst         = false;
                targetPosition  = episode.GetTarget(virtualUserTransform, virtualSpace);
                initialToTarget = targetPosition - virtualUserTransform.localPosition;
                float InitialAngle    = Vector2.SignedAngle(virtualUserTransform.forward, initialToTarget);
                float initialDistance = Vector2.Distance(virtualUserTransform.localPosition, targetPosition);

                virtualTargetDirection = Matrix3x3.CreateRotation(InitialAngle) * virtualUser.transform.forward; // target을 향하는 direction(forward)를 구함
                //realTargetDirection = Matrix3x3.CreateRotation(InitialAngle) * realUser.transform.forward;

                virtualTargetPosition = virtualUser.transform.localPosition + virtualTargetDirection * initialDistance; // target에 도달하는 position을 구함
                //realTargetPosition = realUser.transform.localPosition + realTargetDirection * initialDistance;

                maxRotTime      = Mathf.Abs(InitialAngle) / rotationSpeed;
                maxTransTime    = initialDistance / translationSpeed;
                remainRotTime   = 0;
                remainTransTime = 0;

                initialAngleDirection = Mathf.Sign(InitialAngle);
            }

            float distance = (targetPosition - virtualUserTransform.localPosition).magnitude;
            float angle    = Vector2.SignedAngle(virtualUserTransform.forward, initialToTarget);

            if (remainRotTime < maxRotTime)
            {
                virtualUser.Rotate(initialAngleDirection * rotationSpeed * Time.fixedDeltaTime);
                remainRotTime += Time.fixedDeltaTime;
            }
            else if (remainTransTime < maxTransTime)
            {
                if (isFirst2) // 방향을 동기화
                {
                    isFirst2 = false;
                    SyncDirection(virtualUser, virtualTargetDirection);
                }
                else
                {
                    virtualUser.Translate(virtualUserTransform.forward * translationSpeed * Time.fixedDeltaTime, Space.World);
                    remainTransTime += Time.fixedDeltaTime;
                }
            }
            else
            {
                if (isFirst3) // 위치를 동기화
                {
                    isFirst3 = false;
                    SyncPosition(virtualUser, virtualTargetPosition);
                }
                else
                {
                    episode.DeleteTarget();

                    //Debug.Log(string.Format("realUser: {0}", realUser.transform));
                    //Debug.Log(string.Format("virtualUser: {0}", virtualUser.transform));

                    isFirst  = true;
                    isFirst2 = true;
                    isFirst3 = true;
                }
            }
        }

        UpdateCurrentState(virtualUserTransform);

        return(GetDelta(virtualUserTransform.forward));
    }
예제 #11
0
 public Space2D(Space2D otherSpace)
 {
     this.space     = new Object2D(otherSpace.space);
     this.obstacles = new List <Object2D>(otherSpace.obstacles);
 }
예제 #12
0
 protected Scene2D(Canvas canvas, World2D world, Space2D space) : base(canvas, world, space)
 {
 }
예제 #13
0
 protected virtual void GenerateEpisode(Transform2D virtualUserTransform, Space2D virtualSpace)
 {
 }
예제 #14
0
 public virtual string ApplyReset(Object2D realUser, Object2D virtualUser, Space2D realSpace, string resetType)
 {
     return("DONE");
 }
예제 #15
0
    public bool NeedWallReset(Object2D realUser, Space2D realSpace)
    {
        Vector2 realUserPosition = realUser.transform.localPosition;

        return(!realSpace.IsInside(realUserPosition, 0));
    }