import java.util.*;
import java.awt.image.BufferedImage;
import javax.media.j3d.*;


/**
 *
 * @author  zero
 */
public class ImageBlitCanvas3D extends Canvas3D {
    
    private ArrayList images = new ArrayList();
    
    
    /** Creates a new instance of VCanvas3D */
    public ImageBlitCanvas3D(java.awt.GraphicsConfiguration graphicsConfiguration) {
        this(graphicsConfiguration, false);        
    }
    
    public ImageBlitCanvas3D(java.awt.GraphicsConfiguration graphicsConfiguration, boolean offScreen) {
        super(graphicsConfiguration, offScreen);
    }    

    public void addImage(int xPos, int yPos, BufferedImage bImg) {
        images.add(new ImageAndPos(xPos, yPos, bImg));
    }
    
    public void setPos(int index, int xPos, int yPos, BufferedImage bImg) {
        ImageAndPos imgAndPos = (ImageAndPos) images.get(index);
        imgAndPos.x = xPos;
        imgAndPos.y = yPos;        
    }
    
    public void removeImage(int index) {
        images.remove(index);
    }

    
    public void postRender() {
        super.postRender();  
       
        J3DGraphics2D gfx = this.getGraphics2D();
        for(int i=0; i<images.size(); i++) {
            ImageAndPos imgAndPos = (ImageAndPos) images.get(i);
            gfx.drawAndFlushImage(imgAndPos.bImg, imgAndPos.x, imgAndPos.y, this);
        }
    }
    
    private class ImageAndPos {   
        int x;
        int y;
        BufferedImage bImg;        
                
        ImageAndPos(int x, int y, BufferedImage bImg) {
            this.x = x;
            this.y = y;
            this.bImg = bImg;
        }        
    }
    
    
}
