public void OnCreateDevice(object sender, EventArgs e)
        {
            Device dev = (Device)sender;
            textSprite = new Sprite(dev);
            statsFont = ResourceCache.GetGlobalInstance().CreateFont(dev, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch, "Arial");

            //init cursors
            mouseCursor = new CrosshairCursor(dev, 0x00ff00, .04f);
            wiiCursor1 = new CrosshairCursor(dev, 0x00ff00, .04f);
            wiiCursor2 = new CrosshairCursor(dev, 0x0000ff, .04f);
            wiiCursor3 = new CrosshairCursor(dev, 0xff0000, .04f);
            wiiCursor4 = new CrosshairCursor(dev, 0xffff00, .04f);

            CreateGridGeometry(dev);
            CreateBackgroundGeometry(dev);
            CreateTargetGeometry(dev);
            InitTargets();
            LoadTexture();
            LoadBackground();

            if (doWiimote)
            {
                try
                {
                    if (doWiimote2)
                    {
                        showMouseCursor = true;
                        remote2 = new Wiimote();
                        remote2.Connect();
                        remote2.SetReportType(Wiimote.InputReport.IRAccel, true);
                        remote2.GetBatteryLevel();
                        remote2.SetLEDs(true, true, false, false);
                        remote2.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged2);
                    }
                    remote = new Wiimote();
                    remote.Connect();
                    remote.SetReportType(Wiimote.InputReport.IRAccel, true);
                    remote.GetBatteryLevel();
                    remote.SetLEDs(true, false, false, false);
                    remote.OnWiimoteChanged += new WiimoteChangedEventHandler(wm_OnWiimoteChanged);

                }
                catch (Exception x)
                {
                    MessageBox.Show("Cannot find a wii remote: " + x.Message);
                    doWiimote = false;
                }

            }
        }
Beispiel #2
0
        /// <summary>
        /// Renders the current scene in a single viewport
        /// </summary>
        /// <param name="renderSurface">The view that is to be rendered too</param>
        public void RenderSingleView(IRenderSurface renderSurface)
        {
            // make sure the device is initialised and that the view is initialised
            if((device != null) && (renderSurface.SwapChain != null) && (!renderSurface.SwapChain.Disposed))
            {

                // get the backbuffer of the surface that is to be rendered to
                Surface surface =  renderSurface.SwapChain.GetBackBuffer(0,BackBufferType.Mono);

                // set the device so it renders to the back buffer
                device.SetRenderTarget(0,surface);

                surface.ReleaseGraphics();

                device.DepthStencilSurface = renderSurface.DepthStencil;

                // get the camera that current render surface is using
                MidgetCameras.MidgetCamera camera = renderSurface.Camera;

                // adjust the device camera
                device.Transform.View = camera.ViewMatrix;
                device.Transform.Projection = camera.ProjectionMatrix;

                //device.PresentationParameters.DeviceWindow.

                // clear the backbuffer
                device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0);

                // setup the render quality for the viewport
                SetupDrawMode(renderSurface.DrawMode);

                // start drawing the scene
                device.BeginScene();

                // render the scene
                //device.Transform.World = Matrix.Identity;
                SceneManager.Instance.Scene.Render(device, Matrix.Identity, SceneManager.Instance.CurrentFrameIndex);

                // display viewport description text
                Microsoft.DirectX.Direct3D.Font viewportD3DFont
                    = new Microsoft.DirectX.Direct3D.Font(device, new System.Drawing.Font("Arial", 12, FontStyle.Bold));
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(4, 4, 100, 30),
                    DrawTextFormat.Left, Color.Black);
                // TODO: FIX: D3DFont line causes NullReferenceExceptions to be thrown sometimes
                viewportD3DFont.DrawText(renderSurface.Description, new Rectangle(5, 5, 100, 30),
                    DrawTextFormat.Left, Color.White);
                viewportD3DFont.Dispose();

                // end the scene and display it
                device.EndScene();
                renderSurface.SwapChain.Present();
            }
        }