Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dear_stephen

Pages: 1 2 [3]
31
News / Re: Version 0.90 has been released!
« on: March 23, 2007, 12:08:56 pm »
Code: [Select]

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.KeyEvent;
import java.io.File;

import javax.swing.JFrame;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.IVertexController;
import com.threed.jpct.Lights;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.KeyMapper;
import com.threed.jpct.util.KeyState;

public class HelloWorld extends JFrame {
/**
* Are we rendering in wireframe mode?
*/
private boolean wireframe = false;

private FrameBuffer buffer = null;

private World world = null;

private TextureManager textureManager = null;

private Camera camera = null;

private int width = 640;

private int height = 480;

private Graphics g = null;

/**
* main method
*/
private static final long serialVersionUID = 1L;

public static void main(String[] args) {
HelloWorld h = new HelloWorld();
}

private boolean exit = false;

private int titleBarHeight;

private int leftBorderWidth;

private KeyMapper keyMapper;

/**
*/
public HelloWorld() {
setFrameStuff();
add3DStuff();
gameLoop();
}

private void gameLoop() {
World.setDefaultThread(Thread.currentThread());

buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);

while (!exit) {
buffer.clear();
world.renderScene(buffer);
if (!wireframe) {
world.draw(buffer);
} else {
world.drawWireframe(buffer, Color.white);
}
buffer.update();
poll();
buffer.display(g, leftBorderWidth, titleBarHeight);
Thread.yield();

try {
Thread.sleep(200);
} catch (InterruptedException e) {
}
}

System.exit(0);
}

private void setFrameStuff() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("jPCT Hello World (" + Config.getVersion() + ")");
pack();
Insets insets = getInsets();
titleBarHeight = insets.top;
leftBorderWidth = insets.left;
setSize(width + leftBorderWidth + insets.right, height + titleBarHeight
+ insets.bottom);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);
g = getGraphics();
keyMapper = new KeyMapper(this);
}

private void add3DStuff() {
/**
* Load the textures needed and add them to the TextureManager. We are
* loading the "numbers" texture for blitting the framerate and the
* texture for the ground. Textures used by the game entities are loaded
* by them.
*/
char c = File.separatorChar;

world = new World();
textureManager = TextureManager.getInstance();
Texture rocks = new Texture("textures" + c + "rocks.jpg");
textureManager.addTexture("rocks", rocks);

Object3D box = Primitives.getBox(50, 1);
box.setOrigin(new SimpleVector(0, 0, 0));
//world.addObject(box);

IVertexController demoControl = new DemoVertexController();
Object3D obj = Primitives.getPlane(50, 3);
//obj.calcTextureWrap();
obj.build();
obj.getMesh().setVertexController(demoControl,
IVertexController.PRESERVE_SOURCE_MESH);
obj.setOrigin(new SimpleVector(0, 0, 0));
obj.getMesh().applyVertexController();
obj.rotateZ(3.14f/4);
obj.setTexture("rocks");
world.addObject(obj);

world.buildAllObjects();
SimpleVector cameraPosition;
cameraPosition = obj.getCenter();
cameraPosition.y = cameraPosition.y + 140;
cameraPosition.z = cameraPosition.z - 105;
camera = world.getCamera();
camera.setPosition(cameraPosition);
camera.lookAt(obj.getCenter());

/**
* Place the camera at the starting position.
*/
//setCamera(obj);
setLight();

}

private void setCamera(Object3D box) {
camera = world.getCamera();
camera.setPosition(0, -100, 200);
camera.lookAt(box.getCenter());
}

private void setLight() {
// Config.fadeoutLight = false;
world.getLights().setOverbrightLighting(
Lights.OVERBRIGHT_LIGHTING_DISABLED);
world.getLights().setRGBScale(Lights.RGB_SCALE_2X);
world.setAmbientLight(100, 100, 100);

/**
* Place the lightsources…
*/
world.addLight(new SimpleVector(0, -150, 0), 25, 22, 19);
world.addLight(new SimpleVector(-100, -150, 100), 22, 5, 4);
world.addLight(new SimpleVector(100, -150, -100), 4, 2, 22);

}

/**
* Use the KeyMapper to poll the keyboard
*/
private void poll() {
KeyState state = null;
do {
state = keyMapper.poll();
if (state != KeyState.NONE) {
keyAffected(state);
}
} while (state != KeyState.NONE);
}

private void keyAffected(KeyState state) {
int code = state.getKeyCode();
boolean event = state.getState();

switch (code) {
case (KeyEvent.VK_ESCAPE) : {
exit = event;
break;
}
}
}
}

32
News / Re: Version 0.90 has been released!
« on: March 23, 2007, 10:37:06 am »
Hi

Can you please post the entire code for this mesh example?

cheers

Pages: 1 2 [3]