point4d.java

来自「一个J2ME的3D 一个J2ME的3D 一个J2ME的3D」· Java 代码 · 共 75 行

JAVA
75
字号
/**
 * 
 */
package Math;

/**
 * @author PanXu
 *
 */
public class Point4D {
	/**
	 * 
	 */
	public static final int X = 0 ;
	public static final int Y = 0 ;
	public static final int Z = 0 ;
	public static final int W = 0 ;
	
	public float M[] = null;
	public Point4D() {
		super();
		// TODO 自动生成构造函数存根
		M = new float [4];
		M[0] = 0 ;
		M[1] = 0 ;
		M[2] = 0 ;
		M[3] = 0 ;
	}
	public Point4D(float x,float y,float z) {
		super();
		// TODO 自动生成构造函数存根
		M = new float [4];
		M[0] = x ;
		M[1] = y ;
		M[2] = z ;
		M[3] = 1.0f;
	}
	public void Init (float x ,float y , float z)
	{
		this .M[0] = x;
		this .M[1] = y;
		this .M[2] = z;
		this .M[3] = 1.0f;
	}
	//矩阵乘以点
	public Point4D MAT4X4_MUL_PT4D (Matrix4X4 Mat)
	{
		Point4D res = new Point4D();
		res .M[0] = M[0] * Mat.M[0][0] + M[1] * Mat.M[1][0] + M[2] * Mat.M[2][0] + M[3] * Mat.M[3][0];
		res .M[1] = M[0] * Mat.M[0][1] + M[1] * Mat.M[1][1] + M[2] * Mat.M[2][1] + M[3] * Mat.M[3][1];
		res .M[2] = M[0] * Mat.M[0][2] + M[1] * Mat.M[1][2] + M[2] * Mat.M[2][2] + M[3] * Mat.M[3][2];
		res .M[3] = M[0] * Mat.M[0][3] + M[1] * Mat.M[1][3] + M[2] * Mat.M[2][3] + M[3] * Mat.M[3][3];
		return res ;
	}
	/*
	 * 规格化
	 */
	public void DIVW(){
		float Divw = 1 / this .M[3];
		this .M[0] *= Divw;
		this .M[1] *= Divw;
		this .M[2] *= Divw;
	}
	/**
	 * 打印(调试)
	 *
	 */
	public void Point ()
	{
		System .out .println(this .M[0] + "     " + this .M[1] + "     " +
				this .M[2] + "     " + this .M[3]);
		System .out .println();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?