⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitmapparticleeffect.java

📁 这是有关J2ME 3D编程的源程序
💻 JAVA
字号:
import javax.microedition.m3g.Graphics3D;
import javax.microedition.m3g.Mesh;
import javax.microedition.m3g.PolygonMode;
import javax.microedition.m3g.Transform;

/**
 * Represents a particle effect that uses a bitmap.
 */
public abstract class BitmapParticleEffect implements ParticleEffect
{
    // The mesh
    Mesh mesh = null;
    
    // The transformation matrix
    Transform trans = new Transform();
    
    // The scale
    float scale = 1.0f;
    
    /** Initializes the bitmap used to render particles */
    public BitmapParticleEffect(String filename, float scale)
    {
        // Load the plane with the wanted texture
        mesh = MeshFactory.createAlphaPlane(filename, PolygonMode.CULL_BACK, 0xffffffff);
        
        // Make sure we set the scale
        this.scale = scale;
    }
    
    /**
     * @see ParticleEffect#render(Particle, Graphics3D)
     */
    public void render(Particle p, Graphics3D g3d)
    {
        // Calculate the alpha
        int alpha = (int)(255 * p.getLife());
        
        // Create the color
        int color = p.getColor() | (alpha << 24);
        
        // Set alpha
        MeshOperator.setMeshAlpha(mesh, color);
        
        // Transform
        trans.setIdentity();
        trans.postScale(scale, scale, scale);
        float[] pos = p.getPos();
        trans.postTranslate(pos[0], pos[1], pos[2]);
        
        // Render
        g3d.render(mesh, trans);
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -