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

📄 renderlist.java

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

import javax.microedition.lcdui.Graphics;

import render.Render;

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

/**
 * @author Panxu
 *
 */
public class RenderList {

	/**
	 * 
	 */
	public RenderList() {
		super();
		// TODO 自动生成构造函数存根
		PolyList = new Poly_4D [MAX_POLY_NUM];
		//this .PolyCount = 0;
	}
	
	//最大多边形数
	public static int MAX_POLY_NUM = 1500;
	//多边形计数
	public int PolyCount = 0 ;
	//多边形表
	public Poly_4D PolyList [] = null ;
	
	/*
	 * 函数
	 */
	/**
	 * 插入多边形
	 * @param poly
	 */
	public void InsertPoly (Poly_4D poly)
	{
		if (this .PolyCount >= this .MAX_POLY_NUM)
			return ;
		this .PolyList [this .PolyCount] = poly ;
		this .PolyCount ++;
	}
	/**
	 * 插入物体
	 * @param obj
	 */
	public void InsertObj (Object_4D obj)
	{
		int t = obj .State & Object_4D.OBJ_STATE_CULL;
		
		if (t != 0)
			return ;
		for (t = 0 ; t < obj .PolyNum ; t ++)
		{
			this .PolyList [this.PolyCount] = obj.PolyList[t];
			this .PolyCount ++;
			if (this .PolyCount > this .MAX_POLY_NUM)
			{
				return ;
			}//if 
		}//for 
	}
	/**
	 * 多边形背面消影
	 */
	public void BackCull (Camera ca)
	{
		Vector4D u = null , v = null , n = null;
		for (int i = 0 ; i < this .PolyCount ; i ++)
		{
			u.Build_Vec4D(this .PolyList[i].Vlist[PolyList[i].VIndex[0]].Pos ,
					this .PolyList[i].Vlist[PolyList[i].VIndex[1]].Pos);
			v.Build_Vec4D(this .PolyList[i].Vlist[PolyList[i].VIndex[0]].Pos ,
					this .PolyList[i].Vlist[PolyList[i].VIndex[2]].Pos);
			n = v.Vec4D_Cross(u , v);
			
			v.Build_Vec4D(ca.Pos , this .PolyList[i].Vlist[PolyList[i].VIndex[0]].Pos);
			
			if (v.Vec4D_DOT(v , n) <= 0)
			{
				this .PolyList[i].State |= Poly_4D.POLY_STATE_BACK;
			}//if 
		}//for 
	}
	/**
	 * 重置多边形
	 */
	public void RestAllPoly ()
	{
		for (int i = 0 ; i < this .PolyCount ; i ++)
		{
			this .PolyList[i].State &= Poly_F4D.POLY_STATE_ACTIVE;
			this .PolyList[i] = null;
		}//for 
		this .PolyCount = 0 ;
	}
	/**
	 * 对所有多边形进行变换
	 * @param mt
	 */
	public void TransAllPoly (Matrix4X4 mt)
	{
		int t ;
		Point4D tp = null;
		for (int i = 0 ; i < this .PolyCount ; i++)
		{
			t = this .PolyList[i].State & Poly_F4D.POLY_STATE_BACK;
			
			if (t != 0)
				continue ;
			
			tp = this .PolyList[i].Tlist[this .PolyList[i].VIndex[0]].Pos.MAT4X4_MUL_PT4D(mt);
			this .PolyList[i].Tlist[this .PolyList[i].VIndex[0]].Pos = tp;
			
			tp = this .PolyList[i].Tlist[this .PolyList[i].VIndex[1]].Pos.MAT4X4_MUL_PT4D(mt);
			this .PolyList[i].Tlist[this .PolyList[i].VIndex[1]].Pos = tp;
			
			tp = this .PolyList[i].Tlist[this .PolyList[i].VIndex[2]].Pos.MAT4X4_MUL_PT4D(mt);
			this .PolyList[i].Tlist[this .PolyList[i].VIndex[2]].Pos = tp;
		}//for 
		tp = null;
	}
	
	/**
	 * 渲染所有多边形
	 */
	//public void RenderAllPoly (int [][] Buffer )
	public void RenderAllPoly (Graphics g)
	{
		int t ;
		for (int i = 0 ; i < this .PolyCount ; i ++)
		{
			t = this .PolyList [i].State & Poly_4D.POLY_STATE_BACK;
			if (t != 0)//被剔出的多边形
				continue ;
			
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.DIVW();
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.DIVW();
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.DIVW();
			
			g .drawLine((int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[1],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[1]);
			g .drawLine((int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[1],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[1]);
			g .drawLine((int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[1],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[1]);
		}//for 
	}
	
	public void RenderAllPoly (Render r , Graphics g)
	{
		int t ;
		for (int i = 0 ; i < this .PolyCount ; i ++)
		{
			t = this .PolyList [i].State & Poly_4D.POLY_STATE_BACK;
			if (t != 0)//被剔出的多边形
				continue ;
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.DIVW();
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.DIVW();
			this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.DIVW();
			
			r.DrawPoly(this .PolyList [i]);
			//r.DrawPolyByLine(this .PolyList [i]);
			/*
			g .fillTriangle((int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[0]].Pos.M[1],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[1]].Pos.M[1],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[0],
					(int)this .PolyList [i].Tlist[this .PolyList [i].VIndex[2]].Pos.M[1]);
			*/
		}//for 
	}
}

⌨️ 快捷键说明

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