/// <summary>
        /// Builds a 3-D affine transformation matrix.
        /// </summary>
        /// <param name="scaling">The scaling vactor. Use zero to specify no scaling.</param>
        /// <param name="rotationCenter">A <see cref="Vector3F"/> instance specifying the center of the rotation.</param>
        /// <param name="rotation">A <see cref="QuaternionF"/> instance specifying the rotation. use <see cref="QuaternionF.Identity"/> to specify no rotation.</param>
        /// <param name="translation">A <see cref="Vector3F"/> specifying the translation. Use <see cref="Vector3F.Zero"/> to specify no translation.</param>
        /// <returns>A <see cref="Matrix4F"/> representing the affine transformation.</returns>
        /// <remarks>
        /// <p>
        /// Calculates the transoformation matrix using the following formula:
        /// Mout = Ms * (Mrc)^-1 * Mr * Mrc * Mt
        /// </p>
        /// <p>
        /// where:
        /// <list type="bullet">
        ///		<item>
        ///			<term>Ms</term>
        ///			<description>Scaling transformation.</description>
        ///		</item>
        ///		<item>
        ///			<term>Mrc</term>
        ///			<description>Rotation center transformation.</description>
        ///		</item>
        ///		<item>
        ///			<term>Mr</term>
        ///			<description>Rotation transformation.</description>
        ///		</item>
        ///		<item>
        ///			<term>Mt</term>
        ///			<description>Translation transformation.</description>
        ///		</item>
        /// </list>
        /// </p>
        /// </remarks>
        public static Matrix4F AffineTransformation(float scaling, Vector3F rotationCenter, QuaternionF rotation, Vector3F translation)
        {
            Matrix4F Ms = TransformationF.Scaling(scaling, scaling, scaling);
            Matrix4F Mt = TransformationF.Translation(translation.X, translation.Y, translation.Z);

            // TODO: Implement this.
            throw new NotImplementedException();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrientedBox"/> class using given center point, axes and extents.
 /// </summary>
 /// <param name="center">The center of the box.</param>
 /// <param name="axis1">The first axis.</param>
 /// <param name="axis2">The second axis.</param>
 /// <param name="axis3">The third axis.</param>
 /// <param name="extent1">The extent on the first axis.</param>
 /// <param name="extent2">The extent on the second axis.</param>
 /// <param name="extent3">The extent of the third axis.</param>
 public OrientedBox(Vector3F center, Vector3F axis1, Vector3F axis2, Vector3F axis3, float extent1, float extent2, float extent3)
 {
     _center = center;
     _axis1 = axis1;
     _axis2 = axis2;
     _axis3 = axis3;
     _extent1 = extent1;
     _extent2 = extent2;
     _extent3 = extent3;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisAlignedBox"/> class using given values from another box instance.
 /// </summary>
 /// <param name="box">A <see cref="AxisAlignedBox"/> instance to take values from.</param>
 public AxisAlignedBox(AxisAlignedBox box)
 {
     _min = box.Min;
     _max = box.Max;
 }
        /// <summary>
        /// Computes the box vertices. 
        /// </summary>
        /// <returns>An array of <see cref="Vector3F"/> containing the box vertices.</returns>
        public Vector3F[] ComputeVertices()
        {
            Vector3F[] vertices = new Vector3F[8];

            vertices[0] = _min;
            vertices[1] = new Vector3F(_max.X, _min.Y, _min.Z);
            vertices[2] = new Vector3F(_max.X, _max.Y, _min.Z);
            vertices[4] = new Vector3F(_min.X, _max.Y, _min.Z);

            vertices[5] = new Vector3F(_min.X, _min.Y, _max.Z);
            vertices[6] = new Vector3F(_max.X, _min.Y, _max.Z);
            vertices[7] = _max;
            vertices[8] = new Vector3F(_min.X, _max.Y, _max.Z);

            return vertices;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Segment"/> class using an existing <see cref="Segment"/> instance.
 /// </summary>
 /// <param name="l">A <see cref="Segment"/> instance.</param>
 public Segment(Segment l)
 {
     _p0 = l.P0;
     _p1 = l.P1;
 }
 /// <summary>
 /// Initialize a new instance of the <see cref="IntersectionPair"/> class.
 /// </summary>
 /// <param name="intersectionOccurred">A boolean value.</param>
 /// <param name="intersectionPoint">A <see cref="Vector3F"/> instance.</param>
 public IntersectionPair(bool intersectionOccurred, Vector3F intersectionPoint)
 {
     _occurred = intersectionOccurred;
     _point = intersectionPoint;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrientedBox"/> class with serialized data.
        /// </summary>
        /// <param name="info">The object that holds the serialized object data.</param>
        /// <param name="context">The contextual information about the source or destination.</param>
        private OrientedBox(SerializationInfo info, StreamingContext context)
        {
            _center = (Vector3F)info.GetValue("Center", typeof(Vector3F));

            _axis1 = (Vector3F)info.GetValue("Axis1", typeof(Vector3F));
            _axis2 = (Vector3F)info.GetValue("Axis2", typeof(Vector3F));
            _axis3 = (Vector3F)info.GetValue("Axis3", typeof(Vector3F));

            _extent1 = info.GetSingle("Extent1");
            _extent2 = info.GetSingle("Extent2");
            _extent3 = info.GetSingle("Extent3");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Plane"/> class using given normal and a point.
 /// </summary>
 /// <param name="normal">The plane's normal vector.</param>
 /// <param name="point">A point on the plane in 3D space.</param>
 public Plane(Vector3F normal, Vector3F point)
 {
     _normal = normal;
     _const	= Vector3F.Dot(normal, point);
 }
 /// <summary>
 /// Transforms a given vector by a matrix applying the positional matrix components but omitting the projection components and put the result in a vector.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix4F"/> instance.</param>
 /// <param name="vector">A <see cref="Vector3F"/> instance.</param>
 /// <param name="result">A <see cref="Vector3F"/> instance to hold the result.</param>
 public static void Transform(Matrix4F matrix, Vector3F vector, ref Vector3F result)
 {
     result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + matrix.M14;
     result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + matrix.M24;
     result.Z = (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + matrix.M34;
 }
 /// <summary>
 /// Transforms a given vector by a matrix applying the positional matrix components but omitting the projection components.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix4F"/> instance.</param>
 /// <param name="vector">A <see cref="Vector3F"/> instance.</param>
 /// <returns>A new <see cref="Vector3F"/> instance containing the result.</returns>
 public static Vector3F Transform(Matrix4F matrix, Vector3F vector)
 {
     return new Vector3F(
         (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + matrix.M14,
         (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + matrix.M24,
         (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + matrix.M34);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Triangle"/> class using a given Triangle.
 /// </summary>
 /// <param name="t">A <see cref="Triangle"/> instance.</param>
 public Triangle(Triangle t)
 {
     _p0 = t._p0;
     _p1 = t._p1;
     _p2 = t._p2;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Triangle"/> class.
 /// </summary>
 /// <param name="p0">A <see cref="Vector3F"/> instance.</param>
 /// <param name="p1">A <see cref="Vector3F"/> instance.</param>
 /// <param name="p2">A <see cref="Vector3F"/> instance.</param>
 public Triangle(Vector3F p0, Vector3F p1, Vector3F p2)
 {
     _p0 = p0;
     _p1 = p1;
     _p2 = p2;
 }
 /// <summary>
 /// Indexer ( [P0, P1, P2] ).
 /// </summary>
 public Vector3F this[int index]
 {
     get
     {
         switch(index)
         {
             case 0 : return _p0;
             case 1 : return _p1;
             case 2 : return _p2;
             default:
                 throw new IndexOutOfRangeException();
         }
     }
     set
     {
         switch(index)
         {
             case 0 : _p0 = value; break;
             case 1 : _p1 = value; break;
             case 2 : _p2 = value; break;
             default:
                 throw new IndexOutOfRangeException();
         }
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Ray"/> class with serialized data.
 /// </summary>
 /// <param name="info">The object that holds the serialized object data.</param>
 /// <param name="context">The contextual information about the source or destination.</param>
 private Ray(SerializationInfo info, StreamingContext context)
 {
     _origin		= (Vector3F)info.GetValue("Origin", typeof(Vector3F));
     _direction	= (Vector3F)info.GetValue("Direction", typeof(Vector3F));
 }
 /// <summary>
 /// Transforms a given 3F vector by a matrix using perspective division.
 /// </summary>
 /// <remarks>
 /// Before the matrix multiplication the 3F vector is extended to 4F by setting its W component to 1.
 /// After the matrix multiplication the resulting 4D vector is transformed to 3D by dividing X, Y, and Z by W.
 /// (perspective division).
 /// </remarks>
 /// <param name="matrix">A <see cref="Matrix4F"/> instance.</param>
 /// <param name="vector">A <see cref="Vector3F"/> instance.</param>
 /// <returns>A new <see cref="Vector3D"/> instance containing the result.</returns>
 public static Vector3F TransformPD(Matrix4F matrix, Vector3F vector)
 {
     float w = (matrix.M41 * vector.X) + (matrix.M42 * vector.Y) + (matrix.M43 * vector.Z) + matrix.M44;
     return new Vector3F(
         ((matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + matrix.M14) / w,
         ((matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + matrix.M24) / w,
         ((matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + matrix.M34) / w);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Plane"/> class using given normal and constant values.
 /// </summary>
 /// <param name="normal">The plane's normal vector.</param>
 /// <param name="constant">The plane's constant value.</param>
 public Plane(Vector3F normal, float constant)
 {
     _normal	= normal;
     _const	= constant;
 }
 /// <summary>
 /// Transforms a given vector by a matrix using perspective division and put the result in a vector.
 /// </summary>
 /// <remarks>
 /// Before the matrix multiplication the 3F vector is extended to 4F by setting its W component to 1.
 /// After the matrix multiplication the resulting 4F vector is transformed to 3F by dividing X, Y, and Z by W.
 /// (perspective division).
 /// </remarks>
 /// <param name="matrix">A <see cref="Matrix4F"/> instance.</param>
 /// <param name="vector">A <see cref="Vector3F"/> instance.</param>
 /// <param name="result">A <see cref="Vector3F"/> instance to hold the result.</param>
 public static void TransformPD(Matrix4F matrix, Vector3F vector, ref Vector3F result)
 {
     float w = (matrix.M41 * vector.X) + (matrix.M42 * vector.Y) + (matrix.M43 * vector.Z) + matrix.M44;
     result.X = ((matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + matrix.M14) / w;
     result.Y = ((matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + matrix.M24) / w;
     result.Z = ((matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + matrix.M34) / w;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrientedBox"/> class using given values from another box instance.
        /// </summary>
        /// <param name="box">A <see cref="OrientedBox"/> instance to take values from.</param>
        public OrientedBox(OrientedBox box)
        {
            _center = box.Center;

            _axis1 = box.Axis1;
            _axis2 = box.Axis2;
            _axis3 = box.Axis3;

            _extent1 = box.Extent1;
            _extent2 = box.Extent2;
            _extent3 = box.Extent3;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Plane"/> class using 3 given points.
 /// </summary>
 /// <param name="p0">A point on the plane in 3D space.</param>
 /// <param name="p1">A point on the plane in 3D space.</param>
 /// <param name="p2">A point on the plane in 3D space.</param>
 public Plane(Vector3F p0, Vector3F p1, Vector3F p2)
 {
     _normal = Vector3F.CrossProduct(p2-p1, p0-p1);
     _normal.Normalize();
     _const	= Vector3F.Dot(_normal, p0);
 }
        /// <summary>
        /// Computes the box vertices. 
        /// </summary>
        /// <returns>An array of <see cref="Vector3F"/> containing the box vertices.</returns>
        public Vector3F[] ComputeVertices()
        {
            Vector3F[] vertices = new Vector3F[8];
            Vector3F[] AxisExtents = new Vector3F[3]
                {
                    Axis1*Extent1, Axis2*Extent2, Axis3*Extent3
                };

            vertices[0] = Center - AxisExtents[0] - AxisExtents[1] - AxisExtents[2];
            vertices[1] = Center - AxisExtents[0] + AxisExtents[1] - AxisExtents[2];
            vertices[2] = Center + AxisExtents[0] + AxisExtents[1] - AxisExtents[2];
            vertices[3] = Center - AxisExtents[0] + AxisExtents[1] - AxisExtents[2];

            vertices[0] = Center - AxisExtents[0] - AxisExtents[1] + AxisExtents[2];
            vertices[1] = Center - AxisExtents[0] + AxisExtents[1] + AxisExtents[2];
            vertices[2] = Center + AxisExtents[0] + AxisExtents[1] + AxisExtents[2];
            vertices[3] = Center - AxisExtents[0] + AxisExtents[1] + AxisExtents[2];

            return vertices;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Plane"/> class using given a plane to assign values from.
 /// </summary>
 /// <param name="p">A 3D plane to assign values from.</param>
 public Plane(Plane p)
 {
     _normal	= p.Normal;
     _const	= p.Constant;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="OrientedBox"/> class using given center point, axes and extents.
        /// </summary>
        /// <param name="center">The center of the box..</param>
        /// <param name="axes">The axes of the box.</param>
        /// <param name="extents">The extent values of the box..</param>
        public OrientedBox(Vector3F center, Vector3F[] axes, float[] extents)
        {
            Debug.Assert(axes.Length >= 3);
            Debug.Assert(extents.Length >= 3);

            _center = center;

            _axis1 = axes[0];
            _axis2 = axes[1];
            _axis3 = axes[2];

            _extent1 = extents[0];
            _extent2 = extents[1];
            _extent3 = extents[2];
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Plane"/> class with serialized data.
 /// </summary>
 /// <param name="info">The object that holds the serialized object data.</param>
 /// <param name="context">The contextual information about the source or destination.</param>
 private Plane(SerializationInfo info, StreamingContext context)
 {
     _normal = (Vector3F)info.GetValue("Normal", typeof(Vector3F));
     _const	= info.GetSingle("Constant");
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Segment"/> class.
 /// </summary>
 /// <param name="p0">A <see cref="Vector3F"/> instance marking the segment's starting point.</param>
 /// <param name="p1">A <see cref="Vector3F"/> instance marking the segment's ending point.</param>
 public Segment(Vector3F p0, Vector3F p1)
 {
     _p0 = p0;
     _p1 = p1;
 }
 /// <summary>
 /// Flip the plane.
 /// </summary>
 public void Flip()
 {
     _normal = -_normal;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Segment"/> class with serialized data.
 /// </summary>
 /// <param name="info">The object that holds the serialized object data.</param>
 /// <param name="context">The contextual information about the source or destination.</param>
 private Segment(SerializationInfo info, StreamingContext context)
 {
     _p0	= (Vector3F)info.GetValue("P0", typeof(Vector3F));
     _p1	= (Vector3F)info.GetValue("P1", typeof(Vector3F));
 }
 /// <summary>
 /// Returns the points's position relative to the plane itself (i.e Front/Back/On)
 /// </summary>
 /// <param name="p">A point in 3D space.</param>
 /// <returns>A <see cref="MathFunctions.Sign"/>.</returns>
 public MathFunctions.Sign GetSign(Vector3F p)
 {
     return MathFunctions.GetSign(DistanceMethods.Distance(p,this));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisAlignedBox"/> class using given minimum and maximum points.
 /// </summary>
 /// <param name="min">A <see cref="Vector3F"/> instance representing the minimum point.</param>
 /// <param name="max">A <see cref="Vector3F"/> instance representing the maximum point.</param>
 public AxisAlignedBox(Vector3F min, Vector3F max)
 {
     _min = min;
     _max = max;
 }
 /// <summary>
 /// Returns the points's position relative to the plane itself (i.e Front/Back/On)
 /// </summary>
 /// <param name="p">A point in 3D space.</param>
 /// <param name="tolerance">The tolerance value to use.</param>
 /// <returns>A <see cref="MathFunctions.Sign"/>.</returns>
 /// <remarks>
 /// If the point's distance from the plane is withon the [-tolerance, tolerance] range, the point is considered to be on the plane.
 /// </remarks>
 public MathFunctions.Sign GetSign(Vector3F p, float tolerance)
 {
     return MathFunctions.GetSign(DistanceMethods.Distance(p,this), tolerance);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AxisAlignedBox"/> class with serialized data.
 /// </summary>
 /// <param name="info">The object that holds the serialized object data.</param>
 /// <param name="context">The contextual information about the source or destination.</param>
 private AxisAlignedBox(SerializationInfo info, StreamingContext context)
 {
     _min = (Vector3F)info.GetValue("Min", typeof(Vector3F));
     _max = (Vector3F)info.GetValue("Max", typeof(Vector3F));
 }
Exemple #31
0
 /// <summary>
 /// Transforms a given vector by a matrix applying the positional matrix components but omitting the projection components and put the result in a vector.
 /// </summary>
 /// <param name="matrix">A <see cref="Matrix4F"/> instance.</param>
 /// <param name="vector">A <see cref="Vector3F"/> instance.</param>
 /// <param name="result">A <see cref="Vector3F"/> instance to hold the result.</param>
 public static void Transform(Matrix4F matrix, Vector3F vector, ref Vector3F result)
 {
     result.X = (matrix.M11 * vector.X) + (matrix.M12 * vector.Y) + (matrix.M13 * vector.Z) + matrix.M14;
     result.Y = (matrix.M21 * vector.X) + (matrix.M22 * vector.Y) + (matrix.M23 * vector.Z) + matrix.M24;
     result.Z = (matrix.M31 * vector.X) + (matrix.M32 * vector.Y) + (matrix.M33 * vector.Z) + matrix.M34;
 }