actually it's everything :roll:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;
class Cube {
/* Engine Specific */
private final static int SWITCH_RENDERER=35;
private boolean fullscreen=false;
private boolean openGL=true;
private boolean wireframe=false;
private FrameBuffer buffer=null;
private World theWorld=null;
private TextureManager texMan=null;
private Camera camera=null;
private int width=640;
private int height=480;
private Frame frame=null;
private Graphics gFrame=null;
private BufferStrategy bufferStrategy=null;
private GraphicsDevice device=null;
private int titleBarHeight=0;
private int leftBorderWidth=0;
private int switchMode=0;
private int fps;
private int lastFps;
private long totalFps;
private int pps;
private int lastPps;
private boolean isIdle=false;
private boolean exit=false;
private boolean left=false;
private boolean right=false;
private boolean up=false;
private boolean down=false;
private boolean forward=false;
private boolean back=false;
private boolean jump=false;
private boolean inAir=false;
private boolean fire=false;
private int fireCount=3;
private float GRAVITY=1f;
private int theIlluminator;
private float camAlt=125f;
private float camDist=150f;
private boolean camUp=false;
private boolean camDown=false;
private boolean camIn=false;
private boolean camOut=false;
private float speed=0;
private int t=0;
private float z=0f;
private KeyMapper keyMapper=null;
private Object3D cube = /*Primitives.getCube(10);*/new Object3D(400);
private Object3D terrain = new Object3D(400);
private SimpleVector Csiz = new SimpleVector();
private Cube(String[] args) {
/* init stuff */
char c=File.separatorChar;
Config.glFullscreen=false;
Config.glMipmap=true;
Config.glColorDepth=16;
Config.maxPolysVisible=10000;
/* process commandline arguments */
for(int i=0;i<args.length;i++) {
if(args[i].equals("fullscreen")) {
Config.glFullscreen=true;
}
if(args[i].equals("noGL")) {
openGL=false;
}
}
isIdle=false;
switchMode=0;
totalFps=0;
fps=0;
lastFps=0;
theWorld=new World();
//Lights!
Config.fadeoutLight=false;
theWorld.getLights().setOverbrightLighting(Lights.OVERBRIGHT_LIGHTING_DISABLED);
theWorld.getLights().setRGBScale(Lights.RGB_SCALE_2X);
theWorld.setAmbientLight(25, 30, 30);
theWorld.addLight(new SimpleVector(0, -150, 0), 10, 10, 10);
theWorld.addLight(new SimpleVector(-1000, -1000, 1000), 5, 5, 5);
theWorld.addLight(new SimpleVector(1000, -1000, -1000), 5, 5, 5);
theIlluminator=theWorld.addLight(new SimpleVector(1000, -1000, -1000), 255, 0, 0);
theWorld.setLightDiscardDistance(theIlluminator, 20);
//Fog!
theWorld.setFogging(World.FOGGING_ENABLED);
theWorld.setFogParameters(5000, 0, 0, 0);
Config.farPlane=5000;
//Textures!
texMan=TextureManager.getInstance();
texMan.addTexture("teks", new Texture("textures"+c+"ql0.jpg"));
texMan.addTexture("rocks", new Texture("textures"+c+"rocks.jpg"));
//World!
terrain=Loader.load3DS("models"+c+"terascene.3ds", 1000)[0];
terrain.setOrigin(new SimpleVector(0, 0, 0));
terrain.rotateX((float)-Math.PI/2f);
terrain.setTexture("rocks");
terrain.createTriangleStrips(2);
OcTree oc = new OcTree(terrain, 50, OcTree.MODE_OPTIMIZED);
terrain.setOcTree(oc);
oc.setCollisionUse(OcTree.COLLISION_USE);
Config.collideOffset=250;
terrain.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
terrain.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
//add listener
theWorld.addObject(terrain);
//theCUBE!
cube=Loader.loadMD2("models"+c+"bill"+c+"tris.MD2", 1f);
cube.rotateY((float)-Math.PI/2f);
cube.rotateMesh();
cube.setRotationMatrix(new Matrix());
texMan.addTexture("suit", new Texture("models"+c+"bill"+c+"billywork.jpg"));
//cube.setBaseTexture("suit");
cube.setTexture("suit");
cube.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
//cube.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
cube.setTranslationMatrix(new Matrix());
theWorld.addObject(cube);
float[] bf = cube.getMesh().getBoundingBox();
Csiz.x = (Math.abs(bf[0])+Math.abs(bf[1]))/2f;
Csiz.y = (Math.abs(bf[2])+Math.abs(bf[3]))/2f;
Csiz.z = (Math.abs(bf[4])+Math.abs(bf[5]))/2f;
Logger.log("============================", Logger.MESSAGE);
for(int i=0;i<6;i++) {
Logger.log(String.valueOf(bf[i]), Logger.MESSAGE);
}
Logger.log("============================", Logger.MESSAGE);
Logger.log(String.valueOf(Csiz.x), Logger.MESSAGE);
Logger.log(String.valueOf(Csiz.y), Logger.MESSAGE);
Logger.log(String.valueOf(Csiz.z), Logger.MESSAGE);
Logger.log("============================", Logger.MESSAGE);
//Camera!
camera=theWorld.getCamera();
camera.setPosition(0, 0, 10);
camera.lookAt(cube.getTransformedCenter());
theWorld.buildAllObjects();
Config.tuneForOutdoor();
initializeFrame();
gameLoop();
}
public static void main(String[] args) {
/* main stuff */
new Cube(args);
}
private void initializeFrame() {
if (Config.glFullscreen) {
GraphicsEnvironment env=GraphicsEnvironment.getLocalGraphicsEnvironment();
device=env.getDefaultScreenDevice();
GraphicsConfiguration gc=device.getDefaultConfiguration();
frame=new Frame(gc);
frame.setUndecorated(true);
frame.setIgnoreRepaint(true);
device.setFullScreenWindow(frame);
if (device.isDisplayChangeSupported()) {
device.setDisplayMode(new DisplayMode(width, height, 32, 0));
}
frame.createBufferStrategy(2);
bufferStrategy=frame.getBufferStrategy();
Graphics g=bufferStrategy.getDrawGraphics();
bufferStrategy.show();
g.dispose();
} else {
frame=new Frame("jPCT "+Config.getVersion());
frame.pack();
Insets insets = frame.getInsets();
titleBarHeight=insets.top;
leftBorderWidth=insets.left;
frame.setSize(width+leftBorderWidth+insets.right, height+titleBarHeight+insets.bottom);
frame.setResizable(false);
frame.show();
gFrame=frame.getGraphics();
}
frame.addWindowListener(new WindowEvents());
keyMapper=new KeyMapper(frame);
}
private void moveCube() {
SimpleVector grav = new SimpleVector(0, GRAVITY, 0);
grav = cube.checkForCollisionEllipsoid(grav, Csiz, 6);
grav.x=0;
grav.z=0;
cube.translate(grav);
t=1;
if(cube.wasTargetOfLastCollision()) {
inAir=false;
}
if(right) {
cube.rotateY(0.01f);
}
if(left) {
cube.rotateY(-0.01f);
}
if(up) {
cube.rotateAxis(cube.getXAxis(), -0.01f);
}
if(down) {
cube.rotateAxis(cube.getXAxis(), 0.01f);
}
if(forward) {
t=2;
SimpleVector fax = cube.getZAxis();
fax.scalarMul(1f);
fax=cube.checkForCollisionEllipsoid(fax, Csiz, 6);
cube.translate(fax);
}
if(back) {
SimpleVector bax = cube.getZAxis();
bax.scalarMul(-0.5f);
bax=cube.checkForCollisionEllipsoid(bax, Csiz, 25);
cube.translate(bax);
}
if(jump) {
if(!inAir) {
SimpleVector jax = cube.getZAxis();
jax.scalarMul(-1f);
jax.add(new SimpleVector(0, -5, 0));
jax.x=0;
jax.z=0;
jax=cube.checkForCollisionEllipsoid(jax, Csiz, 25);
cube.translate(jax);
//inAir=true;
}
}
if(camUp) {
camAlt+=0.5f;
}
if(camDown) {
camAlt-=0.5f;
}
if(camIn) {
camDist-=0.5f;
}
if(camOut) {
camDist+=0.5f;
}
// Anim
if(z>1f) {
z=0f;
}
cube.animate(z, t);
z+=0.001f;
}
private void display() {
if (buffer.usesRenderer(IRenderer.RENDERER_SOFTWARE)) {
if (Config.glFullscreen) {
Graphics g=bufferStrategy.getDrawGraphics();
g.drawImage(buffer.getOutputBuffer(), 0, 0, null);
bufferStrategy.show();
g.dispose();
} else {
buffer.display(gFrame, leftBorderWidth, titleBarHeight);
}
} else {
buffer.displayGLOnly();
}
}
private void gameLoop() {
World.setDefaultThread(Thread.currentThread());
buffer=new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
if(openGL) {
frame.hide();
keyMapper.destroy();
buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
keyMapper=new KeyMapper();
}
buffer.setBoundingBoxMode(FrameBuffer.BOUNDINGBOX_NOT_USED);
buffer.optimizeBufferAccess();
Timer timer = new Timer(25);
timer.start();
while(!exit) {
if(!isIdle) {
poll();
buffer.clear();
theWorld.renderScene(buffer);
theWorld.draw(buffer);
buffer.update();
moveCube();
SimpleVector ilpos=cube.getTransformedCenter();
theWorld.setLightPosition(theIlluminator, ilpos);
camera.setPosition(cube.getTransformedCenter());
camera.align(cube);
camera.moveCamera(Camera.CAMERA_MOVEOUT, camDist);
camera.moveCamera(Camera.CAMERA_MOVEUP, camAlt);
camera.lookAt(cube.getTransformedCenter());
display();
Thread.yield();
}
}
if (openGL) {
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
} else {
if (fullscreen) {
device.setFullScreenWindow(null);
}
}
System.exit(0);
}
private void keyAffected(KeyState state) {
int code = state.getKeyCode();
boolean event = state.getState();
switch(code) {
case(KeyEvent.VK_ESCAPE): {
exit=true;
break;
}
case(KeyEvent.VK_RIGHT): {
right=event;
break;
}
case(KeyEvent.VK_LEFT): {
left=event;
break;
}
case(KeyEvent.VK_UP): {
forward=event;
break;
}
case(KeyEvent.VK_DOWN): {
back=event;
break;
}
case(KeyEvent.VK_SPACE): {
jump=event;
break;
}
case(KeyEvent.VK_NUMPAD4): {
camUp=event;
break;
}
case(KeyEvent.VK_NUMPAD1): {
camDown=event;
break;
}
case(KeyEvent.VK_NUMPAD5): {
camIn=event;
break;
}
case(KeyEvent.VK_NUMPAD2): {
camOut=event;
break;
}
case(KeyEvent.VK_INSERT): {
t++;
if(t>17) {
t=0;
}
}
}
}
private void poll() {
KeyState state = null;
do {
state=keyMapper.poll();
if(state != KeyState.NONE) {
keyAffected(state);
}
} while (state != KeyState.NONE);
}
private class WindowEvents extends WindowAdapter {
public void windowIconified(WindowEvent e) {
isIdle=true;
}
public void windowDeiconified(WindowEvent e) {
isIdle=false;
}
}
private class Timer {
private long ticks=0;
private long granularity=0;
public Timer(int granularity) {
this.granularity=granularity;
}
public void start() {
ticks=System.currentTimeMillis();
}
public void reset() {
start();
}
public long getElapsedTicks() {
long cur=System.currentTimeMillis();
long l=cur-ticks;
if (l>=granularity) {
ticks=cur-(l%granularity);
return l/granularity;
}
return 0;
}
}
}
you'll also need a model (cause the cube isn't sticking in the ground, it's just getting blocked if too big, for instance 10)