Пример #1
0
        /// <summary>
        /// Invoked after either control has created its graphics device.
        /// </summary>
        private void loadContent(object sender, GraphicsDeviceEventArgs e)
        {
            // Because this same event is hooked for both controls, we check if the Stopwatch
            // is running to avoid loading our content twice.
            if (!totalTime.IsRunning)
            {

                ServiceContainer = new ServiceContainer();
                contentBuilder = new ContentBuilder();
                ResourceBuilder.Instance.ContentBuilder = contentBuilder;

                resourceContent.Activate();

                errors = new List<Error>();
                outputTextBlock = output;
                EditorStatus = EditorStatus.STARTING;
                EditMode = AridiaEditor.EditMode.STANDARD;
                errorDataGrid.ItemsSource = errors;
                Output.AddToOutput("WELCOME TO ARIDIA WORLD EDITOR ------------");

                GameApplication.Instance.SetGraphicsDevice(e.GraphicsDevice);
                MouseDevice.Instance.ResetMouseAfterUpdate = false;
                ServiceContainer.AddService<IGraphicsDeviceService>(GraphicsDeviceService.AddRef(new IntPtr(), 100, 100));
                ResourceManager.Instance.Content = new ContentManager(ServiceContainer, contentBuilder.OutputDirectory);
                ResourceManager.Instance.Content.Unload();

                sceneGraph = new SceneGraphManager();
                sceneGraph.CullingActive = true;
                sceneGraph.LightingActive = false; //deactivate lighting on beginning!

                spriteBatch = new SpriteBatch(e.GraphicsDevice);
                grid = new GridComponent(e.GraphicsDevice, 2);

                e.GraphicsDevice.RasterizerState = RasterizerState.CullNone;

                var versionAttribute = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                AssemblyBuild.Content = "Build: (Alpha) " + versionAttribute;
                if (File.Exists(Settings.Default.LayoutFile))
                    dockManager.RestoreLayout(Settings.Default.LayoutFile);

                // after we initialized everything we need start loading the content
                // in a new thread!
                StartContentBuilding();

                // Start the watch now that we're going to be starting our draw loop
                totalTime.Start();
            }
        }
Пример #2
0
        /// <summary>
        /// Invoked when our second control is ready to render.
        /// </summary>
        private void xnaControl_RenderXna(object sender, GraphicsDeviceEventArgs e)
        {
            if (totalTime != null)
            {
                UpdateGameTime();

                sceneGraph.Update(gameTime);

                if (gizmo != null)
                {
                    if (CameraManager.Instance.CurrentCamera != null)
                    {
                        Camera currentCamera = CameraManager.Instance.GetCurrentCamera();

                        MouseState stateMouse = Mouse.GetState();
                        KeyboardState stateKeyboard = Keyboard.GetState();

                        // update camera properties for rendering and ray-casting.
                        gizmo.UpdateCameraProperties(currentCamera.View, currentCamera.Projection, currentCamera.Position);

                        // select entities with your cursor (add the desired keys for add-to / remove-from -selection)
                        if (stateMouse.LeftButton == ButtonState.Pressed && _previousMouse.LeftButton == ButtonState.Released)
                            gizmo.SelectEntities(new Vector2(stateMouse.X, stateMouse.Y),
                                  stateKeyboard.IsKeyDown(Keys.LeftControl) || stateKeyboard.IsKeyDown(Keys.RightControl),
                                  stateKeyboard.IsKeyDown(Keys.LeftAlt) || stateKeyboard.IsKeyDown(Keys.RightAlt));

                        System.Windows.Point relativePoint = renderControlWindow.TransformToAncestor(this).Transform(new System.Windows.Point(0, 0));

                        gizmo.Update(gameTime, (float)xnaControl.mouseState.Position.X, (float)xnaControl.mouseState.Position.Y);

                        _previousKeys = stateKeyboard;
                        _previousMouse = stateMouse;
                    }
                }

                KeyboardDevice.Instance.Update();
                MouseDevice.Instance.ResetMouseAfterUpdate = false;
                MouseDevice.Instance.Update();

                if (gizmo != null)
                {
                    if (KeyboardDevice.Instance.IsKeyDown(Keys.LeftShift))
                    {
                        gizmo.PrecisionModeEnabled = true;
                    }
                    else
                    {
                        gizmo.PrecisionModeEnabled = false;
                    }
                }

                if (CameraManager.Instance.CurrentCamera != null)
                    CameraPosition.Content = "Camera: " + CameraManager.Instance.GetCurrentCamera().Position;

                e.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.White);

                sceneGraph.Render();

                grid.Draw3D();

                if (gizmo != null)
                {
                    if (CameraManager.Instance.CurrentCamera != null)
                    {
                        gizmo.Draw();

                    }
                }
            }
        }
Пример #3
0
        private void clientSizeChanged(object sender, GraphicsDeviceEventArgs e)
        {
            if (CameraManager.Instance.CurrentCamera != null)
            {

                GameApplication.Instance.GetGraphics().PresentationParameters.BackBufferWidth = (int)xnaControl.ActualWidth;
                GameApplication.Instance.GetGraphics().PresentationParameters.BackBufferHeight = (int)xnaControl.ActualHeight;

                CameraManager.Instance.GetCurrentCamera().Projection = Microsoft.Xna.Framework.Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                            (float)xnaControl.ActualWidth /
                            (float)xnaControl.ActualHeight,
                            GameApplication.Instance.NearPlane, GameApplication.Instance.FarPlane
                        );
            }
        }