Beispiel #1
0
        protected override void Draw()
        {
            // Ensure transforms are updated and clear; otherwise leave to Model3D tree
            GraphicsDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(1.0f, 1.0f, 1.0f, 1.0f), 1.0f, 0);
            GraphicsDevice.BeginScene();
            float aspect = (float)GraphicsDevice.Viewport.Width / (float)GraphicsDevice.Viewport.Height;

            switch (this.ViewPort3D.ProjectionType)
            {
            case ProjectionType.Perspective:
                projection = Matrix.PerspectiveFovRH(fov, aspect, 0.01f, 10000f);
                break;

            case ProjectionType.Orthogonal:
                float width  = (float)this.Models.Select(m => m.Bounds.Maximum.X).Max() * aspect;
                float height = (float)this.Models.Select(m => m.Bounds.Maximum.Y).Max();
                projection = Matrix.OrthoRH(width / this.Scale, height / this.Scale, 1, 100);
                break;
            }

            view  = Matrix.LookAtRH(CameraPosition, CameraTarget, CameraUpVector);
            world = Matrix.Identity;
            // ENDTODO
            GraphicsDevice.SetTransform(TransformState.Projection, ref projection);
            GraphicsDevice.SetTransform(TransformState.View, ref view);
            GraphicsDevice.SetTransform(TransformState.World, ref world);

            foreach (Model3D model in this.Models)
            {
                model.Draw();
            }
            GraphicsDevice.EndScene();
            GraphicsDevice.Present();
        }