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

📄 render.java

📁 一个J2ME的3D 一个J2ME的3D 一个J2ME的3D
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			ey = y3 .FIX16_TO_INT();
			midy = y2 .FIX16_TO_INT();		
		}
		//y1 ,x1不再使用~~被最为临时变量
		y1 .Data = x1 .Data;
		//裁减
		if (ey > this .ScreenHSub1)
			ey = this .ScreenHSub1;
		/*
		for (drawy = sy ; drawy < ey ; drawy ++)
		{
			//分割三角形
			if (drawy == midy)
			{
				if (y2 .Data > y3 .Data)
				{
					drawsx = x3.FIX16_TO_INT();
					ldx .FLOAT_TO_FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index3].Pos.M[0]) /
				(poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index3].Pos.M[1])) ;
				}//if 
				else 
				{
					drawex = x2.FIX16_TO_INT();
					rdx .FLOAT_TO_FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index2].Pos.M[0]) /
							(poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index2].Pos.M[1])) ;
				}//if 
			}//if 
			//绘制
			this .FillFlatLine(drawy , drawsx , drawex , poly .Color);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.FIX16_TO_INT();
			drawex = y1.FIX16_TO_INT();
		}//for
		*/
		if (sy < 0)
		{
			drawsx = ((-sy)*ldx.Data)>>16;
			drawex = ((-sy)*rdx.Data)>>16;
			sy = 0;
		}//if 
		for (drawy = sy ; drawy <= midy ; drawy ++)
		{
			//绘制
			this .FillFlatLine(drawy , drawsx , drawex , poly .Color);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.Data >> FIX16.FIX16_SHIFT;
			drawex = y1.Data >> FIX16.FIX16_SHIFT;
		}//for
		//三角形分段
		if (y2 .Data > y3 .Data)
		{
			drawsx = x3.Data >> FIX16.FIX16_SHIFT;
			ldx .FLOAT_TO_FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index3].Pos.M[0]) /
		(poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index3].Pos.M[1])) ;
		}//if 
		else 
		{
			drawex = x2.Data >> FIX16.FIX16_SHIFT;
			rdx .FLOAT_TO_FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index2].Pos.M[0]) /
					(poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index2].Pos.M[1])) ;
		}//if 
		for ( ; drawy <= ey ; drawy ++)
		{
			//绘制
			this .FillFlatLine(drawy , drawsx , drawex , poly .Color);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.Data >> FIX16.FIX16_SHIFT;
			drawex = y1.Data >> FIX16.FIX16_SHIFT;
		}//for
		
	}
	/**
	 * 多边形的插值着色 
	 * @param poly 
	 */
	public void DrawPolyGOURAUD (Poly_4D poly)
	{
		int temp ;
		//顶点索引
		int Index1 = poly.VIndex[0] , Index2 = poly.VIndex[1] ,
		Index3 = poly.VIndex[2];
		//顶点排序
		if (poly.Tlist[Index1].Pos.M[1] > poly.Tlist[Index2].Pos.M[1])
		{
			temp = Index1;
			Index1 = Index2;
			Index2 = temp;
		}
		if (poly.Tlist[Index1].Pos.M[1] > poly.Tlist[Index3].Pos.M[1])
		{
			temp = Index1;
			Index1 = Index3;
			Index3 = temp;
		}
		if (poly.Tlist[Index3].Pos.M[0] > poly.Tlist[Index2].Pos.M[0])
		{
			temp = Index2;
			Index2 = Index3;
			Index3 = temp;
		}
		/////////////////////////////////////////////////////
		FIX16 x1 = new FIX16 (poly.Tlist[Index1].Pos.M[0]);
		FIX16 y1 = new FIX16 (poly.Tlist[Index1].Pos.M[1]);
		FIX16 x2 = new FIX16 (poly.Tlist[Index2].Pos.M[0]);
		FIX16 y2 = new FIX16 (poly.Tlist[Index2].Pos.M[1]);
		FIX16 x3 = new FIX16 (poly.Tlist[Index3].Pos.M[0]);
		FIX16 y3 = new FIX16 (poly.Tlist[Index3].Pos.M[1]);
		
		float divldy = 1 / (poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index1].Pos.M[1]);
		float divrdy = 1 / (poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index1].Pos.M[1]);
		FIX16 ldx = new FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index1].Pos.M[0]) * divldy);
		FIX16 rdx = new FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index1].Pos.M[0]) * divrdy);
		
		int drawy , drawsx = x1.FIX16_TO_INT(), drawex = x1 .FIX16_TO_INT();
		int sy = y1.FIX16_TO_INT() , ey , midy ;
		
		//色彩插值数据
		int c1 =(((poly.Tlist[Index1].r & 255)<< 16)+ 
				((poly.Tlist[Index1].g & 255) << 8)+ (poly.Tlist[Index1].b & 255));
		
		int c2 =(((poly.Tlist[Index2].r & 255)<< 16)+ 
				((poly.Tlist[Index2].g & 255) << 8)+ (poly.Tlist[Index2].b & 255));
		
		int c3 =(((poly.Tlist[Index3].r & 255)<< 16)+ 
				((poly.Tlist[Index3].g & 255) << 8)+ (poly.Tlist[Index3].b & 255));
		
		FIX16 ldc = new FIX16 ();
		ldc .Data = (int) (((c2 - c1) << 16) * divldy);
		FIX16 rdc = new FIX16 ();
		rdc .Data = (int) (((c3 - c1) << 16) * divrdy);
		
		int drawsc = c1, drawec = c1;
		
		FIX16 addlc = new FIX16 ();
		addlc .Data = 0 ;
		FIX16 addrc = new FIX16 ();
		addrc .Data = 0 ;
		
		if (y2 .Data > y3 .Data)
		{
			ey = y2 .FIX16_TO_INT();
			midy = y3 .FIX16_TO_INT();
		}
		else 
		{
			ey = y3 .FIX16_TO_INT();
			midy = y2 .FIX16_TO_INT();		
		}
		//y1 ,x1不再使用~~被最为临时变量
		y1 .Data = x1 .Data;
		
		//裁减
		if (ey > this .ScreenHSub1)
			ey = this .ScreenHSub1;
		
		if (sy < 0)
		{
			drawsx = ((-sy)*ldx.Data)>>16;
			drawex = ((-sy)*rdx.Data)>>16;
			sy = 0;
		}//if 
		
		for (drawy = sy ; drawy <= midy ; drawy ++)
		{
			//绘制
			this .FillFlatLineGOURAUD(drawy , drawsx , drawex , drawsc, drawec);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.FIX16_TO_INT();
			drawex = y1.FIX16_TO_INT();
			
			drawsc  = c1 + (addlc .Data >> 16);
			drawec  = c1 + (addrc .Data >> 16);
			addlc.Data += ldc.Data ;
			addrc.Data += rdc.Data ;
		}//for 
		if (y2 .Data > y3 .Data)
		{
			divldy = 1 / (poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index3].Pos.M[1]);
			drawsx = x3.FIX16_TO_INT();
			ldx .FLOAT_TO_FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index3].Pos.M[0]) *
					divldy );
			addlc.Data = 0;
			drawsc = c3;
			ldc .Data = (int) (((c2 - c3) << 16) * divldy);
		}//if 
		else 
		{
			divrdy = 1 / (poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index2].Pos.M[1]);
			drawex = x2.FIX16_TO_INT();
			rdx .FLOAT_TO_FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index2].Pos.M[0]) *
					divrdy );
			addrc.Data = 0;
			drawec = c2;
			rdc .Data = (int) (((c3 - c2) << 16) * divrdy);
		}//if 
		for (drawy = midy + 1 ; drawy <= midy ; drawy ++)
		{
			//绘制
			this .FillFlatLineGOURAUD(drawy , drawsx , drawex , drawsc, drawec);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.FIX16_TO_INT();
			drawex = y1.FIX16_TO_INT();
			
			drawsc  = c1 + (addlc .Data >> 16);
			drawec  = c1 + (addrc .Data >> 16);
			addlc.Data += ldc.Data ;
			addrc.Data += rdc.Data ;
		}//for 
	}
	/**
	 * 三角形的渲染~线筐模式
	 * @param poly
	 */
	public void DrawPolyByLine (Poly_4D poly)
	{		
		this .DrawLine((int)poly .Tlist[poly.VIndex[0]].Pos.M[0] , (int)poly .Tlist[poly.VIndex[0]].Pos.M[1],
				(int)poly .Tlist[poly.VIndex[1]].Pos.M[0], (int)poly .Tlist[poly.VIndex[1]].Pos.M[1],
				poly .Color);
		this .DrawLine((int)poly .Tlist[poly.VIndex[0]].Pos.M[0] , (int)poly .Tlist[poly.VIndex[0]].Pos.M[1],
				(int)poly .Tlist[poly.VIndex[2]].Pos.M[0], (int)poly .Tlist[poly.VIndex[2]].Pos.M[1],
				poly .Color);
		this .DrawLine((int)poly .Tlist[poly.VIndex[1]].Pos.M[0] , (int)poly .Tlist[poly.VIndex[1]].Pos.M[1],
				(int)poly .Tlist[poly.VIndex[2]].Pos.M[0], (int)poly .Tlist[poly.VIndex[2]].Pos.M[1],
				poly .Color);
	}
	/**
	 * 仿射渲染
	 * @param poly
	 */
	public void DrawPolyTextrue (Poly_4D poly)
	{
		int temp ;
		//顶点索引
		int Index1 = poly.VIndex[0] , Index2 = poly.VIndex[1] ,
		Index3 = poly.VIndex[2];
		//顶点排序
		if (poly.Tlist[Index1].Pos.M[1] > poly.Tlist[Index2].Pos.M[1])
		{
			temp = Index1;
			Index1 = Index2;
			Index2 = temp;
		}
		if (poly.Tlist[Index1].Pos.M[1] > poly.Tlist[Index3].Pos.M[1])
		{
			temp = Index1;
			Index1 = Index3;
			Index3 = temp;
		}
		if (poly.Tlist[Index3].Pos.M[0] > poly.Tlist[Index2].Pos.M[0])
		{
			temp = Index2;
			Index2 = Index3;
			Index3 = temp;
		}
		FIX16 x1 = new FIX16 (poly.Tlist[Index1].Pos.M[0]);
		FIX16 y1 = new FIX16 (poly.Tlist[Index1].Pos.M[1]);
		FIX16 x2 = new FIX16 (poly.Tlist[Index2].Pos.M[0]);
		FIX16 y2 = new FIX16 (poly.Tlist[Index2].Pos.M[1]);
		FIX16 x3 = new FIX16 (poly.Tlist[Index3].Pos.M[0]);
		FIX16 y3 = new FIX16 (poly.Tlist[Index3].Pos.M[1]);
		
		FIX16 ldx = new FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index1].Pos.M[0]) /
				(poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index1].Pos.M[1]));
		FIX16 rdx = new FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index1].Pos.M[0]) /
				(poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index1].Pos.M[1]));
		
		int drawy , drawsx = x1.FIX16_TO_INT(), drawex = x1 .FIX16_TO_INT();
		int sy = y1.FIX16_TO_INT() , ey , midy ;
		if (y2 .Data > y3 .Data)
		{
			ey = y2 .FIX16_TO_INT();
			midy = y3 .FIX16_TO_INT();
		}
		else 
		{
			ey = y3 .FIX16_TO_INT();
			midy = y2 .FIX16_TO_INT();		
		}
		//y1 ,x1不再使用~~被最为临时变量
		y1 .Data = x1 .Data;
		//裁减
		if (ey > this .ScreenHSub1)
			ey = this .ScreenHSub1;
		if (sy < 0)
		{
			drawsx = ((-sy)*ldx.Data)>>16;
			drawex = ((-sy)*rdx.Data)>>16;
			sy = 0;
		}//if 
		for (drawy = sy ; drawy <= midy ; drawy ++)
		{
			//绘制
			this .FillFlatLine(drawy , drawsx , drawex , poly .Color);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.Data >> FIX16.FIX16_SHIFT;
			drawex = y1.Data >> FIX16.FIX16_SHIFT;
		}//for
		//三角形分段
		if (y2 .Data > y3 .Data)
		{
			drawsx = x3.Data >> FIX16.FIX16_SHIFT;
			ldx .FLOAT_TO_FIX16 ((poly.Tlist[Index2].Pos.M[0] - poly.Tlist[Index3].Pos.M[0]) /
		(poly.Tlist[Index2].Pos.M[1] - poly.Tlist[Index3].Pos.M[1]));
		}//if 
		else 
		{
			drawex = x2.Data >> FIX16.FIX16_SHIFT;
			rdx .FLOAT_TO_FIX16 ((poly.Tlist[Index3].Pos.M[0] - poly.Tlist[Index2].Pos.M[0]) /
					(poly.Tlist[Index3].Pos.M[1] - poly.Tlist[Index2].Pos.M[1])) ;
		}//if 
		for (drawy = midy + 1 ; drawy <= ey ; drawy ++)
		{
			//绘制
			this .FillFlatLine(drawy , drawsx , drawex , poly .Color);
			x1 .Data += ldx .Data;
			y1 .Data += rdx .Data;
			drawsx = x1.Data >> FIX16.FIX16_SHIFT;
			drawex = y1.Data >> FIX16.FIX16_SHIFT;
		}//for
	}
	/**
	 * 修正映射渲染
	 * @param poly
	 */
	public void DrawPolyTexCorrect (Poly_4D poly)
	{
		
	}
	
	/**
	 * 清除缓存
	 *
	 */
	public void CleanRender ()
	{
		int i ;
		for (i = 0 ; i < this.ScreenBuffer.length ; i ++)
		{
			this .ScreenBuffer [i] = 0;
		}//for 
	}
	/**
	 * 填充指定区域
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 */
	public void FillRect (int x , int y , int w , int h , int Color)
	{
		if (x > this .ScreenWSub1 || x + w < 0 || y > this .ScreenHSub1 ||
				y + h < 0)
			return ;
		if (x < 0)
		{
			w += x ;
			x = 0 ;
		}//if 
		if (y < 0)
		{
			h += y ;
			y = 0;
		}//if 
		w = w > this .ScreenWSub1 ? (this .ScreenWSub1 - x) : w ;
		h = h > this .ScreenHSub1 ? (this .ScreenHSub1 - y) : h ;
		
		int ex = x + w ;
		for (int i = 0 ; i <= h ; i ++)
		{
			//System .out .println("RunHere");
			this .FillFlatLine(y , x ,ex, Color);
			y ++ ;
		}//for 
	}
}

⌨️ 快捷键说明

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