Header Sep

Java Tips, Tricks & Code

我的评分 用户评价
登录票选本页

January 2005

Animate textures in your 3D MIDlet

 

The Mascot Capsule® Micro3D engine (Java 3D) allows you to create nice effects by animating the textures with a sprite bitmap. In JSR-184 it's possible to move or rotate the whole texture instead of using a sprite.

 

The textures are animated by just showing a part of the image in each frame.

Textures in Mascot Capsule Micro3D can be dimensioned at any size up to 256 pixels per side. When specifying the texture coordinates for a figure, the part of the image to be mapped is actually specified.

To show a whole 255*255 image, we use the texture coordinates (x, y):


int TEXTURE[] = {0, 255,
                 255, 255,
                 255, 0,
                 0, 0};

And to just show the left 16 pixels on a 255x255 image, we use (x, y):


int TEXTURE[] = {0, 255,
                 16, 255,
                 16, 0,
                 0, 0};

So, to animate the texture we just change the part of the texture to be shown. The top left corner of the plane has the texture coordinate (0,0) and the right bottom corner has the coordinate (ImageWidth, ImageHeight).

Download an example with source code>>

 

我的评分 用户评价
登录票选本页