Exemplo n.º 1
0
        private void ResetScene(bool loadContent)
        {
            switch (currentScene)
            {
                case SceneType.Cube:
                    this.scene = new SingleCubeScene(this.graphics.GraphicsDevice, rotationOrigin, 20);
                    break;
                case SceneType.ArrowField:
                    this.scene = new ArrowFieldScene(this.graphics.GraphicsDevice, rotationOrigin);
                    break;
                default:
                    throw new Exception(string.Format("Unsupported scene type {0}", currentScene));
            }

            //Create camera
            var cameraPosition = scene.RecommandedSettings.CameraPosition;
            var cameraUp = Vector3.Normalize((rotationOrigin - cameraPosition).SafeCross(Vector3.Right, Vector3.Up));
            camera = new Camera(graphics.GraphicsDevice, "MainCamera", cameraPosition, rotationOrigin, cameraUp, graphics.GraphicsDevice.Viewport.AspectRatio, 0.05f, 1E+5f);

            //Create help/debug text
            var screenText = new ScreenText(graphics.GraphicsDevice, "MainScreenText", new Vector3(1.0f, 1.0f, 0), camera);
            screenText.AdditionalHelpText = "D -> Next Debug Level\nS -> Cycle through scenes";

            //Create controls
            cameraControls = new ArcBallControls(camera, rotationOrigin, scene.RecommandedSettings.ArcBallOriginLocked, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

            this.scene.AddObject(camera);
            this.scene.AddObject(screenText);

            if (loadContent)
                this.scene.LoadContent(this.Content);
        }
Exemplo n.º 2
0
 private void ResetCamera()
 {
     if (camera == null || camera.Position != cameraStartingPos)
         camera = new Camera(cameraStartingPos, Vector3.Zero, GraphicsDevice.Viewport.AspectRatio, float.Epsilon, float.MaxValue);
 }
Exemplo n.º 3
0
        public void DrawDebugPoints(Scene scene, Camera camera, Matrix world, Matrix view, Matrix projection, float viewPortWidth, float viewPortHeight)
        {
            this.Height = (int)(viewPortHeight * 1.2);
            this.Width = (int) (viewPortWidth * 1.2);

            graphicsContext.Clear(Color.CornflowerBlue);

            var writeToCaptureFile = captureStreamWriter != null && UpdateLastCameraVectors(camera);

            StringBuilder line = null;
            if (writeToCaptureFile)
            {
                line = new StringBuilder();
                line.Append(camera.Position.X);
                line.Append("\t");
                line.Append(camera.Position.Y);
                line.Append("\t");
                line.Append(camera.Position.Z);
                line.Append("\t");
                line.Append(camera.Up.X);
                line.Append("\t");
                line.Append(camera.Up.Y);
                line.Append("\t");
                line.Append(camera.Up.Z);
                line.Append("\t");
                line.Append(camera.Forward.X);
                line.Append("\t");
                line.Append(camera.Forward.Y);
                line.Append("\t");
                line.Append(camera.Forward.Z);
            }

            foreach (var object3D in scene.Objects)
            {
                foreach (var debugVertex in object3D.GetDebugVertices())
                {
                    Matrix matrix = Matrix.Multiply(Matrix.Multiply(world, view), projection);
                    Vector3 vector = Vector3.Transform(debugVertex.Position, matrix);
                    float a = (((debugVertex.Position.X * matrix.M14) + (debugVertex.Position.Y * matrix.M24)) + (debugVertex.Position.Z * matrix.M34)) + matrix.M44;
                    if (!XnaExtentions.WithinEpsilon(a, 1f))
                        vector = (Vector3)(vector / a);

                    var x = (((vector.X + 1f)*0.5f)*this.Width);
                    var y = (((-vector.Y + 1f)*0.5f)*this.Height);

                    //var vertexColor = debugVertex.Color.ToSystemDrawingColor();
                    //if (vertexColor == Color.CornflowerBlue)
                    var    vertexColor = Color.Red;

                    graphicsContext.FillEllipse(new SolidBrush(vertexColor), new RectangleF(x, y, 8, 8));

                    if (writeToCaptureFile)
                    {
                        line.Append("\t");
                        line.Append(x);
                        line.Append("\t");
                        line.Append(y);
                    }
                }
            }

            if (writeToCaptureFile)
            {
                captureStreamWriter.WriteLine(line);
            }
        }
Exemplo n.º 4
0
 public ScreenText(GraphicsDevice graphicsDevice, string name, Vector3 position, Camera camera)
     : base(graphicsDevice, name, position, Vector3.Zero, Vector3.Up)
 {
     this.Camera = camera;
     lastDebugLevel = null;
 }
Exemplo n.º 5
0
        private bool UpdateLastCameraVectors(Camera camera)
        {
            if (camera.Position != lastPosition || camera.Up != lastUp || camera.Forward != lastForward)
            {
                lastPosition = camera.Position;
                lastUp = camera.Up;
                lastForward = camera.Forward;

                return true;
            }

            return false;
        }