Ejemplo n.º 1
0
        /// <summary>
        /// Updates the view projection matrix of this Rendertarget.
        /// </summary>
        /// <param name="matrix"></param>
        public void UpdateMatrix(Lunatics.Mathematics.Matrix matrix)
        {
            d_matrix = matrix;

            d_matrixValid = true;
            //! This will trigger the RenderTarget to notify all of its GeometryBuffers to regenerate their matrices
            d_activationCounter = -1;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set a custom transformation matrix that will be applied to the
 /// geometry in the buffer after all the other transformations.
 /// </summary>
 /// <param name="transformation">
 /// 4x4 Matrix that describes the transformation.
 /// </param>
 public void SetCustomTransform(Lunatics.Mathematics.Matrix transformation)
 {
     if (d_customTransform != transformation)
     {
         d_customTransform = transformation;
         d_matrixValid     = false;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a view projection matrix for the Direct3D graphics library (Depth Range from 0 to 1) based
        /// on this RenderTarget's current settings.
        /// </summary>
        /// <returns>
        /// A freshly created Direct3D view projection matrix for this RenderTarget.
        /// </returns>
        public Lunatics.Mathematics.Matrix CreateViewProjMatrixForDirect3D()
        {
            var w = d_area.Width;
            var h = d_area.Height;

            // We need to check if width or height are zero and act accordingly to prevent running into issues
            // with divisions by zero which would lead to undefined values, as well as faulty clipping planes
            // This is mostly important for avoiding asserts
            var widthAndHeightNotZero = (w != 0.0f) && (h != 0.0f);

            var aspect = widthAndHeightNotZero ? w / h : 1.0f;
            var midx   = widthAndHeightNotZero ? w * 0.5f : 0.5f;
            var midy   = widthAndHeightNotZero ? h * 0.5f : 0.5f;

            d_viewDistance = midx / (aspect * d_yfov_tan);

            var eye    = new Lunatics.Mathematics.Vector3(midx, midy, -d_viewDistance);
            var center = new Lunatics.Mathematics.Vector3(midx, midy, 1f);
            var up     = new Lunatics.Mathematics.Vector3(0, -1, 0);

            // We need to have a projection matrix with its depth in clip space ranging from 0 to 1 for nearclip to farclip.
            // The regular OpenGL projection matrix would work too, but we would lose 1 bit of depth precision, which the following
            // manually filled matrix should fix:
            var fovy  = 30f;
            var zNear = d_viewDistance * 0.5f;
            var zFar  = d_viewDistance * 2.0f;
            var f     = 1.0f / (float)Math.Tan(fovy * (float)Math.PI * 0.5f / 180.0f);
            var Q     = zFar / (zNear - zFar);

            var projectionMatrixFloat = new[]
            {
                f / aspect, 0.0f, 0.0f, 0.0f,
                0.0f, f, 0.0f, 0.0f,
                0.0f, 0.0f, Q, -1.0f,
                0.0f, 0.0f, Q *zNear, 0.0f
            };

            var projectionMatrix = new Lunatics.Mathematics.Matrix(projectionMatrixFloat);

            // Projection matrix abuse!
            var viewMatrix = Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up);

            //return projectionMatrix * viewMatrix;

            return(Lunatics.Mathematics.Matrix.Multiply(
                       Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up),
                       Lunatics.Mathematics.Matrix.PerspectiveFovRH(0.523598776f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f)));

            //return  Lunatics.Mathematics.Matrix.Multiply(
            //    Lunatics.Mathematics.Matrix.LookAtRH(eye, center, up),
            //    Lunatics.Mathematics.Matrix.PerspectiveFovRH(30f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f));

            //return Lunatics.Mathematics.Matrix.Multiply(
            //    Lunatics.Mathematics.Matrix.PerspectiveFovLH(30f, aspect, d_viewDistance * 0.5f, d_viewDistance * 2.0f),
            //    Lunatics.Mathematics.Matrix.LookAtLH(eye, center, up));
        }
Ejemplo n.º 4
0
        // TODO: Destructor
        //~ShaderParameterBindings()
        //{
        //    ShaderParameterBindings::ShaderParameterBindingsMap::iterator iter = d_shaderParameterBindings.begin();
        //    ShaderParameterBindings::ShaderParameterBindingsMap::iterator end = d_shaderParameterBindings.end();

        //    while (iter != end)
        //    {
        //        delete iter->second;
        //        ++iter;
        //    }

        //    d_shaderParameterBindings.clear();
        //}

        /// <summary>
        /// Adds a matrix shader parameter to the parameter bindings
        /// </summary>
        /// <param name="parameterName">
        /// The name of the parameter as used by the shader
        /// </param>
        /// <param name="matrix">
        /// The pointer to the matrix
        /// </param>
        public void SetParameter(string parameterName, ref Lunatics.Mathematics.Matrix matrix)
        {
            var shaderParam = GetParameter(parameterName);

            if (shaderParam != null && (shaderParam.GetParamType() == ShaderParamType.SPT_MATRIX_4X4))
            {
                ((ShaderParameterMatrix)shaderParam).d_parameterValue = matrix;
            }
            else
            {
                SetNewParameter(parameterName, new ShaderParameterMatrix(matrix));
            }
        }
Ejemplo n.º 5
0
 public ShaderParameterMatrix(Lunatics.Mathematics.Matrix parameterValue)
 {
     d_parameterValue = parameterValue;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets the currently active view projection matrix.
 /// </summary>
 /// <param name="viewProjectionMatrix">
 /// The view projection matrix that should be set as the new active matrix.
 /// </param>
 public virtual void SetViewProjectionMatrix(Lunatics.Mathematics.Matrix viewProjectionMatrix)
 {
     d_viewProjectionMatrix = viewProjectionMatrix;
 }