コード例 #1
0
    GameObject addErrors(MovingBall m, string error_type)
    {
        float error_std_x = error_model.GetErrorStdX(m);
        float error_std_y = error_model.GetErrorStdY(m);
        float error_std_z = error_model.GetErrorStdZ(m);

        Debug.LogFormat("Errors: X: {0}, Y: {1}, Z: {2}", error_std_x, error_std_y, error_std_z);
        ProjectionError error_object = null;

        if (error_type == "shell")
        {
            // Sample error object
            error_object = Instantiate <ProjectionError>(error_sample);
        }
        else if (error_type == "heatmap")
        {
            error_object = Instantiate <ProjectionError>(heatmap_error_sample);
        }
        else
        {
            Debug.Log("You've f****d up.");
            return(null);
        }
        error_object.parent_object = m;
        error_object.err_x         = error_std_x;
        error_object.err_y         = error_std_y;
        error_object.err_z         = error_std_z;
        error_object.error_type    = error_type;
        return(error_object.gameObject);
    }
コード例 #2
0
        public void FindShortestPath(int x, int y)
        {
            try
            {
                if (_matrix.DijkstraData == null)
                {
                    return;
                }
                int value = _matrix.DijkstraData[x, y].Value;
                if (value < 0)
                {
                    MessageBox.Show(String.Format("Không tìm được đường đi từ điểm '{0}' đến điểm '{1}'",
                                                  (char)('1' + x), (char)('1' + y)));
                    return;
                }
                if (_ball == null)
                {
                    _ball = new MovingBall(this);
                }
                _ball.Reset();
                _path.Clear();
                _preNodeIndex = x;
                _ball.NodeLocations.Add(this.Controls[x + 1].Location);

                GetPath(x, y);

                _ball.NodeLocations.Add(this.Controls[y + 1].Location);
                _ball.Start();
                Invalidate();
            }
            catch (IndexOutOfRangeException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: TestScript.cs プロジェクト: kagami3421/EzFSM
    void Start()
    {
        IdleBall idle = new IdleBall();
        MovingBall moving = new MovingBall();

        idle.AddTransition(moving, "GoToMove");
        moving.AddTransition(idle, "GoToIdle");

        AddState(idle, "Idle");
        AddState(moving, "Moving");

        InitFSM();
    }
コード例 #4
0
    private float ComputeError(MovingBall m, float[] betas)
    {
        float i = 0.0f; // m.x_offset - this.kinect_x_offset;
        float z = (m.y_offset - this.kinect_y_offset) / conversion_factor;
        float j = 0.0f; // m.z_offset - this.kinect_z_offset;


        float ji = i * j;
        float iz = i * z;
        float zj = z * j;

        float i2 = i * i;
        float j2 = j * j;
        float z2 = z * z;

        float square_vals = betas[0] * j2 + betas[1] * i2 + betas[2] * z2;
        float corr_vals   = betas[3] * ji + betas[4] * iz + betas[5] * zj;
        float lin_vals    = betas[6] * j + betas[7] * i + betas[8] * z + betas[9];

        return(square_vals + corr_vals + lin_vals);
    }
コード例 #5
0
 public float GetErrorStdZ(MovingBall m)
 {
     return(z_factor * ComputeError(m, y_betas));
 }
コード例 #6
0
 public float GetErrorStdY(MovingBall m)
 {
     return(conversion_factor * ComputeError(m, z_betas));
 }
コード例 #7
0
 public float GetErrorStdX(MovingBall m)
 {
     return(x_factor * ComputeError(m, x_betas));
 }
コード例 #8
0
    void updateObjects()
    {
        // Clean up the scene objects
        foreach (GameObject ext_object in tracked_game_objects)
        {
            Destroy(ext_object);
        }
        tracked_game_objects.Clear();

        // Set the hand information for the current index
        if (experiment_info[current_index].show_hands)
        {
            hand_model_l.SetActive(true);
            hand_model_r.SetActive(true);
        }
        else
        {
            hand_model_r.SetActive(false);
            hand_model_l.SetActive(false);
        }

        // Get the information of the moving balls
        MovingBallInfo[] object_infos = experiment_info[current_index].data;
        error_model.UpdateKinectPosition(experiment_info[current_index].kinect_x_offset, experiment_info[current_index].kinect_y_offset, experiment_info[current_index].kinect_z_offset);

        // Set the hand tracking
        foreach (HandPositionManager hp in GameObject.FindObjectsOfType <HandPositionManager>())
        {
            hp.from_leap = !experiment_info[current_index].use_vive_tracker;
        }

        // Construct the object
        foreach (MovingBallInfo info in object_infos)
        {
            // Instantiate the new object based on the reference object
            MovingBall new_object = null;
            if (info.type == "sphere")
            {
                new_object = Instantiate(object_samples[0]);
            }
            else if (info.type == "cylinder")
            {
                new_object = Instantiate(object_samples[1]);
            }
            else if (info.type == "cube")
            {
                new_object = Instantiate(object_samples[2]);
            }
            else if (info.type == "flat-cylinder")
            {
                new_object = Instantiate(object_samples[3]);
            }
            else if (info.type == "hand")
            {
                HandTracker.Hand h = HandTracker.LoadHand(info.handPath);
                h._sphere_material = GameObject.FindGameObjectWithTag("hand_tracker").GetComponent <HandTracker>()._sphere_material;
                h._cyl_material    = GameObject.FindGameObjectWithTag("hand_tracker").GetComponent <HandTracker>()._cyl_material;
                new_object         = Instantiate(object_samples[4]);
                new_object.GetComponent <HandMovingBall>().h = h;

                // ref_object = object_samples[4];
            }
            else if (info.type == "controller")
            {
                new_object = Instantiate(object_samples[5]);
            }
            else if (info.type == "neutral")
            {
                new_object = Instantiate(object_samples[6]);
            }
            else
            {
                Debug.Log("Error. Invalid object type.");
                continue;
            }
            new_object.use_vive = info.enable_tracking;


            // Set the x, y and z offset from the info
            new_object.x_offset = info.x_offset;
            new_object.z_offset = info.z_offset;
            new_object.y_offset = info.y_offset;

            new_object.xrot_offset = info.xrot_offset; // + t.start_rot_x;
            new_object.zrot_offset = info.zrot_offset; // + t.start_rot_z;
            new_object.yrot_offset = info.yrot_offset; // + t.start_rot_y;


            if (info.wireframe)
            {
                new_object.SetWireframe();
            }

            // Set the rotation and scale from the info
            new_object.transform.eulerAngles = new Vector3(new_object.transform.eulerAngles.x, new_object.transform.eulerAngles.y, new_object.transform.eulerAngles.z);
            new_object.transform.localScale  = new Vector3(info.scale_x, info.scale_y, info.scale_z);

            // Add the object to the tracked game objects class
            tracked_game_objects.Add(new_object.gameObject);
            if (info.show_error)
            {
                tracked_game_objects.Add(addErrors(new_object, info.error_type));
            }
        }
    }
コード例 #9
0
    public BallInterface()
    {
        topLabelPoint = newPoint(0, 0);
        topLabelSize  = newSize(interfaceWidth, 50.0);

        label.Text      = "Corey's Moving Ball";
        label.Location  = topLabelPoint;
        label.TextAlign = ContentAlignment.MiddleCenter;
        label.Size      = topLabelSize;
        label.BackColor = Color.LightCoral;
        label.ForeColor = Color.Black;

        bottomContainer.Location  = newPoint(0, 8 / 10.0 * interfaceHeight);
        bottomContainer.Size      = newSize(interfaceWidth, 2 / 10.0 * interfaceHeight);
        bottomContainer.BackColor = Color.LightBlue;

        goButton.Text     = "Play";
        goButton.Location = newPoint(50, 50);
        goButton.Size     = newSize(100, 100);
        AcceptButton      = goButton;

        resetButton.Text     = "Reset";
        resetButton.Location = newPoint(150, 50);
        resetButton.Size     = newSize(100, 100);

        exitButton.Text     = "Exit";
        exitButton.Location = newPoint(250, 50);
        exitButton.Size     = newSize(100, 100);

        positionLabel.Location = newPoint(bottomContainer.Width - 300.0, 50);
        positionLabel.Size     = newSize(100, 100);
        positionLabel.Text     = positionString;

        pathX      = 1 / 10.0 * interfaceWidth;
        pathY      = topLabelPoint.Y + 100.0;
        pathWidth  = 8 / 10.0 * interfaceWidth;
        pathHeight = 5 / 10.0 * interfaceHeight;

        path = new Rectangle((int)pathX, (int)pathY, (int)pathWidth, (int)pathHeight);
        ball = new MovingBall(path);
        //Set size of the interface
        Size = newSize(interfaceWidth, interfaceHeight);

        ballClock.Elapsed += UpdateBall;
        uiClock.Elapsed   += UpdateUI;
        uiClock.Start();

        goButton.Click    += new EventHandler(StartAndStop);
        resetButton.Click += new EventHandler(Reset);
        exitButton.Click  += new EventHandler(Exit);

        isPlaying = false;
        ballPen   = donePen;
        ballBrush = doneBrush;

        Controls.Add(label);
        bottomContainer.Controls.Add(goButton);
        bottomContainer.Controls.Add(resetButton);
        bottomContainer.Controls.Add(exitButton);
        bottomContainer.Controls.Add(positionLabel);
        Controls.Add(bottomContainer);
    }
コード例 #10
0
 void Awake()
 {
     GetMovingBall = this;
 }