티스토리 뷰

Computer/Mobile3D

5. 3D Draw

DogBull 2007.07.30 20:29
사용자 삽입 이미지


1. Test.java
import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class Test extends MIDlet{ //############################################################################################### //# MIDlet 클래스 추상 메소드 //# [MIDlet 생명주기 1] 응용프로그램이 시작 될 때. //# canvas 클래스의 쓰레드가 live인 동안 응용프로그램은 Activate 상태이다. //############################################################################################### public void startApp(){ Display display= Display.getDisplay(this); //현재 MIDlet에 해당하는 Display 객체를 얻는다. Canvas canvas= new Canvas3D(); //Canvas 인스턴스 생성. display.setCurrent(canvas); //파라미터(canvas)를 display한다. } //############################################################################################### //# MIDlet 클래스 추상 메소드 정의 //# [MIDlet 생명주기 2] 전화가 왔을 때와 같은 MIDlet 사용 불가 상태. //############################################################################################### public void pauseApp(){} //############################################################################################### //# MIDlet 클래스 추상 메소드 //# [MIDlet 생명주기 3] 종료될 때. //############################################################################################### public void destroyApp(boolean b){} }



2. Canvas3D.java import java.io.*; import javax.microedition.lcdui.*; import com.mascotcapsule.micro3d.v3.*; public class Canvas3D extends Canvas implements Runnable, Const{ public Canvas3D(){ effect= new Effect3D(); trans= new AffineTrans(); objPos= new Vector3D(0, 0, 0); look= new Vector3D(0, 0, -300000); up= new Vector3D(0, 4096, 0); trans.setViewTrans(objPos, look, up); layout= new FigureLayout(trans, 1024, 1024, CENTERX, CENTERY); Thread thread= new Thread(this); //스레드 인스턴스 생성. thread.start(); //스레드 시작. } //########################################################################################## //# Runnable 인터페이스 구현 //# 응용프로그램의 메인 루프 //########################################################################################## public void run(){ while(true){ repaint(); try{ Thread.sleep(100); //초당 10프레임 (예상치) }catch(Exception e){ System.out.println("쓰레드 슬립 에러"); } } } //########################################################################################## //# Canvas 클래스의 paint(...)추상 메소드 구현 //# 화면에 무언가를 그린다.(Canvas 인스턴스가 생성 되거나 repaint() 메소드 호출시 실행된다) //########################################################################################## public void paint(Graphics g){ g.setColor(0x333333); g.fillRect(0, 0, WIDTH, HEIGHT); ((Graphics3D)g).renderPrimitives(tstTex, 0, 0, layout, effect, Graphics3D.PRIMITVE_QUADS | Graphics3D.PDATA_COLOR_PER_COMMAND | Graphics3D.PDATA_NORMAL_NONE | Graphics3D.PDATA_TEXURE_COORD_NONE, 1, vtxCoord, norCoord, texCoord, colCoord); ((Graphics3D)g).flush(); } private final int WIDTH= this.getWidth(); //화면의 넓이(사용가능한) private final int HEIGHT= this.getHeight(); //화면의 높이(사용가능한) private final int CENTERX= WIDTH >> 1; //화면의 X축 중심 private final int CENTERY= HEIGHT >> 1; //화면의 Y축 중심
private Vector3D objPos; private Vector3D look; private Vector3D up; private AffineTrans trans; private FigureLayout layout; private Texture sphTex; private Texture tstTex; private Effect3D effect; private int vtxCoord[]= {-300, -300, -1, -300, 300, -1, 300, 300, -1, 300, -300, -1}; private int norCoord[]= {}; private int texCoord[]= {}; private int colCoord[]= {0xff0000}; }

'Computer > Mobile3D' 카테고리의 다른 글

5. Color Cube  (0) 2007.07.30
5. 3D Draw  (0) 2007.07.30
4. Thread 를 이용한 화면 갱신  (1) 2007.07.30
3. Hello MIDlet  (0) 2007.07.30
2. MIDlet 생명 주기  (0) 2007.07.30
1. Mobile3D  (0) 2007.07.30
댓글
Total
168,054
Today
21
Yesterday
40