Example #1
0
    public void TestLookAtFromWorldCenter() {
      Camera testCamera = new Camera(Matrix.Identity, Matrix.Identity);

      testCamera.LookAt(Vector3.UnitX); // Look to the right

      Vector3 leftPoint = -Vector3.UnitX;

      Vector3 transformed = Vector3.Transform(leftPoint, testCamera.View);

      // The point should be behind the camera
      Assert.Greater(transformed.Z, 0.0f);
    }
Example #2
0
    public void TestLookAtFromArbitraryPosition() {
      Camera testCamera = new Camera(Matrix.Identity, Matrix.Identity);

      testCamera.MoveTo(new Vector3(100.0f, 200.0f, 300.0f));
      testCamera.LookAt(Vector3.Zero); // Look to the right

      Vector3 leftPoint = new Vector3(99.0f, 200.0f, 300.0f);
      Vector3 behindPoint = new Vector3(100.0f, 200.0f, 299.0f);

      Vector3 transformedLeft = Vector3.Transform(leftPoint, testCamera.View);
      Vector3 transformedBehind = Vector3.Transform(behindPoint, testCamera.View);

      // The left point should be in front of the camera
      Assert.Less(transformedLeft.Z, 0.0f);
      // The behind point should be right of the camera
      Assert.Greater(transformedBehind.X, 0.0f);
    }
Example #3
0
    public void TestPositionRetrieval() {
      Camera testCamera = new Camera(
        Matrix.CreateLookAt(
          new Vector3(1.2f, 3.4f, 5.6f),
          Vector3.One,
          Vector3.Up
        ),
        Matrix.Identity
      );

      GeoAssertHelper.AreAlmostEqual(
        new Vector3(1.2f, 3.4f, 5.6f), testCamera.Position, 10
      );
    }
Example #4
0
    public void TestPositionChanging() {
      Camera testCamera = new Camera(Matrix.Identity, Matrix.Identity);

      testCamera.Position = new Vector3(6.5f, 4.3f, 2.1f);

      GeoAssertHelper.AreAlmostEqual(
        new Vector3(6.5f, 4.3f, 2.1f), testCamera.Position, 10
      );
    }
Example #5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            terrainBatch = new PrimitiveBatch<VertexPositionColor>(graphics.GraphicsDevice);

            //terrainDrawContext.BasicEffect.FogEnabled = true;
            //terrainDrawContext.BasicEffect.FogColor = new Color(20, 20, 20).ToVector3();
            //terrainDrawContext.BasicEffect.FogStart = 50;
            //terrainDrawContext.BasicEffect.FogEnd = 200;

            contentManager = new ContentManager(
                GraphicsDeviceServiceHelper.MakePrivateServiceProvider(graphics),
                Content.RootDirectory
            );

            debugDrawer = new DebugDrawer(graphics);

            // Displays a FPS counter
            Components.Add(new FpsComponent(graphics, Content.RootDirectory));

            // Create a new screen. Screens manage the state of a GUI and accept input
            // notifications. If you have an in-game computer display where you want
            // to use a GUI, you can create a second screen for that and thus cleanly
            // separate the state of the in-game computer from your game's own GUI :)
            Viewport viewport = GraphicsDevice.Viewport;
            Screen mainScreen = new Screen(viewport.Width, viewport.Height);
            gui.Screen = mainScreen;

            // Each screen has a 'desktop' control. This invisible control by default
            // stretches across the whole screen and serves as the root of the control
            // tree in which all visible controls are managed. All controls are positioned
            // using a system of fractional coordinates and pixel offset coordinates.
            // We now adjust the position of the desktop window to prevent GUI or HUD
            // elements from appearing outside of the title-safe area.
            mainScreen.Desktop.Bounds = new UniRectangle(
                new UniScalar(0.0f, 0.0f), new UniScalar(0.0f, 0.0f), // x and y = 10%
                new UniScalar(1.0f, 0.0f), new UniScalar(1.0f, 0.0f) // width and height = 80%
            );

            // Now let's do something funky: add buttons directly to the desktop.
            // This will also show the effect of the title-safe area.
            createDesktopControls(mainScreen);

            // Create a new camera with a perspective projection matrix
            camera = new Camera(
                Matrix.CreateLookAt(
                    new Vector3(0.0f, 0.0f, -100.0f), // camera location
                    new Vector3(0.0f, 0.0f, 0.0f), // camera focal point
                    Vector3.Up // up vector for the camera's orientation
                ),
                Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver4, // field of view
                    (float)Window.ClientBounds.Width / (float)Window.ClientBounds.Height, // aspect ratio
                    0.01f, 1000.0f // near and far clipping plane
                )
            );

            base.Initialize();
            //Initialized = true;
        }