Beispiel #1
0
 void Start()
 {
     _canny1Bar.onValueChanged.AddListener(Canny1Changed);
     _canny2Bar.onValueChanged.AddListener(Canny2Changed);
     _threshold1Bar.onValueChanged.AddListener(Threshold1Changed);
     _threshold2Bar.onValueChanged.AddListener(Threshold2Changed);
     m_canShow = false;
     core      = CoreWrapper.GetInstance();
     core.InitCore();
     core.OpenVideoStream(0);
     core.GetCameraFrame();
 }
Beispiel #2
0
    // Use this for initialization
    void Start()
    {
        core     = CoreWrapper.GetInstance();
        cameraOk = core.OpenVideoStream(0);

        if (!cameraOk)
        {
            showPopUp = true;
            return;
        }

        this.frame   = core.GetCameraFrame();
        this.texture = new Texture2D(core.GetFrameWidth(), core.GetFrameHeight(), TextureFormat.BGRA32, false);
        this.transform.localScale = new Vector3(core.GetFrameWidth(), core.GetFrameHeight(), 1);

        //  Camera.main.transform.position = this.transform.position;
        //  Camera.main.transform.Translate(Vector3.back);
        Camera.main.orthographicSize = core.GetFrameHeight() / 2f + 2;
        m_FinishedBuild = false;
    }
Beispiel #3
0
    private void initializeMaze()
    {
        Debug.Log("Initgo");


        GameObject prefabObstacle = ((GameObject)Resources.Load("Prefabs/" + Const.OBSTACLE_PREFAB_NAME, typeof(GameObject)));

        GameObject o         = Instantiate(prefabObstacle, Vector3.zero, Quaternion.Euler(90.0f, 0.0f, 0.0f));
        Vector3    mazeScale = this.GetMazeScale();

        o.transform.localScale = mazeScale;
        o.transform.parent     = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME).transform;
        Renderer rend = o.GetComponent <Renderer>();

        rend.material.SetTextureScale("_MainTex", new Vector2(mazeScale.x, mazeScale.y));


        GameObject arrivalPrefab = ((GameObject)Resources.Load("Prefabs/" + Const.POINT_OF_ARRIVAL_PREFAB_NAME, typeof(GameObject)));

        double[] end = CoreWrapper.GetInstance().GetEndCenter();
        //GameObject arrivalObject = Instantiate(arrivalPrefab, MazeData.MAZE_POINT_OF_ARRIVAL, Quaternion.Euler(-90.0f, 0.0f, 0.0f));
        float      x_scale_arrivee = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)end[0];
        float      y_scale_arrivee = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)end[1];
        GameObject arrivalObject   = Instantiate(arrivalPrefab, new Vector3(x_scale_arrivee, 1.0f, y_scale_arrivee), Quaternion.Euler(-90.0f, 0.0f, 0.0f));

        arrivalObject.transform.parent     = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME).transform;
        arrivalObject.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);

        ParticleSystem arrivalPs = arrivalObject.GetComponent <ParticleSystem>();

        ParticleSystem.MainModule arrivalMain = arrivalPs.main;

        arrivalPs.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
        ParticleSystemRenderer arrivalPsr = arrivalObject.GetComponent <ParticleSystemRenderer>();

        arrivalPsr.renderMode = ParticleSystemRenderMode.Billboard;
        Debug.Log(arrivalMain.simulationSpace);
        arrivalMain.simulationSpace = ParticleSystemSimulationSpace.Local;


        /* for (int i = 0; i < MazeData.ARRAY_DATAS_TEST.Length / 2; ++i)
         * {
         *   MazeObstacle.Create(MazeData.ARRAY_DATAS_TEST[i, 0], MazeData.ARRAY_DATAS_TEST[i, 1]);
         * }*/
        List <double[, ]> walls = CoreWrapper.GetInstance().GetWall();

        foreach (double[,] wall in walls)
        {
            // Debug.Log("(" + -10f / 2f + 10f * (float)wall[0, 0] + " , " + -10f / 2f + 10f * (float)wall[0, 1] + "); (" + -10f / 2f + 10f * (float)wall[1, 0] + " , " + -10f / 2f + 10f * (float)wall[1, 1] + ")");

            float x_scale_wall_start = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)wall[0, 0];
            float y_scale_wall_start = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)wall[0, 1];
            float x_scale_wall_end   = -Const.HAUTEUR_MAZE / 2f + Const.HAUTEUR_MAZE * (float)wall[1, 0];
            float y_scale_wall_end   = -Const.LARGEUR_MAZE / 2f + Const.LARGEUR_MAZE * (float)wall[1, 1];
            Debug.Log("(" + x_scale_wall_start + " , " + y_scale_wall_start + "); (" + x_scale_wall_end + " , " + y_scale_wall_end + ")");

            MazeObstacle.Create(new Vector3(x_scale_wall_start, 1f, y_scale_wall_start), new Vector3(x_scale_wall_end, 1f, y_scale_wall_end));
        }

        GameObject mazeObject = GameObject.Find(Const.MAZE_GAMEOBJECT_NAME);

        mazeObject.transform.position   = new Vector3(0.8f, 394.74f, -10.15f);
        mazeObject.transform.localScale = new Vector3(1.4f, 1.0f, 1.0f);
    }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        if (paused)
        {
            return;
        }

        if (!cameraOk)
        {
            return;
        }

        this.frame = core.GetCameraFrame();
        this.texture.LoadRawTextureData(this.frame);
        this.texture.Apply();
        this.GetComponent <Renderer>().material.SetTexture("_MainTex", this.texture);

        /*
         *
         * if(!m_calibrated && !m_config_exists)
         * {
         *
         *  accTime += Time.deltaTime;
         *  if( accTime >= 1)
         *  {
         *      accTime -= 1;
         *      Debug.Log("mdr");
         *      StartCoroutine(AsycnFindPattern());
         *      //core.AddPatternToCalibrator();
         *
         *      if(core.CheckCalibrator())
         *      {
         *          m_calibrated = true;
         *          core.Calibrate();
         *      }
         *
         *  }
         *  return;
         *
         * }
         *
         */

        //this.camera.Video();
        if (!m_FinishedBuild)
        {
            core.Build();

            if (core.CheckBuid())
            {
                m_FinishedBuild = true;

                core.InitTransformDefault();

                Debug.Log("Built");
                double[]   start      = CoreWrapper.GetInstance().GetBeginCenter();
                GameObject prefabBall = ((GameObject)Resources.Load("Prefabs/" + Const.BALL_PREFAB_NAME, typeof(GameObject)));
                float      x_unity    = -Const.HAUTEUR_MAZE / 2 + Const.HAUTEUR_MAZE * (float)start[0];
                float      y_unity    = (-Const.LARGEUR_MAZE / 2 + Const.LARGEUR_MAZE * (float)start[1]) - 10.15f;

                Vector3    spawnPosition = new Vector3(x_unity, 400.0f, y_unity);
                GameObject objetBall     = Instantiate(prefabBall, spawnPosition, Quaternion.Euler(90.0f, 0.0f, 0.0f));
                objetBall.GetComponent <Ball>().spawnPosition = spawnPosition;

                GameObject o = ((GameObject)Resources.Load("Prefabs/" + Const.MAZE_PREFAB_NAME, typeof(GameObject)));
                maze = Instantiate(o, new Vector3(0.0f, 0.0f, 0.0f), Quaternion.Euler(0.0f, 0.0f, 0.0f));

                GameObject Init = ((GameObject)Resources.Load("Prefabs/" + Const.GAMEINITIALIZER_PREFAB_NAME, typeof(GameObject)));
                GameObject o2   = Instantiate(Init, Vector3.zero, Quaternion.Euler(0.0f, 0.0f, 0.0f));

                double[] rot = core.GetInitRot();

                rotLab = new Vector3(-(float)(rot[0]) + rotOffsetX,
                                     -(float)(rot[2]) + rotOffsetY,
                                     -(float)(rot[1]) + rotOffsetZ);

                inGameController.StartTimer();
            }
        }
        else
        {
            core.Tracking();
            core.UpdateTranform();

            double[] rot = core.GetDeltaRot();
            rotLab += new Vector3(-(float)rot[0], -(float)(rot[2]), -(float)(rot[1]));

            // correction

            /*
             * float rotZ = rotLab[2];
             * if(rotZ > 0)
             *  rotZ -= 35.50f;
             * else
             *  rotZ += 35.5f;
             */

            Quaternion previousRotation = maze.transform.rotation;
            Quaternion nextRotation     = Quaternion.Euler(rotLab);
            maze.transform.rotation = Quaternion.Lerp(previousRotation, nextRotation, Time.deltaTime * 15.0f);
        }
    }