import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; import javax.microedition.m3g.*; public class GF extends MIDlet { MyCanvas d=new MyCanvas(); public void startApp() { try{ d.init(); }catch(Exception e){} Display.getDisplay(this).setCurrent(d); } public void pauseApp() {} public void destroyApp(boolean unc) {} public class MyCanvas extends Canvas implements CommandListener{ Graphics3D graphics3d; Camera camera; Light light; float angle = 0.0f; Transform transform = new Transform(); Background background = new Background(); VertexBuffer vbuffer; IndexBuffer indexbuffer; Appearance appearance; Material material = new Material(); Image image; public MyCanvas() {} // Устанавливаем Displayable для прослушивания команд от пользователя //setCommandListener(new CommandListener() { void init() throws Exception { graphics3d=Graphics3D.getInstance(); camera = new Camera(); camera.setPerspective( 60.0f, (float)getWidth()/ (float)getHeight(), 1.0f, 1000.0f ); light = new Light(); light.setColor(0xffffff); light.setIntensity(1.25f); short[] vert = { 5, 5, 5, -5, 5, 5, 5,-5, 5, -5,-5, 5, -5, 5,-5, 5, 5,-5, -5,-5,-5, 5,-5,-5, -5, 5, 5, -5, 5,-5, -5,-5, 5, -5,-5,-5, 5, 5,-5, 5, 5, 5, 5,-5,-5, 5,-5, 5, 5, 5,-5, -5, 5,-5, 5, 5, 5, -5, 5, 5, 5,-5, 5, -5,-5, 5, 5,-5,-5, -5,-5,-5 }; VertexArray vertArray = new VertexArray(vert.length / 3, 3, 2); vertArray.set(0, vert.length/3, vert); // Задаем нормали куба byte[] norm = { 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127, -127, 0, 0, -127, 0, 0, -127, 0, 0, -127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0, 127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0, 0,-127, 0 }; VertexArray normArray = new VertexArray(norm.length / 3, 3, 1); normArray.set(0, norm.length/3, norm); // Задаем текстурные координаты short[] tex = { 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1 }; VertexArray texArray = new VertexArray(tex.length / 2, 2, 2); texArray.set(0, tex.length/2, tex); int[] stripLen = { 4, 4, 4, 4, 4, 4 }; // VertexBuffer для нашего обЪекта VertexBuffer vb = vbuffer = new VertexBuffer(); vb.setPositions(vertArray, 1.0f, null); vb.setNormals(normArray); vb.setTexCoords(0, texArray, 1.0f, null); indexbuffer = new TriangleStripArray( 0, stripLen ); // изображение для текстуры image=Image.createImage( "/ru.png" ); Image2D image2D = new Image2D( Image2D.RGB, image ); Texture2D texture = new Texture2D( image2D ); texture.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST); texture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP); texture.setBlending(Texture2D.FUNC_MODULATE); // создаем вид appearance = new Appearance(); appearance.setTexture(0, texture); appearance.setMaterial(material); material.setColor(Material.DIFFUSE, 0xFFFFFFFF); material.setColor(Material.SPECULAR, 0xFFFFFFFF); material.setShininess(100.0f); background.setColor(0xffffcc); } protected void paint(Graphics g) { graphics3d.bindTarget(g, true, Graphics3D.DITHER | Graphics3D.TRUE_COLOR); graphics3d.clear(background); // устанавливаем камеру Transform transform = new Transform(); transform.postTranslate(0.0f, 0.0f, 30.0f); graphics3d.setCamera(camera, transform); // Устанавливаем имточники света graphics3d.resetLights(); graphics3d.addLight(light, transform); // Задаем вращение angle += 1.0f; transform.setIdentity(); transform.postRotate(angle, 1.0f, 1.0f, 1.0f); graphics3d.render(vbuffer, indexbuffer, appearance, transform); graphics3d.releaseTarget(); } }//canvas }//main