Esempio n. 1
0
    public void Initialize()
    {
        this.initialPosition = Vector2.zero;
        this.initialForward  = Vector2.up;

        // Initialize according to the motion type
        if (this.movementController == MotionManager.MovementController.AutoPilot)
        {
            this.DISTANCE_TO_WAYPOINT_THRESHOLD = 0.05f;// 0.0001f;

            // Setup waypoints and pathseed
            InstantiateSimulationPrefab();

            switch (condPath)
            {
            case VirtualPathGenerator.PathSeedChoice.Office:
                currentPathSeed = VirtualPathGenerator.getPathSeedOfficeBuilding();
                break;

            case VirtualPathGenerator.PathSeedChoice.ExplorationSmall:
                currentPathSeed = VirtualPathGenerator.getPathSeedExplorationSmall();
                break;

            case VirtualPathGenerator.PathSeedChoice.ExplorationLarge:
                currentPathSeed = VirtualPathGenerator.getPathSeedExplorationLarge();
                break;

            case VirtualPathGenerator.PathSeedChoice.LongWalk:
                currentPathSeed = VirtualPathGenerator.getPathSeedLongCorridor();
                break;

            case VirtualPathGenerator.PathSeedChoice.ZigZag:
                currentPathSeed = VirtualPathGenerator.getPathSeedZigzag();
                break;

            case VirtualPathGenerator.PathSeedChoice.Maze:
                this.waypoints = VirtualPathGenerator.getPathSeedMaze();
                break;
            }

            if (condPath != VirtualPathGenerator.PathSeedChoice.Maze)
            {
                float sumOfDistances, sumOfRotations;
                this.waypoints = VirtualPathGenerator.generatePath(currentPathSeed, initialPosition, initialForward, out sumOfDistances, out sumOfRotations);
                Debug.Log("MOTION sumOfDistances: " + sumOfDistances);
                Debug.Log("MOTION sumOfRotations: " + sumOfRotations);
            }


            // Set First Waypoint Position and Enable It
            this.targetWaypoint.position = new Vector3(this.waypoints[0].x, this.targetWaypoint.position.y, this.waypoints[0].y);
            this.waypointIterator        = 0;
            this.targetWaypoint.gameObject.SetActive(true);
            Debug.Log("First waypoint initialized");
        }
    }
Esempio n. 2
0
    void startNextExperiment()
    {
        Debug.Log("---------- EXPERIMENT STARTED ----------");

        ExperimentSetup setup = experimentSetups[experimentIterator];

        printExperimentDescriptor(getExperimentDescriptor(setup));

        // Setting Gain Scale Factors
        //RedirectionManager.SCALE_G_T = setup.gainScaleFactor.x;
        //RedirectionManager.SCALE_G_R = setup.gainScaleFactor.y;
        //RedirectionManager.SCALE_G_C = setup.gainScaleFactor.z;

        // Enabling/Disabling Redirectors
        simulationManager.redirectionManager.UpdateRedirector(setup.redirector);
        simulationManager.redirectionManager.UpdateResetter(setup.resetter);

        // Setup Trail Drawing
        simulationManager.trailDrawer.enabled = !simulationManager.runAtFullSpeed;

        // Enable Waypoint
        simulationManager.motionManager.targetWaypoint.gameObject.SetActive(true);

        // Resetting User and World Positions and Orientations
        this.transform.position = Vector3.zero;
        this.transform.rotation = Quaternion.identity;
        // ESSENTIAL BUG FOUND: If you set the user first and then the redirection recipient, then the user will be moved, so you have to make sure to do it afterwards!
        //Debug.Log("Target User Position: " + setup.initialConfiguration.initialPosition.ToString("f4"));
        simulationManager.redirectionManager.headTransform.position = Utilities.UnFlatten(setup.initialConfiguration.initialPosition, simulationManager.redirectionManager.headTransform.position.y);
        //Debug.Log("Result User Position: " + redirectionManager.userHeadTransform.transform.position.ToString("f4"));
        simulationManager.redirectionManager.headTransform.rotation = Quaternion.LookRotation(Utilities.UnFlatten(setup.initialConfiguration.initialForward), Vector3.up);

        // Set up Tracking Area Dimensions
        simulationManager.envManager.UpdateTrackedSpaceDimensions(setup.trackingSizeShape.x, setup.trackingSizeShape.z);

        // Set up Virtual Path
        float sumOfDistances, sumOfRotations;

        simulationManager.motionManager.waypoints = VirtualPathGenerator.generatePath(setup.pathSeed, setup.initialConfiguration.initialPosition, setup.initialConfiguration.initialForward, out sumOfDistances, out sumOfRotations);
        Debug.Log("sumOfDistances: " + sumOfDistances);
        Debug.Log("sumOfRotations: " + sumOfRotations);
        if (setup.redirector == typeof(ZigZagRedirector))
        {
            // Create Fake POIs
            Transform poiRoot = (new GameObject()).transform;
            poiRoot.name          = "ZigZag Redirector Waypoints";
            poiRoot.localPosition = Vector3.zero;
            poiRoot.localRotation = Quaternion.identity;
            Transform poi0 = (new GameObject()).transform;
            poi0.localPosition = Vector3.zero;
            poi0.parent        = poiRoot;
            List <Transform> zigzagRedirectorWaypoints = new List <Transform>();
            zigzagRedirectorWaypoints.Add(poi0);
            foreach (Vector2 waypoint in simulationManager.motionManager.waypoints)
            {
                Transform poi = (new GameObject()).transform;
                poi.localPosition = Utilities.UnFlatten(waypoint);
                poi.parent        = poiRoot;
                zigzagRedirectorWaypoints.Add(poi);
            }
            ((ZigZagRedirector)simulationManager.redirectionManager.redirector).waypoints = zigzagRedirectorWaypoints;
        }


        // Set First Waypoint Position and Enable It
        simulationManager.motionManager.targetWaypoint.position = new Vector3(simulationManager.motionManager.waypoints[0].x, simulationManager.motionManager.targetWaypoint.position.y, simulationManager.motionManager.waypoints[0].y);
        simulationManager.motionManager.waypointIterator        = 0;

        // POSTPONING THESE FOR SAFETY REASONS!
        //// Allow Walking
        //UserController.allowWalking = true;

        //// Start Logging
        //redirectionManager.redirectionStatistics.beginLogging();
        //redirectionManager.statisticsLogger.beginLogging();

        //lastExperimentRealStartTime = Time.realtimeSinceStartup;
        experimentInProgress = true;
    }