⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera.java

📁 一个J2ME的3D 一个J2ME的3D 一个J2ME的3D
💻 JAVA
字号:
/**
 * 
 */
package object3d;

import Math.MathTool;
import Math.Matrix4X4;
import Math.Point4D;
import Math.Vector4D;

/**
 * @author PanXu
 *
 */
public class Camera {

	/**
	 * 
	 */
	public Camera() {
		super();
		// TODO 自动生成构造函数存根
	}
	
	int State ;
	Point4D Pos = new Point4D ();
	int Type ;
	
	//欧拉相机朝向
	Vector4D Dir = new Vector4D();
	//UVN相机朝向
	Point4D AimPos = new Point4D ();
	Vector4D n = new Vector4D ();
	Vector4D v = new Vector4D ();
	Vector4D u = new Vector4D ();
	
	//世界坐标到相机坐标
	public Matrix4X4 wtoc = new Matrix4X4();
	//相机坐标到视平面坐标
	public Matrix4X4 ctov = new Matrix4X4();
	//平面坐标到屏幕坐标
	public Matrix4X4 vtos = new Matrix4X4();
	//最终变换矩阵
	public Matrix4X4 finalmat = new Matrix4X4 ();
	
	//视距
	float Dist ;
	float DivDist ;//视距的倒数
	//视角
	int ViewAng ;
	//屏幕的尺寸
	float ScreenW , ScreenH ;
	float ScreenHalfW , ScreenHalfH ;
	//宽高比
	float wdivh ;
	//视平面尺寸
	float Vieww , Viewh ;
	
	//远截面
	float FarClip;
	
	public void InitCamera (int Type , int State ,Point4D Pos ,
			Vector4D Dir , Point4D AimPt , int ViewAng , float Sw , float Sh ,
			float FarClip)
	{		
		this .Type = Type ;
		this .State = State ;
		this .Pos = Pos ;
		
		this .Dir = Dir ;
		this .AimPos = AimPt ;
		
		this .ViewAng = ViewAng;
		
		this .ScreenW = Sw ;
		this .ScreenHalfW = Sw * 0.5f;
		this .ScreenH = Sh ;
		this .ScreenHalfH = Sh * 0.5f;
		
		this .wdivh = Sw / Sh;
		
		this .Vieww = 2.0f;
		
		this .Viewh = Vieww / this .wdivh;
		
		this .FarClip = FarClip ;
		
		this .Dist = 1.0f / MathTool.Tan (ViewAng >> 1); 
		
		this .DivDist = 1 / Dist ;
	}
	
	/*
	 * 欧拉相机
	 */
	/**
	 * 创建相机坐标变换矩阵
	 *
	 */
	public void BuildWtoCMat ()
	{
		
		Matrix4X4 t_mat = new Matrix4X4 ();
		
		wtoc .Set_MOVMAT(-this .Pos.M[0] ,-this .Pos.M[1],-this .Pos.M[2]);
		
		t_mat .Set_CIRMAT(-(int)this .Dir.M [0] , -(int)this .Dir.M [1] ,
				-(int)this .Dir.M [2]);
		this .wtoc = this .wtoc.MAT4X4_MUL_Stack(wtoc , t_mat);
		t_mat = null;
	}
	
	/**
	 * 创建视平面投影矩阵
	 */
	public void BulidCtoVMat ()
	{
		this .ctov .InitMat4X4 (
				1 , 0 , 0 , 0 ,
				0 , 1 , 0 , 0 ,
				0 , 0 , 1 , this .DivDist ,
				0 , 0 , 0 , 0 );
	}
	
	/**
	 * 创建视平面到屏幕的投影矩阵
	 */
	public void BuildVtoSMat ()
	{
		float alpha = this .ScreenW * 0.5f - 0.5f;
		float beta = this .ScreenH * 0.5f - 0.5f;
		
		this .vtos .InitMat4X4(
				alpha , 0 , 0 , 0 ,
				0 , -beta , 0 , 0 ,
				0 , 0 , 1 , 0 ,
				alpha , beta , 0 , 1);
	}
	/**
	 * 创建最终变换矩阵
	 */
	public void BuildFinalMat ()
	{
		Matrix4X4 t_mat = new Matrix4X4 ();
		/*
		this .wtoc.Print();
		
		this .ctov.Print();
		
		this .vtos.Print();
		*/
		t_mat .MAT4X4_MUL(this .wtoc , this .ctov);
		
		this .finalmat .MAT4X4_MUL(t_mat , this .vtos);
		
		//this .finalmat .Print();
		
		t_mat = null;
	}
	/*
	 * UVN相机
	 */
	/**
	 * 创建UVN相机变换矩阵
	 */
	public void BuildUVNWtoV ()
	{
		
	}
}

⌨️ 快捷键说明

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