📄 imagesquare.java
字号:
import javax.microedition.m3g.*;
public class ImageSquare
{
private Mesh imMesh;
public ImageSquare(Image2D bbImage, float x, float y, float z, float size)
{
// build the mesh
VertexBuffer vertexbuffer = makeGeometry();
int[] INDICES = {1,2,0,3}; // one quad
int[] LENGTH = {4};
IndexBuffer indexbuffer = new TriangleStripArray(INDICES, LENGTH);
Appearance appearance = makeAppearance(bbImage);
imMesh = new Mesh(vertexbuffer, indexbuffer, appearance);
// scale and position the mesh
float scale2 = size * 0.5f; // to reduce 2 by 2 image to 1 by 1
imMesh.scale(scale2, scale2, scale2);
imMesh.setTranslation(x, y, z);
} // end of ImageSquare()
private VertexBuffer makeGeometry()
/* A square centered at the origin on the XZ plane
with sides of 2 units. No normals. */
{
// create vertices
short[] POINTS = {-1,-1,0, 1,-1,0, 1,1,0, -1,1,0};
VertexArray POSITION_ARRAY = new VertexArray(POINTS.length/3, 3, 2);
POSITION_ARRAY.set(0, POINTS.length/3, POINTS);
// create texture coordinates
short[] TEXCOORDS = {0,1, 1,1, 1,0, 0,0};
VertexArray TEXCOORD_ARRAY = new VertexArray(TEXCOORDS.length/2, 2, 2);
TEXCOORD_ARRAY.set(0, TEXCOORDS.length/2, TEXCOORDS);
VertexBuffer vertexbuffer = new VertexBuffer();
vertexbuffer.setPositions(POSITION_ARRAY, 1.0f, null); // no scale, bias
vertexbuffer.setTexCoords(0, TEXCOORD_ARRAY, 1.0f, null);
return vertexbuffer;
} // end of makeGeometry()
private Appearance makeAppearance(Image2D bbImage)
// The appearance comes from the transparent texture in bbImage.
{
Appearance appearance = new Appearance();
// only display the opaque parts of the texture
CompositingMode compositingmode = new CompositingMode();
compositingmode.setBlending(CompositingMode.ALPHA);
appearance.setCompositingMode(compositingmode);
if (bbImage != null) {
Texture2D texture = new Texture2D(bbImage);
texture.setFiltering(Texture2D.FILTER_NEAREST, Texture2D.FILTER_NEAREST);
texture.setWrapping(Texture2D.WRAP_CLAMP, Texture2D.WRAP_CLAMP);
texture.setBlending(Texture2D.FUNC_REPLACE);
// the texture's colours and alpha replace the mesh's
appearance.setTexture(0, texture);
}
return appearance;
} // end of makeAppearance()
// -------------------- access method ----------------------
public Mesh getImageSquareMesh()
{ return imMesh; }
} // end of ImageSquare Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -