public void SerializationXml() { var a = new PerspectiveViewVolume(1.23f, 2.13f, 1.01f, 10.345f); // Serialize object. var stream = new MemoryStream(); var serializer = new XmlSerializer(typeof(Shape)); serializer.Serialize(stream, a); // Output generated xml. Can be manually checked in output window. stream.Position = 0; var xml = new StreamReader(stream).ReadToEnd(); Trace.WriteLine("Serialized Object:\n" + xml); // Deserialize object. stream.Position = 0; var deserializer = new XmlSerializer(typeof(Shape)); var b = (PerspectiveViewVolume)deserializer.Deserialize(stream); Assert.AreEqual(a.Left, b.Left); Assert.AreEqual(a.Right, b.Right); Assert.AreEqual(a.Top, b.Top); Assert.AreEqual(a.Bottom, b.Bottom); Assert.AreEqual(a.Near, b.Near); Assert.AreEqual(a.Far, b.Far); Assert.AreEqual(a.InnerPoint, b.InnerPoint); }
public void FarException() { PerspectiveViewVolume frustum = new PerspectiveViewVolume { Near = 1, Far = 0 }; }
public void GetExtentTest() { float extent; extent = PerspectiveViewVolume.GetExtent(MathHelper.ToRadians(90), 1); Assert.IsTrue(Numeric.AreEqual(2, extent)); extent = PerspectiveViewVolume.GetExtent(MathHelper.ToRadians(60), 10); Assert.IsTrue(Numeric.AreEqual(11.547005f, extent)); }
public void InnerPointTest() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetWidthAndHeight(1, 1, 1, 10); Vector3F innerPoint = frustum.InnerPoint; Assert.AreEqual(0, innerPoint.X); Assert.AreEqual(0, innerPoint.Y); Assert.AreEqual(-5.5f, innerPoint.Z); }
public void GetFieldOfViewTest() { float fieldOfView; fieldOfView = PerspectiveViewVolume.GetFieldOfView(2, 1); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(90), fieldOfView)); fieldOfView = PerspectiveViewVolume.GetFieldOfView(1.1547005f, 1); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(60), fieldOfView)); }
public void PerspectiveViewVolumeTest() { var s = new PerspectiveViewVolume(0.4f, 2, 0.1f, 1f); var v0 = s.GetVolume(0.001f, 10); var m = s.GetMesh(0.001f, 10); var s1 = new TriangleMeshShape(m); var v1 = s1.GetVolume(0.0001f, 10); Assert.IsTrue(Numeric.AreEqual(v0, v1, 0.01f * (1 + v0))); // 1% error is allowed. }
/// <summary> /// Initializes a new instance of the <see cref="VarianceShadowMapRenderer"/> class. /// </summary> /// <param name="render"> /// The method which renders the scene into the shadow map. Must not be <see langword="null"/>. /// See <see cref="RenderCallback"/> for more information. /// </param> public VarianceShadowMapRenderer(Func <RenderContext, bool> render) { if (render == null) { throw new ArgumentNullException("render"); } RenderCallback = render; _cameraVolume = new PerspectiveViewVolume(); _orthographicCameraNode = new CameraNode(new Camera(new OrthographicProjection())); }
/// <summary> /// Initializes a new instance of the <see cref="CascadedShadowMapRenderer"/> class. /// </summary> /// <param name="renderCallback"> /// The method which renders the scene into the shadow map. Must not be <see langword="null"/>. /// See <see cref="RenderCallback"/> for more information. /// </param> public CascadedShadowMapRenderer(Func <RenderContext, bool> renderCallback) { if (renderCallback == null) { throw new ArgumentNullException("renderCallback"); } RenderCallback = renderCallback; _splitVolume = new PerspectiveViewVolume(); _orthographicCameraNode = new CameraNode(new Camera(new OrthographicProjection())); }
public void SetFieldOfView2Test() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); PerspectiveViewVolume frustum2 = new PerspectiveViewVolume { Near = 1, Far = 10 }; frustum2.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f); Assert.AreEqual(frustum.Near, frustum2.Near); Assert.AreEqual(frustum.Far, frustum2.Far); }
public void GetWidthAndHeightTest() { float width, height; PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(90), 1, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2, width)); Assert.IsTrue(Numeric.AreEqual(2, height)); PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2.0528009f, width)); Assert.IsTrue(Numeric.AreEqual(1.1547005f, height)); }
public void ConvertToVerticalFieldOfViewTest() { float verticalFieldOfView = PerspectiveViewVolume.GetFieldOfViewY(MathHelper.ToRadians(90), 1); float expectedFieldOfView = MathHelper.ToRadians(90); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, verticalFieldOfView)); verticalFieldOfView = PerspectiveViewVolume.GetFieldOfViewY(MathHelper.ToRadians(75), (float)(4.0 / 3.0)); expectedFieldOfView = (float)MathHelper.ToRadians(59.840444); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, verticalFieldOfView)); verticalFieldOfView = PerspectiveViewVolume.GetFieldOfViewY(MathHelper.ToRadians(90), (float)(16.0 / 9.0)); expectedFieldOfView = (float)MathHelper.ToRadians(58.715507); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, verticalFieldOfView)); }
public void ConvertToHorizontalFieldOfViewTest() { float horizontalFieldOfView = PerspectiveViewVolume.GetFieldOfViewX(MathHelper.ToRadians(60), 1); float expectedFieldOfView = MathHelper.ToRadians(60); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, horizontalFieldOfView)); horizontalFieldOfView = PerspectiveViewVolume.GetFieldOfViewX(MathHelper.ToRadians(60), (float)(4.0 / 3.0)); expectedFieldOfView = (float)MathHelper.ToRadians(75.178179); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, horizontalFieldOfView)); horizontalFieldOfView = PerspectiveViewVolume.GetFieldOfViewX(MathHelper.ToRadians(45), (float)(16.0 / 9.0)); expectedFieldOfView = (float)MathHelper.ToRadians(72.734351); Assert.IsTrue(Numeric.AreEqual(expectedFieldOfView, horizontalFieldOfView)); }
public void PropertiesTest() { PerspectiveViewVolume frustum = new PerspectiveViewVolume { Left = -2, Right = 2, Bottom = -1, Top = 1, Near = 2, Far = 10 }; Assert.AreEqual(-2, frustum.Left); Assert.AreEqual(2, frustum.Right); Assert.AreEqual(-1, frustum.Bottom); Assert.AreEqual(1, frustum.Top); Assert.AreEqual(2, frustum.Near); Assert.AreEqual(10, frustum.Far); Assert.AreEqual(4, frustum.Width); Assert.AreEqual(2, frustum.Height); Assert.AreEqual(8, frustum.Depth); Assert.AreEqual(2, frustum.AspectRatio); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(90), frustum.FieldOfViewX)); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(53.130102f), frustum.FieldOfViewY)); frustum = new PerspectiveViewVolume { Left = 2, Right = -2, Bottom = 1, Top = -1, Near = 10, Far = 2 }; Assert.AreEqual(2, frustum.Left); Assert.AreEqual(-2, frustum.Right); Assert.AreEqual(1, frustum.Bottom); Assert.AreEqual(-1, frustum.Top); Assert.AreEqual(10, frustum.Near); Assert.AreEqual(2, frustum.Far); Assert.AreEqual(4, frustum.Width); Assert.AreEqual(2, frustum.Height); Assert.AreEqual(8, frustum.Depth); Assert.AreEqual(2, frustum.AspectRatio); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(90), frustum.FieldOfViewX)); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(53.130102f), frustum.FieldOfViewY)); }
public void Clone() { PerspectiveViewVolume perspectiveViewVolume = new PerspectiveViewVolume(1.23f, 2.13f, 1.01f, 10.345f); PerspectiveViewVolume clone = perspectiveViewVolume.Clone() as PerspectiveViewVolume; Assert.IsNotNull(clone); Assert.AreEqual(perspectiveViewVolume.Left, clone.Left); Assert.AreEqual(perspectiveViewVolume.Right, clone.Right); Assert.AreEqual(perspectiveViewVolume.Bottom, clone.Bottom); Assert.AreEqual(perspectiveViewVolume.Top, clone.Top); Assert.AreEqual(perspectiveViewVolume.Near, clone.Near); Assert.AreEqual(perspectiveViewVolume.Far, clone.Far); Assert.AreEqual(perspectiveViewVolume.FieldOfViewX, clone.FieldOfViewX); Assert.AreEqual(perspectiveViewVolume.FieldOfViewY, clone.FieldOfViewY); Assert.AreEqual(perspectiveViewVolume.GetAabb(Pose.Identity).Minimum, clone.GetAabb(Pose.Identity).Minimum); Assert.AreEqual(perspectiveViewVolume.GetAabb(Pose.Identity).Maximum, clone.GetAabb(Pose.Identity).Maximum); }
public void AabbTest() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.Set(-1, 1, -1, 1, 2, 5); Aabb aabb = frustum.GetAabb(Pose.Identity); Assert.AreEqual(new Vector3F(-2.5f, -2.5f, -5), aabb.Minimum); Assert.AreEqual(new Vector3F(2.5f, 2.5f, -2), aabb.Maximum); frustum.Set(0, 2, 0, 2, 1, 5); aabb = frustum.GetAabb(Pose.Identity); Assert.AreEqual(new Vector3F(0f, 0, -5), aabb.Minimum); Assert.AreEqual(new Vector3F(10, 10, -1), aabb.Maximum); frustum.Set(1, 2, 1, 2, 1, 5); aabb = frustum.GetAabb(Pose.Identity); Assert.AreEqual(new Vector3F(1, 1, -5), aabb.Minimum); Assert.AreEqual(new Vector3F(10, 10, -1), aabb.Maximum); }
public void SetWidthAndHeightTest() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetWidthAndHeight(2.0528009f, 1.1547005f, 1, 10); Assert.IsTrue(Numeric.AreEqual(-2.0528009f / 2.0f, frustum.Left)); Assert.IsTrue(Numeric.AreEqual(2.0528009f / 2.0f, frustum.Right)); Assert.IsTrue(Numeric.AreEqual(-1.1547005f / 2.0f, frustum.Bottom)); Assert.IsTrue(Numeric.AreEqual(1.1547005f / 2.0f, frustum.Top)); Assert.AreEqual(1, frustum.Near); Assert.AreEqual(10, frustum.Far); Assert.IsTrue(Numeric.AreEqual(2.0528009f, frustum.Width)); Assert.IsTrue(Numeric.AreEqual(1.1547005f, frustum.Height)); Assert.AreEqual(9, frustum.Depth); Assert.AreEqual(16.0f / 9.0f, frustum.AspectRatio); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(91.492843f), frustum.FieldOfViewX)); Assert.IsTrue(Numeric.AreEqual(MathHelper.ToRadians(60), frustum.FieldOfViewY)); }
public void GetWidthAndHeightTest() { float width, height; PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(90), 1, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2, width)); Assert.IsTrue(Numeric.AreEqual(2, height)); PerspectiveViewVolume.GetWidthAndHeight(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, out width, out height); Assert.IsTrue(Numeric.AreEqual(2.0528009f, width)); Assert.IsTrue(Numeric.AreEqual(1.1547005f, height)); // We are pretty confident that the Projection.CreateProjectionXxx() works. // Use Projection.CreateProjectionXxx() to test GetWidthAndHeight(). Matrix44F projection = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); Matrix44F projection2 = Matrix44F.CreatePerspective(width, height, 1, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(projection, projection2)); }
public void SerializationBinary() { var a = new PerspectiveViewVolume(1.23f, 2.13f, 1.01f, 10.345f); // Serialize object. var stream = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(stream, a); // Deserialize object. stream.Position = 0; var deserializer = new BinaryFormatter(); var b = (PerspectiveViewVolume)deserializer.Deserialize(stream); Assert.AreEqual(a.Left, b.Left); Assert.AreEqual(a.Right, b.Right); Assert.AreEqual(a.Top, b.Top); Assert.AreEqual(a.Bottom, b.Bottom); Assert.AreEqual(a.Near, b.Near); Assert.AreEqual(a.Far, b.Far); Assert.AreEqual(a.InnerPoint, b.InnerPoint); }
public void SetException2() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.Set(1, 2, 4, 4, 5, 6); }
public void GetHorizontalViewException() { PerspectiveViewVolume.GetFieldOfViewX(0, 4.0f / 3.0f); }
public void SetWidthAndHeightException5() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetWidthAndHeight(2.0528009f, 1.1547005f, 1, 1); }
public void SetWidthAndHeightException() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetWidthAndHeight(0, 1.1547005f, 1, 10); }
public override void Update(GameTime gameTime) { Random random = new Random(1234567); // The debug renderer stores all draw commands. In this sample we recreate // the draw jobs each frame. --> Clear draw jobs of last frame. _debugRenderer.Clear(); // The DebugRenderer can draw stuff "in" the scene (enabled z test) or "over" // the scene (disabled z test). // Draw some points and line "in" and "over" the scene. for (int i = 0; i < 10; i++) { var position = new Vector3F(-6, 0, -3) + random.NextVector3F(-0.5f, 0.5f); _debugRenderer.DrawPoint(position, Color.Green, false); } for (int i = 0; i < 10; i++) { var position = new Vector3F(-4, 0, -3) + random.NextVector3F(-0.5f, 0.5f); _debugRenderer.DrawPoint(position, Color.Yellow, true); } for (int i = 0; i < 10; i++) { var start = new Vector3F(-2, 0, -3) + random.NextVector3F(-0.5f, 0.5f); var end = new Vector3F(-2, 0, -3) + random.NextVector3F(-0.5f, 0.5f); _debugRenderer.DrawLine(start, end, Color.Green, false); } for (int i = 0; i < 10; i++) { var start = new Vector3F(0, 0, -3) + random.NextVector3F(-0.5f, 0.5f); var end = new Vector3F(0, 0, -3) + random.NextVector3F(-0.5f, 0.5f); _debugRenderer.DrawLine(start, end, Color.Yellow, true); } // Text without a specified position is drawn at a default position. _debugRenderer.DefaultTextPosition = new Vector2F(10, 100); _debugRenderer.DrawText("White objects are positioned in screen space."); _debugRenderer.DrawText("Yellow objects are positioned in world space. Depth test disabled."); _debugRenderer.DrawText("Other objects are positioned in world space. Depth test enabled."); // Text can also be drawn in world space coordinates or in screen space coordinates. _debugRenderer.DrawText("WorldSpacePosition (0, 0, 0)", new Vector3F(0, 0, 0), Color.Green, false); _debugRenderer.DrawText("WorldSpacePosition (0, 0, -1)", new Vector3F(0, 0, -1), Color.Yellow, true); _debugRenderer.DrawText("ScreenPosition (600, 40)", new Vector2F(600, 40), Color.White); _debugRenderer.DrawText("ScreenPosition (640, 360)", new Vector2F(640, 360), Color.White); // It is often useful to copy textures to the screen for debugging. _debugRenderer.DrawTexture(NoiseHelper.GetGrainTexture(GraphicsService, 128), new Rectangle(1000, 10, 128, 128)); // Axes can be drawn to display poses (positions and orientations). _debugRenderer.DrawAxes(new Pose(new Vector3F(0, 0, 0)), 1, true); // Axis-aligned bounding boxes (AABB) _debugRenderer.DrawAabb(new Aabb(new Vector3F(-0.5f), new Vector3F(0.5f)), new Pose(new Vector3F(2, 0, -3)), Color.Green, false); _debugRenderer.DrawAabb(new Aabb(new Vector3F(-0.5f), new Vector3F(0.5f)), new Pose(new Vector3F(4, 0, -3)), Color.Yellow, true); // Box shapes var orientation = random.NextQuaternionF(); _debugRenderer.DrawBox(1, 1, 1, new Pose(new Vector3F(-6, 0, -5), orientation), new Color(255, 0, 0, 100), false, false); _debugRenderer.DrawBox(1, 1, 1, new Pose(new Vector3F(-6, 0, -5), orientation), Color.Green, true, false); _debugRenderer.DrawBox(1, 1, 1, new Pose(new Vector3F(-4, 0, -5), orientation), Color.Yellow, true, true); // View volumes (frustums) var viewVolume = new PerspectiveViewVolume(1, 2, 0.1f, 1f); _debugRenderer.DrawViewVolume(viewVolume, new Pose(new Vector3F(-2, 0, -5), orientation), new Color(0, 255, 0, 100), false, false); _debugRenderer.DrawViewVolume(viewVolume, new Pose(new Vector3F(-2, 0, -5), orientation), Color.Green, true, false); _debugRenderer.DrawViewVolume(viewVolume, new Pose(new Vector3F(0, 0, -5), orientation), Color.Yellow, true, true); // Spheres _debugRenderer.DrawSphere(0.5f, new Pose(new Vector3F(2, 0, -5), orientation), new Color(0, 0, 255, 100), false, false); _debugRenderer.DrawSphere(0.5f, new Pose(new Vector3F(2, 0, -5), orientation), Color.Green, true, false); _debugRenderer.DrawSphere(0.5f, new Pose(new Vector3F(4, 0, -5), orientation), Color.Yellow, true, true); // Capsules _debugRenderer.DrawCapsule(0.3f, 1, new Pose(new Vector3F(-6, 0, -7), orientation), new Color(255, 255, 0, 100), false, false); _debugRenderer.DrawCapsule(0.3f, 1, new Pose(new Vector3F(-6, 0, -7), orientation), Color.Green, true, false); _debugRenderer.DrawCapsule(0.3f, 1, new Pose(new Vector3F(-4, 0, -7), orientation), Color.Yellow, true, true); // Cylinders _debugRenderer.DrawCylinder(0.3f, 1, new Pose(new Vector3F(-2, 0, -7), orientation), new Color(255, 0, 255, 100), false, false); _debugRenderer.DrawCylinder(0.3f, 1, new Pose(new Vector3F(-2, 0, -7), orientation), Color.Green, true, false); _debugRenderer.DrawCylinder(0.3f, 1, new Pose(new Vector3F(0, 0, -7), orientation), Color.Yellow, true, true); // Cones _debugRenderer.DrawCone(0.3f, 1, new Pose(new Vector3F(2, 0, -7), orientation), new Color(0, 255, 255, 100), false, false); _debugRenderer.DrawCone(0.3f, 1, new Pose(new Vector3F(2, 0, -7), orientation), Color.Green, true, false); _debugRenderer.DrawCone(0.3f, 1, new Pose(new Vector3F(4, 0, -7), orientation), Color.Yellow, true, true); // The debug renderer can draw any IGeometricObjects, like SceneNodes, RigidBodies, etc. _debugRenderer.DrawObject(_geometricObject, Color.Brown, false, false); _debugRenderer.DrawObject(_geometricObject, Color.Yellow, true, true); // The debug renderer can also an XNA model (without materials). _debugRenderer.DrawModel(_xnaModel, new Pose(new Vector3F(0, 2, -2), orientation), new Vector3F(1, 2, 1), new Color(128, 255, 64, 100), false, false); _debugRenderer.DrawModel(_xnaModel, new Pose(new Vector3F(0, 2, -2), orientation), new Vector3F(1, 2, 1), Color.LightCyan, true, false); // Draw a DigitalRune model. _debugRenderer.DrawModel(_modelNode, Color.Peru, true, false); // Draw the bounding shapes of the meshes in this model. foreach (var node in _modelNode.GetSubtree()) { _debugRenderer.DrawObject(node, Color.PeachPuff, true, false); } }
public void GetExtentException() { PerspectiveViewVolume.GetExtent(0, 1); }
public void GetVerticalViewException() { PerspectiveViewVolume.GetFieldOfViewY(0, 4.0f / 3.0f); }
public void SetException5() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.Set(1, 2, 3, 4, 1, 0); }
public void SetFieldOfViewException5() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 0); }
public void SetWidthAndHeightException2() { PerspectiveViewVolume frustum = new PerspectiveViewVolume(); frustum.SetWidthAndHeight(2.0528009f, 0, 1, 10); }
public void GetHorizontalViewException2() { PerspectiveViewVolume.GetFieldOfViewX(ConstantsF.PiOver4, 0); }
public void GetVerticalViewException2() { PerspectiveViewVolume.GetFieldOfViewY(ConstantsF.PiOver4, 0); }
public void GetExtentException2() { PerspectiveViewVolume.GetExtent(ConstantsF.PiOver4, -0.1f); }
/// <summary> /// Initializes a new instance of the <see cref="PerspectiveProjection"/> class. /// </summary> public PerspectiveProjection() { ViewVolume = new PerspectiveViewVolume(); SetFieldOfView(DefaultFieldOfViewY, DefaultAspectRatio, DefaultNear, DefaultFar); }