Esempio n. 1
0
        //--------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="Camera"/> class with a given projection.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="projection"/> is <see langword="null"/>.
        /// </exception>
        public Camera(Projection projection)
        {
            if (projection == null)
            throw new ArgumentNullException("projection");

              Projection = projection;
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProjectorLight"/> class.
 /// </summary>
 /// <param name="texture">The texture that is projected.</param>
 /// <param name="projection">The projection.</param>
 public ProjectorLight(Texture2D texture, Projection projection)
 {
     Texture = texture;
       Color = Vector3F.One;
       DiffuseIntensity = 1;
       SpecularIntensity = 1;
       HdrScale = 1;
       Projection = projection; // Automatically sets Shape.
       Attenuation = 2;
 }
Esempio n. 3
0
        public static void GetFrustumFarCorners(Projection projection, Vector2F topLeftTexCoord, Vector2F bottomRightTexCoord, Vector3[] frustumFarCorners)
        {
            GetFrustumFarCorners(projection, frustumFarCorners);
              float dX = frustumFarCorners[1].X - frustumFarCorners[0].X;
              float dY = frustumFarCorners[2].Y - frustumFarCorners[0].Y;

              float left = frustumFarCorners[0].X;
              float top = frustumFarCorners[0].Y;

              var texCoordLeft = topLeftTexCoord.X;
              var texCoordTop = topLeftTexCoord.Y;
              var texCoordRight = bottomRightTexCoord.X;
              var texCoordBottom = bottomRightTexCoord.Y;

              frustumFarCorners[0].X = left + texCoordLeft * dX;
              frustumFarCorners[0].Y = top + texCoordTop * dY;
              frustumFarCorners[1].X = left + texCoordRight * dX;
              frustumFarCorners[1].Y = top + texCoordTop * dY;
              frustumFarCorners[2].X = left + texCoordLeft * dX;
              frustumFarCorners[2].Y = top + texCoordBottom * dY;
              frustumFarCorners[3].X = left + texCoordRight * dX;
              frustumFarCorners[3].Y = top + texCoordBottom * dY;
        }
Esempio n. 4
0
 /// <summary>
 /// Makes the instance a clone (deep copy) of the specified 
 /// <see cref="Projection"/>.
 /// </summary>
 /// <param name="source">The object to clone.</param>
 /// <remarks>
 /// <strong>Notes to Inheritors:</strong> Every <see cref="Projection"/> derived class must
 /// implement this method. 
 /// </remarks>
 protected abstract void CloneCore(Projection source);
Esempio n. 5
0
        /// <overloads>
        /// <summary>
        /// Gets the view space positions of the 4 far corners of the viewing frustum.
        /// </summary>
        /// </overloads>
        /// 
        /// <summary>
        /// Gets the view space positions of the 4 far corners of the viewing frustum.
        /// </summary>
        /// <param name="projection">The projection.</param>
        /// <param name="frustumFarCorners">
        /// A 4 element array that will be initialized with the frustum far corners.
        /// </param>
        /// <remarks>
        /// <paramref name="frustumFarCorners"/> will be initialized with the 4 corner positions (in 
        /// view space) of the far plane of the projection frustum. The order of the corners is: 
        /// top-left, top-right, bottom-left, bottom-right.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="projection"/> or <paramref name="frustumFarCorners"/> is 
        /// <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="frustumFarCorners"/> has wrong length. Expected length: 4.
        /// </exception>
        public static void GetFrustumFarCorners(Projection projection, Vector3[] frustumFarCorners)
        {
            if (projection == null)
            throw new ArgumentNullException("projection");
              if (frustumFarCorners == null)
            throw new ArgumentNullException("frustumFarCorners");
              if (frustumFarCorners.Length != 4)
            throw new ArgumentException("frustumFarCorners must be an array with 4 elements.");

              var farOverNear = projection.Far / projection.Near;
              frustumFarCorners[0] = new Vector3(projection.Left, projection.Top, -projection.Near) * farOverNear;
              frustumFarCorners[1] = new Vector3(projection.Right, projection.Top, -projection.Near) * farOverNear;
              frustumFarCorners[2] = new Vector3(projection.Left, projection.Bottom, -projection.Near) * farOverNear;
              frustumFarCorners[3] = new Vector3(projection.Right, projection.Bottom, -projection.Near) * farOverNear;
        }
 /// <inheritdoc/>
 protected override void CloneCore(Projection source)
 {
     var sourceTyped = (OrthographicProjection)source;
       SetOffCenter(sourceTyped.Left, sourceTyped.Right,
            sourceTyped.Bottom, sourceTyped.Top,
            sourceTyped.Near, sourceTyped.Far);
 }
Esempio n. 7
0
 /// <summary>
 /// Makes the instance a clone (deep copy) of the specified
 /// <see cref="Projection"/>.
 /// </summary>
 /// <param name="source">The object to clone.</param>
 /// <remarks>
 /// <strong>Notes to Inheritors:</strong> Every <see cref="Projection"/> derived class must
 /// implement this method.
 /// </remarks>
 protected abstract void CloneCore(Projection source);
Esempio n. 8
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        #region ----- Cloning -----

        /// <inheritdoc/>
        protected override Light CreateInstanceCore()
        {
            return(new ProjectorLight(null, Projection.Clone()));
        }
 /// <inheritdoc/>
 protected override void CloneCore(Projection source)
 {
     var sourceTyped = (PerspectiveProjection)source;
       NearClipPlane = sourceTyped._nearClipPlane;
       SetOffCenter(sourceTyped.Left, sourceTyped.Right,
            sourceTyped.Bottom, sourceTyped.Top,
            sourceTyped.Near, sourceTyped.Far);
 }
Esempio n. 10
0
 /// <summary>
 /// When implemented in a derived class, creates a new instance of the <see cref="Camera"/>
 /// derived class.
 /// </summary>
 /// <returns>The new instance.</returns>
 /// <remarks>
 /// <para>
 /// Do not call this method directly (except when calling base in an implementation). This
 /// method is called internally by the <see cref="Clone"/> method whenever a new instance of the
 /// <see cref="Camera"/> is created.
 /// </para>
 /// <para>
 /// <strong>Notes to Inheritors:</strong> Every <see cref="Camera"/> derived class must
 /// implement this method. A typical implementation is to simply call the default constructor
 /// and return the result.
 /// </para>
 /// </remarks>
 protected virtual Camera CreateInstanceCore()
 {
     return(new Camera(Projection.Clone()));
 }