Example6.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.m3g.*;
- /**
- * Image, sprite and background test.
- *
- * The test moves a sprite back and forth in front of the camera. The
- * transition between different mipmap levels should be visible.
- *
- */
- public class Example6 extends ExampleBase
- {
- private static final int IMAGE_BASE_SIZE = 128;
- // private static final int IMAGE_BASE_SIZE = 256 - 13;
- private static final String TEXTURE_NAME = "/textures/pukki_small_cg2.png";
- private World iWorld;
- private Background iBackground;
- private Sprite3D iSprite;
- private Image2D iImage;
- public Example6()
- {
- super(SHOW_RENDER_TIME);
- }
- protected void render(int time)
- {
- double temp = Math.tan((1.0f - (float)Math.cos(time * 0.0005f))*0.5f);
- iSprite.setTranslation(0.0f, 0.0f, (float)(temp*temp*temp) * -100.0f + 30.0f);
- Graphics3D.getInstance().render(iWorld);
- }
- protected void initialize()
- {
- iWorld = new World();
- Camera camera = new Camera();
- camera.setPerspective(70.0f, 1.0f, 1.0f, 10000.0f);
- camera.setTranslation(0.0f, 0.0f, 40.0f);
- iWorld.addChild(camera);
- iWorld.setActiveCamera(camera);
- Light light = new Light();
- light.setTranslation(0.0f, 0.0f, 40.0f);
- iWorld.addChild(light);
- iImage = new Image2D(Image2D.RGBA, platformServices.loadImage(TEXTURE_NAME));
- iBackground = new Background();
- iBackground.setColor(0xffFFFFFF);
- iWorld.setBackground(iBackground);
- iSprite = new Sprite3D(true, iImage, new Appearance());
- iSprite.setScale(20.0f, 20.0f, 20.0f);
- iWorld.addChild(iSprite);
- }
- }