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

📄 screen.java

📁 一个J2ME的3D 一个J2ME的3D 一个J2ME的3D
💻 JAVA
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

import object3d.*;
import render.Render;
import Math.*;

import com.nokia.mid.ui.FullCanvas;

public class Screen extends FullCanvas implements Runnable {

	MIDlet Mid = null;

	Render ren = new Render ();
	
	int ScreenW, ScreenH;

	Point4D camera_pos = new Point4D();

	Vector4D camera_dir = new Vector4D ();
	
	Camera camera = new Camera();
	
	Poly_4D poly = new Poly_4D();
	
	Point4D poly_pos = new Point4D();
	
	Vector4D poly_dir = new Vector4D ();

	RenderList rl = new RenderList();

	Vertex4D Vlist[] = new Vertex4D [3];

	Vertex4D Tlist[] = new Vertex4D [3];

	public Screen(MIDlet Mid) {
		super();
		///////////////////
		MathTool .InitSCos();
		
		this .Mid = Mid;
		this.ScreenW = this.getWidth();
		this.ScreenH = this.getHeight();
		
		this .ren.InitRender(0,0,this .ScreenW , this .ScreenH , this .ScreenW ,
				this .ScreenH);		

		this.camera_pos.Init(0, 0, 0);
		this.camera_dir.Init(0, 0, 0);

		this.camera.InitCamera(0, 0, this.camera_pos, this.camera_dir, null,
				90, this.ScreenW, this.ScreenH, 100);
		
		//Vlist = new Vertex4D [3];
		Vlist [0] = new Vertex4D ();
		Vlist [1] = new Vertex4D ();
		Vlist [2] = new Vertex4D ();
		//Tlist = new Vertex4D [3];
		Tlist [0] = new Vertex4D ();
		Tlist [1] = new Vertex4D ();
		Tlist [2] = new Vertex4D ();		
		/**
		 * 设置多边形
		 */
		this .poly_dir.Init(0 , 0, 0 );
		this .poly_pos.Init(0 ,0 , 100);
		
		this .poly .Dir = this .poly_dir;
		this .poly .Pos = this .poly_pos;
		
		Vlist [0].Pos.Init(-60 , -60 , 0);
		Vlist [1].Pos.Init( 60 , -60 , 0);
		Vlist [2].Pos.Init(  0 ,  60 , 0);
		
		this .poly.Vlist = this .Vlist;
		this .poly.Tlist = this .Tlist;
		this .poly.VIndex[0] = 0 ;
		this .poly.VIndex[1] = 1 ;
		this .poly.VIndex[2] = 2 ;
		
		/**
		 * 初始化相机
		 */
		this .camera.BulidCtoVMat();
		
		this .camera.BuildVtoSMat();
		//启动线程
		new Thread(this).start();
	}

	Graphics g = null; //全局画笔
	
	Matrix4X4 temat;
	
	protected void paint(Graphics g) {
		// TODO 自动生成方法存根		
		this.g = g ;
		//g .fillRect( 0 , 0, this .ScreenW , this .ScreenH);
		ren .CleanRender();
		this .poly_dir.M[1] += 2;
		//创建变换矩阵
		this .camera.BuildWtoCMat();
		
		this .camera.BuildFinalMat();
		//this .camera.finalmat.Print();

		//物体局部变换
		temat = this .poly.BuildTranMat();
		this .poly.TranToWorld(temat);
		
		//多边形插入渲染列表
		this .rl.InsertPoly(this.poly);
		//变换所有多边形到屏幕
		this .rl.TransAllPoly(this .camera.finalmat);
		
		//渲染
		g .setColor(255 , 0 , 0);
		//this .rl.RenderAllPoly(g);
		this .rl.RenderAllPoly(this.ren , g);
		
		//重置渲染列表
		this .rl.RestAllPoly();
		
		ren .EndRander(g);
	}
	
	long oldtime , nowtime ;
	public void run() {
		// TODO 自动生成方法存根
		while (true)
		{
			oldtime = System .currentTimeMillis();
			this .repaint();
			nowtime = System .currentTimeMillis();
			//System .out .println(nowtime - oldtime);
			try {
				Thread.sleep(30);
			} catch (InterruptedException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}//where
	}
}

⌨️ 快捷键说明

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