import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;
public class Transparency extends Frame implements WindowListener {
private World theWorld;
private FrameBuffer buffer;
private Camera cam;
private Object3D obj;
private boolean keepGoing, turnRight, turnLeft;
private com.threed.jpct.util.KeyMapper keyMapper;
private Texture boxMap;
private int transparency = 0;
private FadeoutEffect effect;
public Transparency() {
this.setTitle("BR's");
theWorld = new World();
buffer = new FrameBuffer(1440, 900, FrameBuffer.SAMPLINGMODE_NORMAL);
obj = com.threed.jpct.util.ExtendedPrimitives.createBox(new SimpleVector(2f, 2f, 2f));//Primitives.getCube(1f);
TextureManager.getInstance().addTexture("boxMap", (boxMap=new Texture("BoxMap.png", true)));
boxMap.setEffect((effect=new FadeoutEffect()));
obj.setTexture("boxMap");
obj.build();
obj.setTransparencyMode(Object3D.TRANSPARENCY_MODE_DEFAULT);
obj.setTransparency(transparency);
Object3D backgroundPlane = Primitives.getPlane(1, 4f);
backgroundPlane.build();
backgroundPlane.translate(0f, -2f, 0f);
theWorld.addObject(backgroundPlane);
cam = theWorld.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 8f);
theWorld.addObject(obj);
obj.setLighting( Object3D.LIGHTING_NO_LIGHTS );
keyMapper = new com.threed.jpct.util.KeyMapper(this);
this.addWindowListener(this);
this.setSize(buffer.getWidth(), buffer.getHeight());
this.setVisible(true);
loop();
}
public void loop() {
keepGoing = true;
while (keepGoing) {
buffer.clear();
com.threed.jpct.util.KeyState keyState = keyMapper.poll();
if (keyState.getState() == com.threed.jpct.util.KeyState.PRESSED)
keyPressed(keyState.getKeyCode());
else if (keyState.getState() == com.threed.jpct.util.KeyState.RELEASED)
keyReleased(keyState.getKeyCode());
if (turnRight)
obj.rotateY(-.01f);
if (turnLeft)
obj.rotateY(.01f);
theWorld.renderScene(buffer);
theWorld.draw(buffer);
//theWorld.drawWireframe(buffer, Color.yellow);
buffer.display(this.getGraphics());
Thread.yield();
}
buffer.dispose();
this.dispose();
System.exit(0);
}
private void keyPressed(int keyCode) {
if (keyCode == KeyEvent.VK_RIGHT)
turnRight = true;
if (keyCode == KeyEvent.VK_LEFT)
turnLeft = true;
}
private void keyReleased(int keyCode) {
if (keyCode == KeyEvent.VK_RIGHT)
turnRight = false;
if (keyCode == KeyEvent.VK_LEFT)
turnLeft = false;
if (keyCode == KeyEvent.VK_T) {
float fade = 1.00f;
if (transparency < 255)
fade = (float)((transparency+=8)/255f);
effect.transparency = 255-transparency;
obj.setTransparency(255-transparency);
//boxMap.setAlpha(255-transparency);
TextureManager.getInstance().replaceTexture("boxMap", boxMap);
//obj.setAdditionalColor(intensity(boxColor, fade));
//boxMap.applyEffect();
Logger.log("Transparency: "+transparency, Logger.MESSAGE);
}
}
public void windowClosing(WindowEvent e) {
keepGoing = false;
}
public void windowClosed(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public static void main(String[] args) {
new Transparency();
}
}
class FadeoutEffect implements ITextureEffect {
public int transparency;
private Texture tex;
public FadeoutEffect() {
}
public void init(Texture texture) {
this.tex = texture;
}
public void apply(int[] dest, int[] src) {
/*for (int y =0; y < 512;y++) {
for (int x = 0; x < 512; x++) {
dest[y*x] = transparency;
}
}*/
tex.setAlpha(transparency);
}
public boolean containsAlpha() {
return false;
}
}
Page created in 0.071 seconds with 6 queries.