Пример #1
0
	    /**
	     * 从4*4矩阵设置数值
	     * 
	     * @param matrix
	     */
	    public void setValue(Matrix4 matrix)
	    {
		    if (matrix == null)
		    {
			    return;
		    }
		    for (int i = 0; i < data.Length; i++)
		    {
			    this.data[i] = matrix.data[i];
		    }
	    }
Пример #2
0
	    /**
	     * 4x4矩阵和本向量的乘积(结果会化成w=1)
	     * 
	     * @param m
	     *            矩阵
	     */
	    public void multiplyBy(Matrix4 m)
	    {
		    float wT = 1.0f / (m.data[Matrix4.M30] * x + m.data[Matrix4.M31] * y + m.data[Matrix4.M32] * z + m.data[Matrix4.M33]);
		    x = (m.data[Matrix4.M00] * x + m.data[Matrix4.M01] * y + m.data[Matrix4.M02] * z + m.data[Matrix4.M03]) * wT;
		    y = (m.data[Matrix4.M10] * x + m.data[Matrix4.M11] * y + m.data[Matrix4.M12] * z + m.data[Matrix4.M13]) * wT;
		    z = (m.data[Matrix4.M20] * x + m.data[Matrix4.M21] * y + m.data[Matrix4.M22] * z + m.data[Matrix4.M23]) * wT;
	    }
Пример #3
0
        public static void drawTextureImage(TextureImage textrueImage, RectangleF srcRect, RectangleF destRect, Matrix4 matrix,float alpha)
	    {
            alpha = MathUtil.limitNumber(alpha, 0, 1);
            //GLGraphics.setColor((uint)(0xFFFFFF | (((int)(alpha*255))<<24)));
            GL.Color4(1.0f, 1.0f, 1.0f, alpha);
            GL.PushMatrix();
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.LineSmooth);

            //目标尺寸
            float _dw = destRect.Width;
            float _dh = destRect.Height;

            //贴图坐标
            float txW = textrueImage.TextureWidth;
            float txH = textrueImage.TextureHight;
            float ltX = srcRect.X / txW;
            float ltY = srcRect.Y / txH;
            float rbX = (srcRect.X + srcRect.Width) / txW;
            float rbY = (srcRect.Y + srcRect.Height) / txH;

            GL.BindTexture(TextureTarget.Texture2D, textrueImage._name);
            matrixDraw.identity();
            matrixDraw.preTranslate(destRect.X, destRect.Y);
            if (matrix != null)
            {
                matrix.multiply(matrixDraw, matrixDraw);
            }
            float[] data = matrixDraw.getValue();
            GL.MultMatrix(data);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(ltX, ltY);
            GL.Vertex3(0, 0, 0);
            GL.TexCoord2(rbX, ltY);
            GL.Vertex3(_dw, 0, 0);
            GL.TexCoord2(rbX, rbY);
            GL.Vertex3(_dw, _dh, 0);
            GL.TexCoord2(ltX, rbY);
            GL.Vertex3(0, _dh, 0);
            GL.End();


            GL.Disable(EnableCap.Texture2D);
		    GL.PopMatrix();
	    }
Пример #4
0
 public Matrix4(Matrix4 t)
 {
     setData(t.data);
 }
Пример #5
0
	    /**
	     * 逆反矩阵,将结果赋值给指定结果
	     */
	    public bool inverse(Matrix4 res)
	    {
		    return inverse(this.getValue(), res.getValue());
	    }
Пример #6
0
	    /**
	     * 4x4矩阵转置(矩阵的行和列互换。)
	     */
	    public Matrix4 transpose()
	    {
		    Matrix4 m = new Matrix4();
		    for (int i = 0; i < 16; i++)
		    {
			    m.data[i] = data[TR[i]];
		    }
		    return m;
	    }
Пример #7
0
	    /**
	     * 两个4×4矩阵的乘积(当前矩阵左乘M,并将结果赋值给传入的矩阵。)
	     * 
	     * @param m
	     * @param res
	     */
	    public void multiply(Matrix4 m, Matrix4 res)
	    {
		    multiply(this.getValue(), m.getValue(), res.getValue());
	    }
Пример #8
0
	    /**
	     * 两个4×4矩阵的乘积,并将结果赋给当前矩阵(当前矩阵左乘M。)
	     * 
	     * @param m
	     */
	    public void multiply(Matrix4 m)
	    {
		    multiply(this.getValue(), m.getValue(), this.getValue());
	    }