示例#1
0
        private void _setProgramConstants_Matrix(geom.Matrix3D matrix3D, int startindex, bool transpose)
        {
            if (transpose)
            {
                matrix3D.transpose();
            }

            programConstants.registers[startindex]     = new float4(matrix3D.M00, matrix3D.M01, matrix3D.M02, matrix3D.M03);
            programConstants.registers[startindex + 1] = new float4(matrix3D.M10, matrix3D.M11, matrix3D.M12, matrix3D.M13);
            programConstants.registers[startindex + 2] = new float4(matrix3D.M20, matrix3D.M21, matrix3D.M22, matrix3D.M23);
            programConstants.registers[startindex + 3] = new float4(matrix3D.M30, matrix3D.M31, matrix3D.M32, matrix3D.M33);
        }
示例#2
0
        public void setProgramConstantsFromMatrix(geom.Matrix3D matrix3D, int startindex, bool transpose)
        {
            if (startindex < ProgramConstants.USERDEFINE_STARTIDX)
            {
                throw new ArgumentException("之前行被保留");
            }

            if (transpose)
            {
                matrix3D.transpose();
            }

            programConstants.registers[startindex]     = new float4(matrix3D.M00, matrix3D.M01, matrix3D.M02, matrix3D.M03);
            programConstants.registers[startindex + 1] = new float4(matrix3D.M10, matrix3D.M11, matrix3D.M12, matrix3D.M13);
            programConstants.registers[startindex + 2] = new float4(matrix3D.M20, matrix3D.M21, matrix3D.M22, matrix3D.M23);
            programConstants.registers[startindex + 3] = new float4(matrix3D.M30, matrix3D.M31, matrix3D.M32, matrix3D.M33);
        }
示例#3
0
        public static Matrix3D lookAtLH(float eyex, float eyey, float eyez,
                                        float lookatx, float lookaty, float lookatz,
                                        float upx, float upy, float upz)
        {
            // 相机UVN
            //N= lookAt- eye
            //U=UP * N
            //V = N *U

            Vector3 lookat = new Vector3(lookatx, lookaty, lookatz);
            Vector3 eye    = new Vector3(eyex, eyey, eyez);
            Vector3 up     = new Vector3(upx, upy, upz);


            var N = lookat - eye;

            var U = up.cross(N);            //Vector3.Cross(up, N);

            var V = N.cross(U);             //Vector3.Cross(N, U);

            N.normalize();
            U.normalize();
            V.normalize();


            Matrix3D m1 = new Matrix3D(U.x, U.y, U.z, 0.0f,
                                       V.x, V.y, V.z, 0.0f,
                                       N.x, N.y, N.z, 0.0f,
                                       0.0f, 0.0f, 0.0f, 1.0f);
            Matrix3D m2 = new Matrix3D(

                1.0f, 0.0f, 0.0f, -eyex,
                0.0f, 1.0f, 0.0f, -eyey,
                0.0f, 0.0f, 1.0f, -eyez,
                0.0f, 0.0f, 0.0f, 1.0f

                );

            m1.append(m2);
            m1.transpose();
            return(m1);
        }
示例#4
0
        public static Matrix3D perspectiveOffCenterLH(float left,
                                                      float right,
                                                      float bottom,
                                                      float top,
                                                      float zNear,
                                                      float zFar)
        {
            float a = zFar / (zFar - zNear);
            float b = -zNear * zFar / (zFar - zNear);


            Matrix3D m = new Matrix3D(
                2.0f * zNear / (right - left), 0.0f, (left + right) / (left - right), 0.0f,
                0.0f, 2.0f * zNear / (top - bottom), (bottom + top) / (bottom - top), 0.0f,
                0.0f, 0.0f, a, b,
                0.0f, 0.0f, 1.0f, 0.0f
                );

            m.transpose();
            return(m);
        }