package newm3g; import javax.microedition.lcdui.game.GameCanvas; import javax.microedition.m3g.*; public class PlayerCanvas extends GameCanvas { static final int POGOROO_MOVE_GROUP_TRANSFORM_ID = 554921620; static final int CAMERA_GROUP_TRANSFORM_ID = 769302310; private float m_fDirRoo = 0.0f; private float m_fDirCam = 0.0f; public PlayerCanvas(boolean bSuppress) { super(bSuppress); } public void run() throws Exception { World1 wMyWorld; Group grTRoo; Group grTCams; Graphics3D g3D = Graphics3D.getInstance(); /** load the world from the M3D file */ wMyWorld = (World1)Loader.load("/skaterboy.m3g")[0]; grTRoo = (Group) wMyWorld.find(POGOROO_MOVE_GROUP_TRANSFORM_ID); grTCams = (Group) wMyWorld.find(CAMERA_GROUP_TRANSFORM_ID); long lStart, lElapsed, lTime = 0; while(true) { lStart = System.currentTimeMillis(); g3D.bindTarget(getGraphics()); try { wMyWorld.animate((int)lTime); g3D.render(wMyWorld); } finally { g3D.releaseTarget(); } flushGraphics(); lElapsed = System.currentTimeMillis() - lStart; lTime += (lElapsed < 100) ? 100 : (int)lElapsed; if(lElapsed < 100) Thread.sleep(100 - lElapsed); switch(getKeyStates()) { /** ����� ������� ����... */ case GameCanvas.LEFT_PRESSED: m_fDirRoo += 5f; m_fDirCam -= 5f; grTRoo.setOrientation(m_fDirRoo, 0, 0, 1); grTCams.setOrientation(m_fDirCam, 0, 0, 1); break; /** ����� ������� ���... */ case GameCanvas.RIGHT_PRESSED: m_fDirRoo -= 5f; m_fDirCam += 5f; grTRoo.setOrientation(m_fDirRoo, 0, 0, 1); grTCams.setOrientation(m_fDirCam, 0, 0, 1); break; case GameCanvas.FIRE_PRESSED: /** ������� �� ����� � �� ����� ��������... */ return; default: if (m_fDirCam > 4.9f) { m_fDirCam -= 5.0f; } else { if (m_fDirCam < -4.9f) { m_fDirCam += 5.0f; } else { m_fDirCam = 0.0f; } } grTCams.setOrientation(m_fDirCam, 0, 0, 1); } } } }