示例#1
0
        public void CanCreateFieldOfViewPerspectiveMatrix()
        {
            const float fieldOfView      = MathUtility.PI_OVER_2;
            Matrix3D    projectionMatrix = Matrix3D.CreatePerspectiveFieldOfView(fieldOfView, 1, 1, 200);

            Matrix otherProjectionMatrix = Matrix.PerspectiveFovRH(fieldOfView, 1, 1, 200);

            AssertMatricesAreEqual(otherProjectionMatrix, projectionMatrix);
        }
示例#2
0
        public void CanTransformPointWithPerspectiveProjection()
        {
            const float fieldOfView              = MathUtility.PI_OVER_2;
            Matrix3D    actualProjectionMatrix   = Matrix3D.CreatePerspectiveFieldOfView(fieldOfView, 1, 1, 200);
            Matrix      expectedProjectionMatrix = Matrix.PerspectiveFovRH(fieldOfView, 1, 1, 200);
            Point4D     actualPoint              = new Point4D(100, 100, -100, 1);
            Vector4     expectedPoint            = new Vector4(100, 100, -100, 1);

            Point4D actualTransformedPoint   = actualProjectionMatrix.Transform(actualPoint);
            Vector4 expectedTransformedPoint = Vector4.Transform(expectedPoint, expectedProjectionMatrix);

            AssertPointsAreEqual(expectedTransformedPoint, actualTransformedPoint);
        }
示例#3
0
        public Renderer(Device device, Model model, int width, int height, Transform3D cameraTransform)
        {
            _device          = device;
            _model           = model;
            _cameraTransform = cameraTransform;

            const float fov = MathUtility.PI_OVER_4;

            AxisAlignedBoundingBox bounds = _model.SourceScene.Bounds;
            Vector3D max    = bounds.Size;
            float    radius = System.Math.Max(max.X, System.Math.Max(max.Y, max.Z));

            _projection = Matrix3D.CreatePerspectiveFieldOfView(
                fov,
                width / (float)height,
                1.0f, radius * 10);

            float dist = radius / MathUtility.Sin(fov / 2);

            _view = Matrix3D.CreateLookAt(
                bounds.Center + Vector3D.Backward * dist,
                Vector3D.Forward,
                Vector3D.Up);
        }
示例#4
0
 public override Matrix3D GetProjectionMatrix(float aspectRatio)
 {
     return(Matrix3D.CreatePerspectiveFieldOfView(FieldOfView,
                                                  aspectRatio, NearPlaneDistance, FarPlaneDistance));
 }
示例#5
0
 public double[] GetProjectionMatrix(float aspectRatio)
 {
     return(Matrix3D.CreatePerspectiveFieldOfView(MathUtility.PI_OVER_4, aspectRatio, 0.1f, 1000000f).ToArray());
 }