Exemple #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //CubeForm cubefrm = new CubeForm();

            using (CubeForm cubefrm = new CubeForm())
                //CubePuzz cubepuzz = new CubePuzz();

                using (CubePuzz cubepuzz = new CubePuzz())
                {
                    if (cubepuzz.InitializeApplication(cubefrm))
                    {
                        cubefrm.Show();

                        while (cubefrm.Created)
                        {
                            cubepuzz.MainLoop();
                            Thread.Sleep(1);
                            Application.DoEvents();
                        }
                    }
                    else
                    {
                    }
                }
        }
Exemple #2
0
        private void CreateDevice(CubeForm topLevelForm, PresentParameters presentationParameters)
        {
            try
            {
                this._device = new Device
                               (
                    0,
                    DeviceType.Hardware,
                    topLevelForm.Handle,
                    CreateFlags.HardwareVertexProcessing,
                    presentationParameters
                               );
            }
            catch (DirectXException ex1)
            {
                Debug.WriteLine(ex1.ToString());

                try
                {
                    this._device = new Device
                                   (
                        0,
                        DeviceType.
                        Hardware,
                        topLevelForm.Handle,
                        CreateFlags.SoftwareVertexProcessing,
                        presentationParameters
                                   );
                }
                catch (DirectXException ex2)
                {
                    Debug.WriteLine(ex2.ToString());

                    try
                    {
                        this._device = new Device
                                       (
                            0,
                            DeviceType.Reference,
                            topLevelForm.Handle,
                            CreateFlags.SoftwareVertexProcessing,
                            presentationParameters
                                       );
                    }
                    catch (DirectXException ex3)
                    {
                        throw ex3;
                    }
                }
            }
        }
Exemple #3
0
        private void CreateDevice(CubeForm topLevelForm)
        {
            PresentParameters pp = new PresentParameters();

            pp.BackBufferFormat       = Format.Unknown;
            pp.Windowed               = true;
            pp.SwapEffect             = SwapEffect.Discard;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.D16;
            pp.PresentationInterval   = PresentInterval.Immediate;

            try
            {
                this.CreateDevice(topLevelForm, pp);
            }
            catch (DirectXException ex)
            {
                throw ex;
            }
        }
Exemple #4
0
        public bool InitializeApplication(CubeForm topLevelForm)
        {
            this._form = topLevelForm;
            this.CreateInputEvent(topLevelForm);

            try
            {
                this.CreateDevice(topLevelForm);
                this.CreateFont();
            }
            catch (DirectXException ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            this.SettingCamera();

            // front-top
            CreateCube(this._device, "cube020", new Vector3(-3.1f, 3.1f, -1.1f), new Vector3(-1.1f, 1.1f, -3.1f));
            CreateCube(this._device, "cube120", new Vector3(-1.0f, 3.1f, -1.1f), new Vector3(1.0f, 1.1f, -3.1f));
            CreateCube(this._device, "cube220", new Vector3(1.1f, 3.1f, -1.1f), new Vector3(3.1f, 1.1f, -3.1f));
            // front-middle                  "
            CreateCube(this._device, "cube010", new Vector3(-3.1f, 1.0f, -1.1f), new Vector3(-1.1f, -1.0f, -3.1f));
            CreateCube(this._device, "cube110", new Vector3(-1.0f, 1.0f, -1.1f), new Vector3(1.0f, -1.0f, -3.1f));
            CreateCube(this._device, "cube210", new Vector3(1.1f, 1.0f, -1.1f), new Vector3(3.1f, -1.0f, -3.1f));
            // front-low                     "
            CreateCube(this._device, "cube000", new Vector3(-3.1f, -1.1f, -1.1f), new Vector3(-1.1f, -3.1f, -3.1f));
            CreateCube(this._device, "cube100", new Vector3(-1.0f, -1.1f, -1.1f), new Vector3(1.0f, -3.1f, -3.1f));
            CreateCube(this._device, "cube200", new Vector3(1.1f, -1.1f, -1.1f), new Vector3(3.1f, -3.1f, -3.1f));
            // midldle-top                   "
            CreateCube(this._device, "cube021", new Vector3(-3.1f, 3.1f, 1.0f), new Vector3(-1.1f, 1.1f, -1.0f));
            CreateCube(this._device, "cube121", new Vector3(-1.0f, 3.1f, 1.0f), new Vector3(1.0f, 1.1f, -1.0f));
            CreateCube(this._device, "cube221", new Vector3(1.1f, 3.1f, 1.0f), new Vector3(3.1f, 1.1f, -1.0f));
            // middle-middle                 "
            CreateCube(this._device, "cube011", new Vector3(-3.1f, 1.0f, 1.0f), new Vector3(-1.1f, -1.0f, -1.0f));
            CreateCube(this._device, "cube111", new Vector3(-1.0f, 1.0f, 1.0f), new Vector3(1.0f, -1.0f, -1.0f));
            CreateCube(this._device, "cube211", new Vector3(1.1f, 1.0f, 1.0f), new Vector3(3.1f, -1.0f, -1.0f));
            // middle-low                    "
            CreateCube(this._device, "cube001", new Vector3(-3.1f, -1.1f, 1.0f), new Vector3(-1.1f, -3.1f, -1.0f));
            CreateCube(this._device, "cube101", new Vector3(-1.0f, -1.1f, 1.0f), new Vector3(1.0f, -3.1f, -1.0f));
            CreateCube(this._device, "cube201", new Vector3(1.1f, -1.1f, 1.0f), new Vector3(3.1f, -3.1f, -1.0f));
            // low-top                       "
            CreateCube(this._device, "cube002", new Vector3(-3.1f, -1.1f, 3.1f), new Vector3(-1.1f, -3.1f, 1.1f));
            CreateCube(this._device, "cube102", new Vector3(-1.0f, -1.1f, 3.1f), new Vector3(1.0f, -3.1f, 1.1f));
            CreateCube(this._device, "cube202", new Vector3(1.1f, -1.1f, 3.1f), new Vector3(3.1f, -3.1f, 1.1f));
            // low-middle                    "
            CreateCube(this._device, "cube012", new Vector3(-3.1f, 1.0f, 3.1f), new Vector3(-1.1f, -1.0f, 1.1f));
            CreateCube(this._device, "cube112", new Vector3(-1.0f, 1.0f, 3.1f), new Vector3(1.0f, -1.0f, 1.1f));
            CreateCube(this._device, "cube212", new Vector3(1.1f, 1.0f, 3.1f), new Vector3(3.1f, -1.0f, 1.1f));
            // low-low                       "
            CreateCube(this._device, "cube022", new Vector3(-3.1f, 3.1f, 3.1f), new Vector3(-1.1f, 1.1f, 1.1f));
            CreateCube(this._device, "cube122", new Vector3(-1.0f, 3.1f, 3.1f), new Vector3(1.0f, 1.1f, 1.1f));
            CreateCube(this._device, "cube222", new Vector3(1.1f, 3.1f, 3.1f), new Vector3(3.1f, 1.1f, 1.1f));

            this._device.RenderState.Lighting = false;

            unchecked
            {
                this._background = TextureLoader.FromFile(_device, "background.bmp", 640, 480, 1, Usage.None, Format.A8R8G8B8, Pool.Managed, Filter.None, Filter.None, (int)0xFF000000);
            }

            sprite = new Sprite(_device);

            return(true);
        }