Esempio n. 1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                var cube = new ColorCube();

                using (var stream = dlgOpen.OpenFile())
                {
                    for (int i = 0; i < 4 * 4 * 6; i++)
                    {
                        var b = stream.ReadByte();

                        if (b < 0)
                        {
                            break;
                        }

                        Faces face;
                        if (Enum.TryParse <Faces>(((char)b).ToString(), out face))
                        {
                            cube.colors[i] = ColorCube.colorDictionary[face];
                        }
                    }
                }

                using (var state = GlobalState.GetState())
                {
                    state.InitialCube = cube;
                }
            }
        }
 public void PeriodicUpdate(ColorCube cube)
 {
     foreach (var part in _parts)
     {
         part.PeriodicUpdate(cube);
     }
 }
Esempio n. 3
0
    void Update()
    {
        if (changeVictoryNumber == true)
        {
            RandomNumberVictory();
        }
        player1Objectif.text = "Qbert : " + victoryP1;
        player2Objectif.text = "PacMan : " + victoryP2;

        foreach (Transform child in transform)
        {
            colorCube = child.GetComponent <ColorCube>();
            if ((int)colorCube.whosColor == 1)
            {
                countP1++;
            }
            else if ((int)colorCube.whosColor == 2)
            {
                countP2++;
            }
        }
        if (countP1 == victoryP1 && countP2 == victoryP2)
        {
            stageint           += 1;
            changeVictoryNumber = true;
            score.AddScore(1000);
            stage.text = "Stage " + stageint;
        }
        countP1 = 0;
        countP2 = 0;
    }
Esempio n. 4
0
 public LayerCubes(int colorCube, int layerNumber)
 {
     colorLayer = NewColor(colorCube);
     layerNum   = layerNumber;
     Cubes      = new Cube[8];
     tower      = GameObject.FindObjectOfType <Tower>();
 }
Esempio n. 5
0
        public SimpleLiteD3d(NyARToolkitCS topLevelForm, ResourceBuilder i_resource)
        {
            NyMath.initialize();
            this._capture = i_resource.createWmCapture();
            this._capture.setOnSample(this);

            this._d3dmgr      = i_resource.createD3dManager(topLevelForm);
            this._back_ground = i_resource.createBackGround(this._d3dmgr);
            this._d3dcube     = new ColorCube(this._d3dmgr.d3d_device, 40);


            //AR用のパターンコードを読み出
            NyARCode code = i_resource.createNyARCode();

            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this.m_raster = i_resource.createARRaster();

            //1パターンのみを追跡するクラスを作成
            this.m_ar = new NyARSingleDetectMarker(i_resource.ar_param, code, 80.0, this.m_raster.getBufferType());
            //計算モードの設定
            this.m_ar.setContinueMode(false);

            ////立方体(頂点数8)の準備


            return;
        }
Esempio n. 6
0
        private void btnRand_Click(object sender, EventArgs e)
        {
            var cube = new Cube();

            var rand = new Random();

            var twists = new List <Twist>();

            for (int i = 0; i < 100; i++)
            {
                var t = Twist.Twists[rand.Next(0, Twist.Twists.Length - 1)];

                cube.twist(t);

                twists.Add(t);

                // ce modèle ne respecte pas la norme où les movement u,l,d,r,b bougent 2 couronnes. Ici la fonction twist n'en bouge qu'une. Le 2eme est bougé artificiellement
                if (char.IsLower(t.Name[0]))
                {
                    var t2 = Twist.Twists.First(x => x.Name == t.Name.ToUpper());

                    cube.twist(t2);
                }
            }

            var colorCube = new ColorCube();

            colorCube.setColors(cube);

            using (var state = GlobalState.GetState())
            {
                state.InitialCube = colorCube;
            }
        }
Esempio n. 7
0
    public static void AddPower(ColorCube cube, int value)
    {
        if (cube != null && !collectedfCubes.Contains(cube))
        {
            collectedfCubes.Add(cube);
        }

        instance.powerValue = Mathf.Clamp(instance.powerValue + value, 0, MAX_POWER);

        if (instance.powerValue == 0)
        {
            instance.powerValueDisplay.text  = "Nothing";
            instance.powerValueDisplay.color = Color.red;
        }
        else if (instance.powerValue == MAX_POWER)
        {
            instance.powerValueDisplay.text  = "More than you ever dreamed";
            instance.powerValueDisplay.color = Color.green;
        }
        else
        {
            instance.powerValueDisplay.text  = "" + instance.powerValue;
            instance.powerValueDisplay.color = Color.white;
        }

        instance.powerValueDisplay.text += "/" + DAILY_POWER_REQUIREMENTS[day];
    }
Esempio n. 8
0
 public void ChangeCube(ColorCube cube)
 {
     byteSave  = File.ReadAllBytes(path);
     cubeColor = cube;
     prefabCube.GetComponent <MeshRenderer>().material.color = cubeColor.colorCube;
     redColor   = cubeColor.colorCube.r;
     greenColor = cubeColor.colorCube.g;
     blueColor  = cubeColor.colorCube.b;
 }
        public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));

            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //マーカライブラリ(NyId)の構築
            this._mklib = new RawbitSerialIdTable(10);
            //マーカサイズテーブルの作成(とりあえず全部8cm)
            this._mklib.addAnyItem("any id", 80);

            //Realityの準備
            this._reality        = new NyARRealityD3d(ap, 10, 10000, 2, 10);
            this._reality_source = new NyARRealitySource_DShow(SCREEN_WIDTH, SCREEN_HEIGHT, null, 2, 100);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;



            //カメラProjectionの設定
            Matrix tmp = new Matrix();

            this._reality.getD3dCameraFrustum(ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();

            vp.Y      = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width  = ap.getScreenSize().w;
            vp.MaxZ   = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);
            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            return(true);
        }
Esempio n. 10
0
    void RandomNumberVictory()
    {
        victoryP2           = Mathf.CeilToInt(Random.Range(5, 24));
        victoryP1           = transform.childCount - victoryP2;
        changeVictoryNumber = false;
        stage.text          = "";

        foreach (Transform child in this.gameObject.transform)
        {
            ColorCube ChildScript = child.GetComponent <ColorCube>();
            ChildScript.whosColor = 0;
            ChildScript.transform.gameObject.renderer.material.color = Color.white;
        }
    }
Esempio n. 11
0
        public static Solution Solve(ColorCube cube)
        {
            var c1 = string.Join("", cube.FaceColors.Select(x => x.ToString()));

            var c1Split = Enumerable.Range(0, c1.Length / 16).Select(i => c1.Substring(i * 16, 16)).ToArray();

            // le solver java attend les couleurs des faces dans l'ordre URFDLB alors que le modèle renvoi ULFRBD donc on split la chaine en 6 et on réordonne
            var colorsForSolver = string.Join("", c1Split[0], c1Split[3], c1Split[2], c1Split[5], c1Split[1], c1Split[4]);

            var startInfo = new ProcessStartInfo("java", "solver " + colorsForSolver);

            startInfo.WorkingDirectory       = Path.Combine(Path.GetDirectoryName(cube.GetType().Assembly.Location), "solver");
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            var proc = Process.Start(startInfo);

            proc.WaitForExit(8000);

            var output = proc.StandardOutput.ReadToEnd();

            var algStr = output.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Last().Replace("    ", " ").Replace("   ", " ").Replace("  ", " ");

            var moves = MoveParser.Parse(algStr);

            if (moves.Count == 0 && !cube.IsSolved)
            {
                throw new Exception("Cube insoluble");
            }

            var calculator = new MoveCalculator();

            foreach (Move mv in moves)
            {
                calculator.AddCubeMove(mv);
            }

            var sol = new Solution();

            sol.MachineMoves = calculator.MachineMoves;
            sol.OriginalCube = cube.CloneCube();
            sol.SolverOutput = output;
            sol.Moves        = moves;
            sol.MovesString  = algStr;
            sol.Date         = DateTime.Now;

            return(sol);
        }
        public static ColorCube GetCube(IList <Color> colors)
        {
            var result = Classify(colors);

            result.Groups.ForEach((x) => x.UpdateAverageColor());


            var orderedRGroups = result.Groups.OrderBy((x) => x.AverageColor.R).ToList();

            if (orderedRGroups[0].AverageColor.B < orderedRGroups[1].AverageColor.B)
            {
                orderedRGroups[0].TheoreticalColor = Color.Green;
                orderedRGroups[1].TheoreticalColor = Color.Blue;
            }
            else
            {
                orderedRGroups[0].TheoreticalColor = Color.Blue;
                orderedRGroups[1].TheoreticalColor = Color.Green;
            }

            orderedRGroups[5].TheoreticalColor = Color.Orange;

            var orderedGGroups = orderedRGroups.Skip(2).Take(3).OrderBy((x) => x.AverageColor.G).ToList();

            orderedGGroups[0].TheoreticalColor = Color.Red;


            if (orderedGGroups[1].AverageColor.B < orderedGGroups[2].AverageColor.B)
            {
                orderedGGroups[1].TheoreticalColor = Color.Yellow;
                orderedGGroups[2].TheoreticalColor = Color.White;
            }
            else
            {
                orderedGGroups[1].TheoreticalColor = Color.White;
                orderedGGroups[2].TheoreticalColor = Color.Yellow;
            }

            var cube = new ColorCube();

            Console.WriteLine("R;G;B;ID;Color");
            result.Points.ForEach((x) => Console.WriteLine(x.MeasuredColor.R + ";" + x.MeasuredColor.G + ";" + x.MeasuredColor.B + ";" + x.Group.ID + ";" + x.Group.TheoreticalColor.Name));

            cube.setColors(result.Points.Select((x) => x.Group.TheoreticalColor).ToArray());

            return(cube);
        }
Esempio n. 13
0
        private void OnLoad(object sender, EventArgs e)
        {
            // initialize and bind framebuffer
            _framebuffer = new Framebuffer();
            _framebuffer.Bind(FramebufferTarget.Framebuffer);

            // initialize a renderbuffer and bind it to the depth attachment
            // to support depth testing while rendering to the texture
            _depthBuffer = new Renderbuffer();
            _depthBuffer.Init(RenderbufferStorage.DepthComponent, FramebufferWidth, FramebufferHeight);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, _depthBuffer);

            // initialize texture and bind it to the color attachment
            _texture = new Texture2D(SizedInternalFormat.Rgba8, FramebufferWidth, FramebufferHeight, 1);
            _framebuffer.Attach(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, _texture);
            Framebuffer.Unbind(FramebufferTarget.Framebuffer);

            // initialize demonstration geometry
            _cube = new ColorCube();
            _cube.UpdateBuffers();
            _quad = new TexturedQuad();
            _quad.UpdateBuffers();

            // initialize shaders
            _colorProgram   = ProgramFactory.Create <SimpleColorProgram>();
            _textureProgram = ProgramFactory.Create <SimpleTextureProgram>();

            // set up vertex attributes for the cube
            _cubeVao = new VertexArray();
            _cubeVao.Bind();
            _cubeVao.BindAttribute(_colorProgram.InPosition, _cube.VertexBuffer);
            _cubeVao.BindAttribute(_colorProgram.InColor, _cube.ColorBuffer);
            _cubeVao.BindElementBuffer(_cube.IndexBuffer);

            // set up vertex attributes for the quad
            _quadVao = new VertexArray();
            _quadVao.Bind();
            _quadVao.BindAttribute(_textureProgram.InPosition, _quad.VertexBuffer);
            _quadVao.BindAttribute(_textureProgram.InTexCoord, _quad.TexCoordBuffer);

            // set camera position
            Camera.DefaultState.Position = new Vector3(0, 0, 3);
            Camera.ResetToDefault();

            // enable depth testing
            GL.Enable(EnableCap.DepthTest);
        }
Esempio n. 14
0
    void Update()
    {
        TextEvent.text = nameEvent;
        if (launchEvent == true)
        {
            if (numberOfEvent <= 20)
            {
                Event_WeHaveToCooperate();
                nameEvent = "Cooperate";
            }
            if (numberOfEvent > 20)
            {
                Event_UpLife();
                nameEvent = "1 LIFE";
            }
        }
        if (EventFinish == true)
        {
            if (EventFail == true)
            {
                foreach (Transform child in pyramide.transform)
                {
                    ColorCube ChildScript = child.GetComponent <ColorCube>();
                    ChildScript.whosColor = 0;
                    ChildScript.transform.gameObject.renderer.material.color = Color.white;
                }
                timerofThisEvent = 0.0f;



                Debug.Log("Fail");
            }

            else if (EventFail == false)
            {
                timerofThisEvent = 0.0f;

                Debug.Log("Completed");
            }
            StartCoroutine(Event_Reset());
        }
    }
Esempio n. 15
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            var cube = new Cube();

            var rand = new Random();

            var twists = new List <Twist>();

            for (int i = 0; i < udMoves.Value; i++)
            {
                var t = Twist.Twists[rand.Next(0, Twist.Twists.Length - 1)];

                cube.twist(t);

                twists.Add(t);

                // ce modèle ne respecte pas la norme où les movement u,l,d,r,b bougent 2 couronnes. Ici la fonction twist n'en bouge qu'une. Le 2eme est bougé artificiellement
                if (char.IsLower(t.Name[0]))
                {
                    var t2 = Twist.Twists.First(x => x.Name == t.Name.ToUpper());

                    cube.twist(t2);
                }
            }

            var colorCube = new ColorCube();

            colorCube.setColors(cube);

            var c1 = string.Join("", colorCube.FaceColors.Select(x => x.ToString()));

            var c1Split = Enumerable.Range(0, c1.Length / 16).Select(i => c1.Substring(i * 16, 16)).ToArray();

            // le solver java attend les couleurs des faces dans l'ordre URFDLB alors que le modèle renvoi ULFRBD donc on split la chaine en 6 et on réordonne
            txtColors.Text = string.Join("", c1Split[0], c1Split[3], c1Split[2], c1Split[5], c1Split[1], c1Split[4]);

            txtMoves.Text = string.Join(" ", twists.Select(x => x.Name));



            btnGo_Click(sender, e);
        }
Esempio n. 16
0
        public void PeriodicUpdate(ColorCube cube)
        {
            Color color = Color.Transparent;

            if (cube != null)
            {
                color = cube.colors[_index];
            }

            if (Clickable && ClientRectangle.Contains(PointToClient(Cursor.Position)))
            {
                Cursor    = Cursors.Hand;
                BackColor = ControlPaint.Dark(color, 0.02f);
            }
            else
            {
                Cursor    = Cursors.Default;
                BackColor = color;
            }
        }
        public void RefreshCube(ColorCube cube)
        {
            var faces = cube?.FaceColors;

            var sb = new StringBuilder();

            sb.Append("reloadWithColors([");

            for (int i = 0; i < 6; i++)
            {
                sb.Append("[");
                for (int j = 0; j < 16; j++)
                {
                    sb.Append(faces == null ? 7 : (int)faces[i * 16 + j] + 1);
                    sb.Append(",");
                }
                sb.Append("],");
            }
            sb.Append("])");

            ExecuteJS(sb.ToString());
        }
Esempio n. 18
0
        private void InitializeCornerCube(ColorCube cube)
        {
            Color topColor   = Color.Gray;
            Color leftColor  = Color.Gray;
            Color rightColor = Color.Gray;

            if ((object)cube != null)
            {
                topColor   = cube.colors[47];
                leftColor  = cube.colors[83];
                rightColor = cube.colors[60];
            }

            var img = (Bitmap)Properties.Resources.FixedCornerColor.Clone();

            for (int x = 0; x < img.Size.Width; x++)
            {
                for (int y = 0; y < img.Size.Height; y++)
                {
                    var pixelColor = img.GetPixel(x, y);

                    if (pixelColor.R == 0 && pixelColor.G == 0 && pixelColor.B == 255)
                    {
                        img.SetPixel(x, y, rightColor);
                    }
                    if (pixelColor.R == 0 && pixelColor.G == 255 && pixelColor.B == 0)
                    {
                        img.SetPixel(x, y, topColor);
                    }
                    if (pixelColor.R == 255 && pixelColor.G == 0 && pixelColor.B == 0)
                    {
                        img.SetPixel(x, y, leftColor);
                    }
                }
            }

            cornerPicture.Image = img;
        }
Esempio n. 19
0
        public SimpleLiteMain(Form i_form, CaptureDevice i_dev)
        {
            //setup camera
            i_dev.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f);

            //setup form
            i_form.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);

            //setup AR
            INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT);

            this._ms = new NyARD3dMarkerSystem(cf);
            this._ss = new NyARDirectShowCamera(i_dev);
            this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80);

            //setup directx

            //3dデバイスを準備する
            this._d3d = NyARD3dUtil.createD3dDevice(i_form);
            this._d3d.RenderState.ZBufferEnable = true;
            this._d3d.RenderState.Lighting      = false;
            //ビューポートとビューの位置
            this._d3d.Transform.View = NyARD3dUtil.getARView();
            this._d3d.Viewport       = NyARD3dUtil.getARViewPort(SCREEN_WIDTH, SCREEN_HEIGHT);
            //Projectionの設定
            this._ms.setProjectionMatrixClipping(10, 10000);
            Matrix pm = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(this._ms.getARParam(), 10, 10000, ref pm);
            this._d3d.Transform.Projection = pm;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._d3d, 40);

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._d3d, SCREEN_WIDTH, SCREEN_HEIGHT);
        }
Esempio n. 20
0
        public Test_NyARRealityD3d_ARMarker(Form1 topLevelForm, ResourceBuilder i_resource)
        {
            this._capture = i_resource.createWmCapture();
            this._capture.setOnSample(this);

            this._d3dmgr      = i_resource.createD3dManager(topLevelForm);
            this._back_ground = i_resource.createBackGround(this._d3dmgr);
            this._d3dcube     = new ColorCube(this._d3dmgr.d3d_device, 40);


            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this.m_raster = i_resource.createARRaster();
            //AR用のパターンコードを読み出


            //マーカライブラリ(ARTKId)の構築
            this._mklib = new ARTKMarkerTable(10, 16, 16, 25, 25, 4);
            //マーカテーブルの作成(1種類)
            this._mklib.addMarker(i_resource.createNyARCode(), 0, "HIRO", 80, 80);

            //Realityの準備
            this._reality        = new NyARRealityD3d(i_resource.ar_param, 10, 10000, 1, 5);
            this._reality_source = new NyARRealitySource_WMCapture(SCREEN_WIDTH, SCREEN_HEIGHT, null, 2, 100);
        }
Esempio n. 21
0
 public void SetColor(int col)
 {
     colorLayer = NewColor(col);
 }
Esempio n. 22
0
        public bool InitializeApplication(Form1 topLevelForm)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            this._raster            = new NyARBitmapRaster(new Bitmap(TEST_IMAGE));


            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し
            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            //1パターンのみを追跡するクラスを作成
            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);

            //計算モードの設定
            this._ar.setContinueMode(true);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;


            //カメラProjectionの設定
            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap, 10, 1000, ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();

            vp.X      = 0;
            vp.Y      = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width  = ap.getScreenSize().w;
            vp.MaxZ   = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;
            //マーカの認識
            bool is_marker_enable = this._ar.detectMarkerLite(this._raster, 110);

            if (is_marker_enable)
            {
                //あればMatrixを計算
                this._ar.getTransmationMatrix(nyar_transmat);
                NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat);
            }
            this._is_marker_enable = is_marker_enable;
            //サーフェイスへ背景をコピー
            this._surface.setRaster(this._raster);
            return(true);
        }
Esempio n. 23
0
        public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //ARの設定

            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.loadFromARParamFile(File.OpenRead(AR_CAMERA_FILE), SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し
            NyARCode code = NyARCode.loadFromARPattFile(File.OpenRead(AR_CODE_FILE), 16, 16);

            //1パターンのみを追跡するクラスを作成
            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);

            //計算モードの設定
            this._ar.setContinueMode(true);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;


            //カメラProjectionの設定
            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();

            vp.X      = 0;
            vp.Y      = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width  = ap.getScreenSize().w;
            vp.MaxZ   = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);


            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            this._is_marker_enable = false;
            return(true);
        }
 public InitializeIHMInstruction(ColorCube cube)
 {
     this.Cube = cube;
 }
Esempio n. 25
0
        public NyARWordsBingoCore(Label lbl, Game currentGame, PictureBox pbx)
        {
            //Instanciando o PictureBox com o recebido do Form
            pbxNyAR = pbx;
            lbNyAR  = lbl;
            gmNyAR  = currentGame;


            //Parâmetros da RA
            NyARParam ap = new NyARParam();

            ap.loadARParamFromFile(AR_CAMERA_FILE);   //Lendo arquivo .dat
            ap.changeScreenSize(640, 480);            //Setando tamanho da câmera.

            //Lendo padrão do marcador
            NyARCode codeKanji = new NyARCode(16, 16);
            NyARCode codeA     = new NyARCode(16, 16);
            NyARCode codeB     = new NyARCode(16, 16);
            NyARCode codeC     = new NyARCode(16, 16);
            NyARCode codeD     = new NyARCode(16, 16);
            NyARCode codeE     = new NyARCode(16, 16);
            NyARCode codeF     = new NyARCode(16, 16);
            NyARCode codeG     = new NyARCode(16, 16);
            NyARCode codeH     = new NyARCode(16, 16);
            NyARCode codeI     = new NyARCode(16, 16);
            NyARCode codeJ     = new NyARCode(16, 16);
            NyARCode codeK     = new NyARCode(16, 16);
            NyARCode codeL     = new NyARCode(16, 16);
            NyARCode codeM     = new NyARCode(16, 16);
            NyARCode codeN     = new NyARCode(16, 16);
            NyARCode codeO     = new NyARCode(16, 16);
            NyARCode codeP     = new NyARCode(16, 16);
            NyARCode codeQ     = new NyARCode(16, 16);
            NyARCode codeR     = new NyARCode(16, 16);
            NyARCode codeS     = new NyARCode(16, 16);
            NyARCode codeT     = new NyARCode(16, 16);
            NyARCode codeU     = new NyARCode(16, 16);
            NyARCode codeV     = new NyARCode(16, 16);
            NyARCode codeW     = new NyARCode(16, 16);
            NyARCode codeX     = new NyARCode(16, 16);
            NyARCode codeY     = new NyARCode(16, 16);
            NyARCode codeZ     = new NyARCode(16, 16);

            NyARCode codeBall      = new NyARCode(16, 16);
            NyARCode codeSword     = new NyARCode(16, 16);
            NyARCode codeCar       = new NyARCode(16, 16);
            NyARCode codeBrigadier = new NyARCode(16, 16);
            NyARCode codeFork      = new NyARCode(16, 16);
            NyARCode codePen       = new NyARCode(16, 16);
            NyARCode codeFish      = new NyARCode(16, 16);


            //Carregando os arquivos dos marcadores no NyARCode
            codeKanji.loadARPattFromFile(AR_CODE_FILE_KANJI);
            codeA.loadARPattFromFile(AR_CODE_FILE_A);
            codeB.loadARPattFromFile(AR_CODE_FILE_B);
            codeC.loadARPattFromFile(AR_CODE_FILE_C);
            codeD.loadARPattFromFile(AR_CODE_FILE_D);
            codeE.loadARPattFromFile(AR_CODE_FILE_E);
            codeF.loadARPattFromFile(AR_CODE_FILE_F);
            codeG.loadARPattFromFile(AR_CODE_FILE_G);
            codeH.loadARPattFromFile(AR_CODE_FILE_H);
            codeI.loadARPattFromFile(AR_CODE_FILE_I);
            codeJ.loadARPattFromFile(AR_CODE_FILE_J);
            codeK.loadARPattFromFile(AR_CODE_FILE_K);
            codeL.loadARPattFromFile(AR_CODE_FILE_L);
            codeM.loadARPattFromFile(AR_CODE_FILE_M);
            codeN.loadARPattFromFile(AR_CODE_FILE_N);
            codeO.loadARPattFromFile(AR_CODE_FILE_O);
            codeP.loadARPattFromFile(AR_CODE_FILE_P);
            codeQ.loadARPattFromFile(AR_CODE_FILE_Q);
            codeR.loadARPattFromFile(AR_CODE_FILE_R);
            codeS.loadARPattFromFile(AR_CODE_FILE_S);
            codeT.loadARPattFromFile(AR_CODE_FILE_T);
            codeU.loadARPattFromFile(AR_CODE_FILE_U);
            codeV.loadARPattFromFile(AR_CODE_FILE_V);
            codeW.loadARPattFromFile(AR_CODE_FILE_W);
            codeX.loadARPattFromFile(AR_CODE_FILE_X);
            codeY.loadARPattFromFile(AR_CODE_FILE_Y);
            codeZ.loadARPattFromFile(AR_CODE_FILE_Z);

            codeBall.loadARPattFromFile(AR_CODE_FILE_BALL);
            codeSword.loadARPattFromFile(AR_CODE_FILE_SWORD);
            codeCar.loadARPattFromFile(AR_CODE_FILE_CAR);
            codeBrigadier.loadARPattFromFile(AR_CODE_FILE_BRIGADIER);
            codeFork.loadARPattFromFile(AR_CODE_FILE_FORK);
            codePen.loadARPattFromFile(AR_CODE_FILE_PEN);
            codeFish.loadARPattFromFile(AR_CODE_FILE_FISH);



            double[] WidthArray = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0,
                                    80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0,
                                    80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 };

            NyARCode[] arrayCodes = { codeKanji, codeA, codeB, codeC, codeD, codeE, codeF, codeG, codeH, codeI,
                                      codeJ,     codeK, codeL, codeM, codeN, codeO, codeP, codeQ, codeR, codeS,
                                      codeT,     codeU, codeV, codeW, codeX, codeY, codeZ };

            double[]   WidthArrayImages = { 80.0, 80.0, 80.0, 80.0, 80.0, 80.0, 80.0 };
            NyARCode[] arrayCodesImage  = { codeBall, codeSword, codeCar, codeBrigadier, codeFork, codePen, codeFish };


            //Seta propriedades da câmera
            try
            {
                Core.cap.SetCaptureListener(this);
            }
            catch (Exception e)
            {
                MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente. Favor, reinicie a aplicação.", "Erro!");
                Environment.Exit(0);
            }

            Core.cap.PrepareCapture(640, 480, 30);


            //Create a cluster - Instanciando o Raster, passando os parâmetros do vídeo encontrado no CaptureDevice
            Core.raster = Core.InstanceRaster(Core.cap.video_width, Core.cap.video_height);


            //Instanciando os detectores únicos
            this.ballMarkerDetector = new NyARSingleDetectMarker(ap, codeBall, 80.0, Core.raster.getBufferType());
            this.ballMarkerDetector.setContinueMode(true);

            this.brigadierlMarkerDetector = new NyARSingleDetectMarker(ap, codeBrigadier, 80.0, Core.raster.getBufferType());
            this.brigadierlMarkerDetector.setContinueMode(true);

            this.carMarkerDetector = new NyARSingleDetectMarker(ap, codeCar, 80.0, Core.raster.getBufferType());
            this.carMarkerDetector.setContinueMode(true);

            this.forkMarkerDetector = new NyARSingleDetectMarker(ap, codeFork, 80.0, Core.raster.getBufferType());
            this.forkMarkerDetector.setContinueMode(true);

            this.penMarkerDetector = new NyARSingleDetectMarker(ap, codePen, 80.0, Core.raster.getBufferType());
            this.penMarkerDetector.setContinueMode(true);

            this.swordMarkerDetector = new NyARSingleDetectMarker(ap, codeSword, 80.0, Core.raster.getBufferType());
            this.swordMarkerDetector.setContinueMode(true);

            this.fishMarkerDetector = new NyARSingleDetectMarker(ap, codeFish, 80.0, Core.raster.getBufferType());
            this.fishMarkerDetector.setContinueMode(true);



            //Instanciando o detector de todas as letras
            this.markerDetectorLetters = new NyARDetectMarker(ap, arrayCodes, WidthArray, 27, Core.raster.getBufferType());
            this.markerDetectorLetters.setContinueMode(true);

            //Instanciando o detector das imagens que representam a palavra na cartela
            this.markerDetectorImages = new NyARDetectMarker(ap, arrayCodesImage, WidthArrayImages, 7, Core.raster.getBufferType());
            this.markerDetectorImages.setContinueMode(true);


            //Inicia a captura
            //Inicia a captura
            try
            {
                Core.cap.StartCapture();
            }
            catch (Exception e)
            {
                MessageBox.Show("Ocorreu um erro no estabelecimento da conexão com a câmera. Verifique se ela está instalada corretamente.");
                Environment.Exit(0);
            }


            //Abaixo, são as funções que preparam todo o dispositivo e cenário para renderização 3D
            //Necessário descobrir mais detalhes do funcionamento.

            //Preparing the 3D device
            this._device = Core.PrepareD3dDevice(pbx); //Prepara o dispositivo em cima do PictureBox
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;

            //Projection Camera Settings
            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);
            this._device.Transform.Projection = tmp;

            // View conversion settings (set in the left-handed view matrix).
            //From 0,0,0, and facing Z +, Y-axis direction on
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();

            vp.X      = 0;
            vp.Y      = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width  = ap.getScreenSize().w;
            vp.MaxZ   = 1.0f;
            //Set viewport
            this._device.Viewport = vp;

            //Draw a color cube instance - Instância de um cubo colorido, padrão da biblioteca NyAR
            this._cube = new ColorCube(this._device, 40);

            //Create a background surface
            this._surface = new NyARSurface_XRGB32(this._device, 640, 480);

            //Carregando os meshs (objetos 3D)
            LoadMeshes();
        }
Esempio n. 26
0
        public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);

            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;



            //this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32);

            #region my code
            try
            {
                byte[] bimg = service.getb();
                //if(bimg != null)
                {
                    Image img = byteToImage(bimg);
                    if (img != null)
                    {
                        //frm.textBox1.Text = img.ToString();
                        this._raster = new NyARBitmapRaster((Bitmap)img);
                    }
                }
                //else
            }
            catch (Exception x)
            {
                //MessageBox.Show(x.ToString());
            }
            #endregion


            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);


            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE), 16, 16);


            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);


            this._ar.setContinueMode(true);


            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting      = false;



            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);
            this._device.Transform.Projection = tmp;


            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();
            vp.X      = 0;
            vp.Y      = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width  = ap.getScreenSize().w;
            vp.MaxZ   = 1.0f;

            this._device.Viewport = vp;


            this._cube = new ColorCube(this._device, 40);



            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            this._is_marker_enable = false;
            return(true);
        }