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 - athanazio

Pages: 1 2 [3] 4
31
Support / rearview mirror
« on: December 02, 2006, 01:59:19 pm »
getting better !! :)
after some small changes in the code, some stupid mistakes... shhh... =) like the second world instance wanst used in the code that copies the objects.

now I got and fixed image ... in the "mirror" now I will create something like a movement listener to update the clone with the position information ...

Hey would be great if we dont need to clone() the objets, just share the same objets, one sugestion is create a subclass of world called Viewport that can share the same objects, and have for example different light sources, differnt camera...

look how it looks

32
Support / rearview mirror
« on: December 02, 2006, 01:36:49 pm »
well, I'm trying to solve this ... with no success ...
I tried to save the image fro mthe second renderer but still black screen ...
no good ... help me Egon !! :)

look what I tried ...

Code: [Select]
public void afterPaintComponent(Graphics g) {
BufferedImage buffer = new BufferedImage(getWidth(), getHeight(),
BufferedImage.TYPE_INT_RGB);

Graphics2D g2 = buffer.createGraphics();

rearViewBuffer.display(g2);

try {
generateJPG(buffer, "d:/foo.jpg");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

g.setColor(Color.WHITE);
g.drawRect(30, 30, 300, 100);
}

private static void generateJPG(BufferedImage buffer, String fileName)
throws FileNotFoundException, IOException {

FileOutputStream file = new FileOutputStream(fileName);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(file);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buffer);
param.setQuality(1.0F, true);
encoder.setJPEGEncodeParam(param);

encoder.encode(buffer);
file.close();
}

33
Support / rearview mirror
« on: December 02, 2006, 01:28:35 pm »
I found in a presentation of ogre, the way that is done over there ...
It can be done with the creation of ViewPort, or RenderTexture, that is something like render a camera to an texture ... this would be very cool :)
imagine to render mirrors and reflexive images over water ... uhuuuu !

I can see the player gatting close to the water and seeing its on image on it ... this is a good coding challenge hehehe

34
Support / rearview mirror
« on: December 02, 2006, 12:18:55 pm »
ouch !  :shock:

I tried last night to do like this:

1. created a new world
2. cloned all the objects to the new world (is itreally necessary, as Im looking for the same objects ? ...
3. created another FrameBuffer
4. rendered the new FrameBuffer in a small rectangle

result = black rectangle ...

is this a good aproach Egon ? IMO a good to do it is have the possibility of use the way I'm doing with some other details:
- dont need to copy the objects from one world to other
- define a view port or something like this to the rendering process

all the source code is here

and this is the game class, with what I tried

Code: [Select]
package com.foo.game;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.util.Enumeration;

import com.foo.game.test.Pathbuilder;
import com.foo.game.util.CameraUtil;
import com.foo.game.util.LightUtil;
import com.foo.game.util.PlaneUtil;
import com.foo.game.util.SimpleGame;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;

public class RearViewGame extends SimpleGame {

public RearViewGame(Component owner, Pathbuilder builder) throws Exception {
super(owner, builder);
init();
}

private static final long serialVersionUID = 1L;

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

private static final float SPEED = 25.0f;

private Object3D current = null;

public void init() throws Exception {
addTexture("rocks", "textures/rocks.jpg");
addTexture("floor", "textures/floor.jpg");

Object3D[] list = new Object3D[3];

list[0] = Primitives.getCube(20);
setCurrent(list[0]);

// remove from the floor, decrease
list[0].translate(0, -20, 0);
list[2] = Primitives.getCylinder(50);
list[2].translate(0, -50, -100);

list[1] = PlaneUtil.getPlane("floor", 20, 300);
addObjects(list);

CameraUtil.setCameraLookingFromTop(getCamera(), list[0]);
LightUtil.addDefaultLight(getWorld());
createRearViewWorld();
}

World rearView = new World();

FrameBuffer rearViewBuffer;

private void createRearViewWorld() {
World rearView = new World();
Enumeration objects = getWorld().getObjects();
while (objects.hasMoreElements()) {
Object3D element = (Object3D) objects.nextElement();
rearView.addObject(element.cloneObject());
}
rearView.buildAllObjects();

LightUtil.addDefaultLight(rearView);
Camera c = rearView.getCamera();
c.setPosition(50, -100, 50);
c.lookAt(SimpleVector.ORIGIN);

rearViewBuffer = new FrameBuffer(300, 100,
FrameBuffer.SAMPLINGMODE_NORMAL);
rearViewBuffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);

Enumeration o= rearView.getObjects();
while (o.hasMoreElements()) {
Object3D element = (Object3D) o.nextElement();
System.out.println(element.getVisibility());
System.out.println(element.getCenter());
}

}

private void renderRearView() {
rearViewBuffer.clear();
rearView.renderScene(rearViewBuffer);
rearView.draw(rearViewBuffer);
rearViewBuffer.update();
}

public void afterPaintComponent(Graphics g) {
rearViewBuffer.display(g, 30, 30);
g.setColor(Color.WHITE);
g.drawRect(30, 30, 300, 100);
}

// TODO move the camera with the object
public void loop() {
renderRearView();

if (getCurrent() != null) {

if (isUp()) {
SimpleVector a = getCurrent().getZAxis();
a.scalarMul(SPEED);
getCurrent().translate(a);
CameraUtil.moveCamera(getWorld().getCamera(), current);
}

if (isDown()) {
SimpleVector a = getCurrent().getZAxis();
a.scalarMul(-SPEED);
getCurrent().translate(a);
CameraUtil.moveCamera(getWorld().getCamera(), current);
}

if (isLeft()) {
getCurrent().rotateY(ROTATE_ANGLE);
}

if (isRight()) {
getCurrent().rotateY(-ROTATE_ANGLE);
}
} else {
System.out.println("current is null");
}
}

public Object3D getCurrent() {
return current;
}

public void setCurrent(Object3D current) {
this.current = current;
}

}


this is the visual result :

35
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

36
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

37
Support / same code running in a Applet and JFrame
« on: November 23, 2006, 12:15:12 pm »
I forget this one ... the interface

Code: [Select]

import java.io.InputStream;

public interface Pathbuilder {
public InputStream  createPath(String filename) throws Exception ;
}

38
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;
}
}

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

40
Feedback / Free e books
« on: November 21, 2006, 05:56:58 pm »
Aha ! just in the middle of the google ads ... bad glasses :D
thanks

41
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 !

42
Support / JPCT in PS2
« on: November 21, 2006, 12:45:30 am »
So ... there is some light at the end of the tunnel !
and its not the train hehehe

tks

43
Feedback / Software development
« on: November 20, 2006, 08:48:29 pm »
I like to think about the classes as workers ... :D dont overload then, and dont let then stay without work.

I believe that seems to be too simplistic, but simple concepts helps to drive our mind in the design, of course some patterns helps a lot, not to follow as is , but to see how to adapt then in each case, evaluating your code scenarios against some others already evaluated problems.

hope my 2 cents help on something, Im really new to gaming projets, but in the IT arena, 15 yrs over my back hehehe :D thats why Im moving to games now, I'm tired of CRUDs !

44
Support / JPCT in PS2
« on: November 20, 2006, 08:32:09 pm »
yes playstation 2

45
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 2 [3] 4