Never mind, I got my code to work, here is the updated version:
import com.threed.jpct.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;
/**
* A simple HelloWorld using the Software-renderer and rendering into a frame
* using active rendering.
* @author EgonOlsen
*
*/
public class gun {
private World world;
private FrameBuffer buffer;
private JFrame frame;
private boolean kUP = false;
private boolean kDOWN = false;
private boolean kLEFT = false;
private boolean kRIGHT = false;
KeyMapper keymap;
Object3D rifle;
Camera cam;
public static void main(String[] args) throws Exception {
new gun().loop();
}
public gun() throws Exception {
frame=new JFrame("Hello world");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
world = new World();
// frame.addWindowListener(new WindowEvents());
keymap = new KeyMapper(frame);
// world.setAmbientLight(255, 255, 255);
TextureManager.getInstance().addTexture("shoe1", new Texture("shoe1.jpg"));
Object3D[] miss=Loader.load3DS("rifle.3ds", 4);
rifle = miss[0];
rifle.rotateX((float)-1.46);
rifle.setEnvmapped(Object3D.ENVMAP_ENABLED);
rifle.build();
world.addObject(rifle);
world.getCamera().setPosition(-60, -25, -5);
world.getCamera().lookAt(rifle.getTransformedCenter());
cam = world.getCamera();
world.addLight(new SimpleVector(60, -70, -20), 65, 23,8);
rifle.translate(new SimpleVector(0, 0, -10));
}
private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
while (frame.isShowing()) {
// rifle.rotateY((float).015);
// cam.rotateCameraX((float).009);
// cam.moveCamera(new SimpleVector(2, .5, 0), (float).1);
// cam.lookAt(rifle.getTransformedCenter());
buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(frame.getGraphics());
Thread.sleep(10);
poll();
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}
private void poll() {
KeyState state=null;
do {
state=keymap.poll();
if (state!=KeyState.NONE) {
keyAffected(state);
}
} while (state!=KeyState.NONE);
}
private void keyAffected(KeyState state) {
int code=state.getKeyCode();
boolean event=state.getState();
System.out.println("test");
switch (code) {
case (KeyEvent.VK_LEFT): {
kLEFT=event;
break;
}
case (KeyEvent.VK_UP): {
kUP=event;
break;
}
case (KeyEvent.VK_DOWN): {
kDOWN=event;
break;
}
case (KeyEvent.VK_RIGHT): {
kRIGHT=event;
break;
}
}
}
}
NOTE: I realize my previous post wasn't exactly following forum etiquette , but I was rather frustrated at the time.