/// <summary> /// Initializes a new instance of <see cref="Plane"/> from a <see cref="PlaneShape"/>. /// </summary> /// <param name="planeShape"> /// The <see cref="PlaneShape"/> from which normal vector and distance from origin are copied. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="planeShape"/> is <see langword="null"/>. /// </exception> public Plane(PlaneShape planeShape) { if (planeShape == null) { throw new ArgumentNullException("planeShape"); } Normal = planeShape.Normal; DistanceFromOrigin = planeShape.DistanceFromOrigin; }
private void Update(bool invalidateRenderData) { if (invalidateRenderData) RenderData.SafeDispose(); // Update shape. if (Volume == null) { // Use a PlaneShape for an infinite ocean. var planeShape = Shape as PlaneShape; if (planeShape != null) { planeShape.Normal = new Vector3F(0, 1, 0); planeShape.DistanceFromOrigin = ExtraHeight; } else { Shape = new PlaneShape(new Vector3F(0, 1, 0), ExtraHeight); } return; } // Check if we have a valid AABB. var aabb = Volume.GetAabb(); if (!Numeric.IsZeroOrPositiveFinite(aabb.Extent.LengthSquared)) throw new GraphicsException("Invalid water volume. The water volume must be a finite shape or null."); // Apply ExtraHeight. We also apply it horizontally because choppy waves // move vertices horizontally too. aabb.Minimum.X -= ExtraHeight; // Minimum y should be at least max y - ExtraHeight. aabb.Minimum.Y = Math.Min(aabb.Minimum.Y, aabb.Maximum.Y - ExtraHeight); aabb.Minimum.Z -= ExtraHeight; aabb.Maximum.X += ExtraHeight; aabb.Maximum.Y += ExtraHeight; aabb.Maximum.Z += ExtraHeight; // Create shape from volume AABB. if (aabb.Center.IsNumericallyZero) { // Use BoxShape. var boxShape = Shape as BoxShape; if (boxShape != null) boxShape.Extent = aabb.Extent; else Shape = new BoxShape(aabb.Extent); } else { BoxShape boxShape = null; var transformedShape = Shape as TransformedShape; if (transformedShape != null) boxShape = transformedShape.Child.Shape as BoxShape; if (boxShape != null) { boxShape.Extent = aabb.Extent; ((GeometricObject)transformedShape.Child).Pose = new Pose(aabb.Center); } else { Shape = new TransformedShape( new GeometricObject(new BoxShape(aabb.Extent), new Pose(aabb.Center))); } } }