Ejemplo n.º 1
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));
            }
        }
    }
Ejemplo n.º 2
0
 public HandMovingBall(HandTracker.Hand h)
 {
     this.h = h;
 }