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.


Topics - athanazio

Pages: [1]
1
Support / show selected object
« on: December 10, 2006, 05:20:41 am »
I'm thinking about to show the current selected object, using a elipse at the ground where the object is like this image bellow :



any ideas ?

was thinking about an transparent plane between the ground and the character base and draw on this plane ... not sure if it will work or not ...

suggestions ?

2
Support / collision basics
« on: December 10, 2006, 04:28:28 am »
Now my journey in the JPCT its in the collision phase ...

Well sometimes the Character is able to go thru the cube, sometimes it hits the cube, and got stopped, so sometimes its working, sometimes not ... any help would be great !


look what I'm doing :

I have a class that Wrap around every Object3D that I create, and this is the translate method

Code: [Select]
public void translate(SimpleVector where) {
int collisionObject = w.checkCollision(getTransformedCenter(), where,
5);
if (collisionObject == Object3D.NO_OBJECT) {
super.translate(where);
syncTranslate(where);
}
else {
System.out.println("colide with " + collisionObject );
}
}


the basic idea is dont allow those objets to go thru other object ... :)

and this is the init() method of my Game class
Code: [Select]

public void init() throws Exception {
System.out.println("Config.maxPolysVisible=" + Config.maxPolysVisible);
Config.maxPolysVisible = 12000;
Config.collideOffset = 250;
Config.tuneForOutdoor();

addTexture("alita2", "models/alita/alita2.jpg");
addTexture("floor", "textures/floor.jpg");
addTexture("red", "textures/red.jpg");

AbstractEntity[] list = new AbstractEntity[3];

list[0] = ModelUtil.loadModelMD2(getWorld(), "alita/tris", 0, -90, 0,
0.9f);
list[0].setTexture("alita2");
setCurrent(list[0]);
Animation run = list[0].getAnimationSequence();
anim = run.createSubSequence("run");

list[1] = new AbstractEntity(PlaneUtil.getPlane("floor", 20, 300),
getWorld());
list[1].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

list[2] = new AbstractEntity(Primitives.getCube(50), getWorld());
list[2].setTexture("red");
list[2].setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);

addObjects(list);
PositionUtil.placeOver(list[0], 0, 0);
PositionUtil.placeOver(list[2], -50, -50);

CameraUtil.setCameraLookingFromTop(getCamera(), list[0]);

LightUtil.addDefaultLight(getWorld());
addFPSListener(this);
Config.tuneForOutdoor();
Logger.setLogLevel(Logger.LL_ONLY_ERRORS);
}

3
Support / disable System.out
« on: December 02, 2006, 06:15:18 pm »
Is there a way to disable the System.out messages from jpct ? for exemple in the last implementation that I made I change a texture all the time, with replaceTexture(), and receive a lot of System.out messages ... is there a way to disable all at Config class ?

thanks

I tried to force a remotion of the System.out, but without sucess ...

Code: [Select]
System.setOut(new PrintStream(new OutputStream() {
public void write(int i) {
}

public void write(byte[] b) throws IOException {
}

public void write(byte[] b, int off, int len) throws IOException {
}

}));

4
Support / rearview mirror
« on: December 02, 2006, 03:45:08 am »
Iīm implementing a basic car control to understand more about jpct features, butīm facing a challenge now: how to implement a rearview mirror ?
something like this for example ...


should I use more than one camera ?

thanks for the help

5
Support / any plans to support the gmax file type ?
« on: November 25, 2006, 06:54:52 pm »
Hello !
is there any plans to support the gmax file type, this file type is used by default by http://www.turbosquid.com/gmax

thanks

6
Support / same code running in a Applet and JFrame
« on: November 23, 2006, 12:12:41 pm »
-- warning long message -- (sorry for this)

In my studies yesterday I got a result that I liked, and want to share with the other JPCT learners :D

I separated a class to represent the game, and used in a Applet and in a JFrame, I didn't use the OGL rendering just the software rendering, but I dont have parameters to say if the performance was good or not, follow some comments and the code - note that the game is a cut and paste of Car example, changing just some details to see how it looks :)

One detail that is important to comment is about the PathBuilder interface, this one allows both (Applet and JFrame) to pass its instance as parameter to the game class, and when the game needs any external resources as models, textures can delegate to the caller the job of find out where the resources are, by using the method createPath()

As the Game class extends JComponent, I only to override the paintComponent() method, allowing for example the use of the game component within other Swing components in the interface.

The Applet

Code: [Select]
import java.io.InputStream;
import java.net.URL;

import javax.swing.JApplet;

public class Load3DSApplet extends JApplet implements Runnable, Pathbuilder {

private static final long serialVersionUID = 1L;

private Load3DSGame game = null;

public void start() {
try {
game = new Load3DSGame(this, this);
game.finishOnESC(false);
getContentPane().add(game);

Thread gamethread = new Thread(this);
gamethread.start();
} catch (Exception e) {
System.err.println("Initialization failed");
e.printStackTrace();
}
}

public void run() {
game.play();
}

public InputStream createPath(String fileName) throws Exception {
System.out.println("createPath() filename=" + fileName);
URL url = new URL(getDocumentBase(), fileName);
InputStream in = url.openStream();
return in;
}

public void destroy() {
game.exit();
}

public void stop() {
game.exit();
}

}


The JFrame

Code: [Select]

import java.awt.BorderLayout;
import java.awt.Label;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.swing.JFrame;

public class Load3DSFrame extends JFrame implements Pathbuilder, Runnable {

private static final long serialVersionUID = 1L;

private Load3DSGame game;

public static void main(String[] args) throws Exception {
Load3DSFrame frame = new Load3DSFrame();
frame.setVisible(true);
}

public Load3DSFrame() throws Exception {
game = new Load3DSGame(this, this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Game Frame");
setSize(800, 600);
setResizable(false);
setLocationRelativeTo(null);

getContentPane().add(game, BorderLayout.CENTER);
getContentPane().add(new Label("this is a label"), BorderLayout.SOUTH);

Thread gamethread = new Thread(this);
gamethread.start();

}

public InputStream createPath(String fileName) throws Exception {
System.out.println("createPath() filename=" + fileName);
FileInputStream in = new FileInputStream(fileName);
return in;
}

public void run() {
game.play();
}

}


The game class

Code: [Select]
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.KeyEvent;

import javax.swing.JComponent;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Lights;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
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 Load3DSGame extends JComponent {

private static final long serialVersionUID = 1L;

private FrameBuffer buffer = null;

private World world = null;

private Camera camera = null;

private Object3D box = null;

private TextureManager textureManager = null;

private static final float ROTATE_ANGLE = (float) Math.toRadians(20.0);

private static final float SPEED = 6.0f;

private static boolean left = false;

private static boolean right = false;

private static boolean up = false;

private static boolean down = false;

private boolean exit = false;

private int titleBarHeight = 0;

private int leftBorderWidth = 0;

private KeyMapper keyMapper;

private Pathbuilder builder;

private Component owner;

private boolean finishOnESC = true;

/**
* @throws Exception
*/
public Load3DSGame(Component owner, Pathbuilder builder) throws Exception {
this.owner = owner;
this.builder = builder;
add3DStuff();
}

public void play() {
World.setDefaultThread(Thread.currentThread());

// wait until Swing determine the dimension of the component
while ((getWidth() == 0 || getHeight() == 0) && !exit) {
Thread.yield();

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

if (getWidth() > 0 && getHeight() > 0) {
buffer = new FrameBuffer(getWidth(), getHeight(),
FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
}

while (!exit) {
buffer.clear();
moveTheCube();

world.renderScene(buffer);
world.draw(buffer);
buffer.update();

// poll the keyboard
poll();

// force the refresh of the component
repaint();
Thread.yield();

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

buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
}

protected void paintComponent(Graphics g) {
if (buffer != null) {
buffer.display(g, leftBorderWidth, titleBarHeight);
}
super.paintComponent(g);
}

private void add3DStuff() throws Exception {
keyMapper = new KeyMapper(owner);
Config.maxPolysVisible = 10000;
Config.farPlane = 1200;

SimpleVector middle = new SimpleVector(0, 0, 0);
world = new World();
textureManager = TextureManager.getInstance();

box = Primitives.getBox(10, 1);
box.setOrigin(middle);

Texture rocks = new Texture(builder.createPath("textures/rocks.jpg"));
textureManager.addTexture("rocks", rocks);

Object3D terrain = null;
Object3D[] foo = Loader.load3DS(builder
.createPath("models/terascene.3ds"), 400);
if (foo.length > 0) {
terrain = foo[0];
}

if (terrain != null) {
terrain.setTexture("rocks");
terrain.build();
SimpleVector pos = terrain.getCenter();
pos.scalarMul(-1f);
terrain.translate(pos);
terrain.rotateX((float) Math.toRadians(-90));
terrain.translateMesh();
terrain.rotateMesh();
terrain.setTranslationMatrix(new Matrix());
terrain.setRotationMatrix(new Matrix());
terrain.enableLazyTransformations();
world.addObject(terrain);
}

world.addObject(box);
world.buildAllObjects();
/**
* Place the camera at the starting position.
*/
setCamera(box);
setLight();
Config.tuneForOutdoor();
}

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

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

world.addLight(new SimpleVector(0, -150, 0), 25, 25, 3);
world.addLight(new SimpleVector(-100, -150, 100), 22, 15, 4);
world.addLight(new SimpleVector(100, -150, -100), 4, 2, 22);

world.setFogging(World.FOGGING_ENABLED);
world.setFogParameters(1200, 0, 0, 0);

}

/**
* 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): {
if (finishOnESC)
exit = event;
break;
}
case (KeyEvent.VK_UP): {
up = event;
break;
}
case (KeyEvent.VK_DOWN): {
down = event;
break;
}
case (KeyEvent.VK_LEFT): {
left = event;
break;
}
case (KeyEvent.VK_RIGHT): {
right = event;
break;
}
}
}

// TODO Understand how to move the camera to follow the car ...
private void moveTheCamera() {
camera.lookAt(box.getTransformedCenter());
// SimpleVector a = camera.getPosition();
// a.scalarMul(SPEED);
// camera.setPosition(a);
}

private void moveTheCube() {

if (up) {
SimpleVector a = box.getZAxis();
a.scalarMul(SPEED);
box.translate(a);
moveTheCamera();
}

if (down) {
SimpleVector a = box.getZAxis();
a.scalarMul(-SPEED);
box.translate(a);
moveTheCamera();
}

if (left) {
box.rotateY(ROTATE_ANGLE);
}

if (right) {
box.rotateY(-ROTATE_ANGLE);
}

}

public void exit() {
exit = true;
}

public void finishOnESC(boolean b) {
this.finishOnESC = b;
}

// my component does not care about overlapping
public boolean isOptimizedDrawingEnabled() {
return true;
}
}

7
Support / trying to understand the Car sample 2
« on: November 21, 2006, 06:04:28 pm »
another detail in the sample that is not clear for me is how come the car go over the surface of the terrain ? is this because of the collision definition of the terrain ?

this is the piece of code that I think is doing the "magic"... am I correct, if so how ? :)

Code: [Select]

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);

8
Support / trying to understand the Car sample
« on: November 21, 2006, 04:39:59 pm »
I'm very happy with the engine ! but I got stuck at one piece of code at the Car sample ...

Code: [Select]
     
      /**
       * The terrain isn't located where we want it to, so we take
       * care of this here:
       */
      SimpleVector pos=terrain.getCenter();
      pos.scalarMul(-1f);
      terrain.translate(pos);
      terrain.rotateX((float)-Math.PI/2f);
      terrain.translateMesh();
      terrain.rotateMesh();
      terrain.setTranslationMatrix(new Matrix());
      terrain.setRotationMatrix(new Matrix());


I just dont understand this ... :D any help would be great !

9
Support / JPCT in PS2
« on: November 20, 2006, 06:11:52 pm »
Is possible to run a JPCT game in PS2 ? any ideas on this subject ?

Pages: [1]