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
16
News / Away from keyboard for one week
« on: December 07, 2006, 12:01:21 am »
picture... please pictures !! :D
have fun !!

17
Support / trying to understand the Car sample 2
« on: December 06, 2006, 11:57:45 pm »
hehehehe,
no car game, just trying to cover the concepts of an generic game, as I'm learning all about this new world :)

but ... to reveal the secrets ... me and some other 2 are planning to begin the matrix, and those models will be projected inside the freezing humans :)

moving from my crazy side, we are planning a game for the new year, something about simulation, working on the story and some game details now.

18
Support / rearview mirror
« on: December 06, 2006, 04:58:19 pm »
Mizuki,
reflexive texture... humm is there possible to put one texture one over the other like layers ? if so we can use the technique that I used and merge the original texture, with a view of something that is around, creating the reflexive effect ... :D

19
Support / rearview mirror
« on: December 06, 2006, 04:55:24 pm »
the problem was the size restrictions of the Texture, I changed the size of the viewport and averybody got happy !!! thanks !!!


20
Support / rearview mirror
« on: December 06, 2006, 04:28:00 pm »
I got the problem ! I was updating the framebuffer AFTER the display ... like this is harder to see something hehehehe, anyway now at least I see something ... still wrong ... probably the size of the texture or something like this ...

the FPS are increasing :) around 10 when hanging around the mirror and around 20 without the mirror


21
Support / rearview mirror
« on: December 06, 2006, 02:24:34 pm »
thanks worked fine !!!

Code: [Select]
public void apply(int[] dest, int[] source) {
System.arraycopy(fb.getPixels(), 0, dest, 0, fb.getPixels().length);
}


trying to optimize the code, I'm looking for a way to remove the Graphics operations, and use the blit method, in order to draw the upper box with a blit over the main frambuffer

done this :

this the method to draw the current viewport
Code: [Select]
public void display(FrameBuffer buffer, int x, int y) {
if (buffer != null) {
buffer.blit(getTexture(), 0, 0, x, y, getTexture().getWidth(),
getTexture().getHeight(), false);
}
// fb.display(g, x, y);
}


that is called by (that its in my game class)
Code: [Select]
public void afterPaintComponent(Graphics g) {

rearview.display(getBuffer(), 30, 30);

g.setColor(Color.WHITE);
g.drawRect(30, 30, 300, 100);
g.drawString(Integer.toString(lastFPS) + "FPS", 15, 15);
}


and its called by my gamesuper class (that is a Jcomponent)
Code: [Select]
protected void paintComponent(Graphics g) {
if (buffer != null) {
buffer.display(g, leftBorderWidth, titleBarHeight);
afterPaintComponent(g);
}
}


but ... I got nothing at the white box ...

22
Projects / Buggaroo
« on: December 06, 2006, 04:41:42 am »
nice to play ... :D but in the first times I didn't notice that I could shoot ... :) took me some tries to discover that  :D

23
Support / rearview mirror
« on: December 06, 2006, 04:11:29 am »
I tried this way :

Code: [Select]
public class ViewPortEffect implements ITextureEffect {

private FrameBuffer fb;

public ViewPortEffect(FrameBuffer fb) {
this.fb = fb;
}

public void apply(int[] dest, int[] source) {
dest = fb.getPixels();
}

public void init(Texture arg0) {
}


}


and set the effect to the Texture object

Code: [Select]
public ViewPort(World master, int width, int height) {

this.camera = new Camera();
this.width = width;
this.height = height;
this.w = master;

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

texture = TextureManager.getInstance().getDummyTexture();
texture.setEffect(new ViewPortEffect(fb));

// buffer = new BufferedImage(width, height,
// BufferedImage.TYPE_INT_RGB);
// g2 = buffer.createGraphics();

}


at my loop the render method of the viewport is called

Code: [Select]
public void render() {
Camera foo = w.getCamera();
w.setCameraTo(camera);

fb.clear();
w.renderScene(fb);
w.draw(fb);
fb.update();
texture.applyEffect();

w.setCameraTo(foo);
}


and at the creation of the objects I set the texture to the new one ...

Code: [Select]
mirror = new ViewPort(getWorld(), 256, 256);
Camera c = mirror.getCamera();
getTextureManager().replaceTexture("mirror", mirror.getTexture());

c.setPosition(80, -70, 80);
c.lookAt(SimpleVector.ORIGIN);


but I got nothing at the mirror ... any idea ? I'm missing something ?

24
Support / rearview mirror
« on: December 05, 2006, 01:33:34 pm »
done !! only one world and multiple cameras, and the mirror I'm rendering in a BufferedImage and changing the Texture in the TextureManager ... hehehe dont know if this is the best aproach ... but its working, the performance its not fantastic, but I'm trying to tune it ...


this is funny screenshot mirror seeing it self ... :)

25
Support / rearview mirror
« on: December 04, 2006, 12:02:13 pm »
Egon,

is there possible to set something at the Object3D to allow the use in multiple worlds ? doing like this I would be able to set more than one camera with less objects in memory.

26
Support / disable System.out
« on: December 02, 2006, 08:04:26 pm »
perfect !
Code: [Select]
Logger.setLogLevel(Logger.LL_ONLY_ERRORS);

thanks !!

27
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 {
}

}));

28
Support / more mirrors ... :)
« on: December 02, 2006, 05:41:14 pm »
Oh well, I really like this challenge ! :)
soh I implemented the class ViewPort to be like a second view of an world, and add the possbility to create an texture with the current framebuffer of it

the result was pretty nice (I think ...)



This is the ViewPort class

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

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Enumeration;

import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Texture;
import com.threed.jpct.World;

public class ViewPort {

private World w;

private FrameBuffer fb;

private int width;

private int height;

public ViewPort(World master, int width, int height) {

this.width = width;
this.height = height;

w = new World();
Enumeration objects = master.getObjects();
while (objects.hasMoreElements()) {
AbstractEntity element = (AbstractEntity) objects.nextElement();
AbstractEntity clone = new AbstractEntity(element.cloneObject());
element.addSyncObject(clone);
w.addObject(clone);
}
w.buildAllObjects();

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

public void render() {
fb.clear();
w.renderScene(fb);
w.draw(fb);
fb.update();
}

public World getWorld() {
return w;
}

/**
* draws the world using the framebuffer in the informed Graphics at the
* position (x,y)
*
* @param g
* @param x
* @param y
*/
public void display(Graphics g, int x, int y) {
fb.display(g, x, y);
}

/**
* returns the draw result of the view port in a texture
*
* @return
*/
public Texture getTexture() {
BufferedImage buffer = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);

Graphics2D g2 = buffer.createGraphics();
display(g2, 0, 0);

return new Texture(buffer);
}
}


This is the class that is using the ViewPort class

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

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

import com.foo.game.test.Pathbuilder;
import com.foo.game.util.AbstractEntity;
import com.foo.game.util.CameraUtil;
import com.foo.game.util.FPSListener;
import com.foo.game.util.LightUtil;
import com.foo.game.util.PlaneUtil;
import com.foo.game.util.SimpleGame;
import com.foo.game.util.ViewPort;
import com.threed.jpct.Camera;
import com.threed.jpct.Config;
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;

public class RearViewGame extends SimpleGame implements FPSListener {

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;

private int lastFPS = 0;

private ViewPort rearview;

private ViewPort mirror;

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

addTexture("rocks", "textures/rocks.jpg");
addTexture("floor", "textures/floor.jpg");

AbstractEntity[] list = new AbstractEntity[4];

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

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

// the mirror
list[3] = new AbstractEntity(Primitives.getPlane(50, 3));
list[3].translate(100, -50, 100);
getTextureManager().addTexture("mirror",
getTextureManager().getDummyTexture());
list[3].setTexture("mirror");

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

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

mirror = new ViewPort(getWorld(), 256, 256);
Camera c = mirror.getWorld().getCamera();
c.setPosition(100, -50, 100);
c.lookAt(SimpleVector.ORIGIN);

rearview = new ViewPort(getWorld(), 300, 100);
c = rearview.getWorld().getCamera();
c.setPosition(50, -100, 50);
c.lookAt(SimpleVector.ORIGIN);

LightUtil.addDefaultLight(getWorld());
LightUtil.addDefaultLight(rearview.getWorld());
LightUtil.addDefaultLight(mirror.getWorld());
addFPSListener(this);
}

public void afterPaintComponent(Graphics g) {

rearview.display(g, 30, 30);

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

g.drawString(Integer.toString(lastFPS) + "FPS", 15, 15);
}

public void loop() {
rearview.render();
mirror.render();
getTextureManager().replaceTexture("mirror", mirror.getTexture());

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

public void notifyFPS(int fps) {
lastFPS = fps;
}

}

29
Support / rearview mirror
« on: December 02, 2006, 03:37:17 pm »
source code for the implementation of an rearview mirror =) (this is to help google ...)
http://www.athanazio.pro.br/wp-content/uploads/2006/11/rearwindow_src_20061202.zip

some interesting pieces ... :)

the game class

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

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.AbstractEntity;
import com.foo.game.util.CameraUtil;
import com.foo.game.util.FPSListener;
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 implements FPSListener{

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;
private int lastFPS = 0;

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

AbstractEntity[] list = new AbstractEntity[3];

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

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

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

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

World rearViewWorld = new World();

FrameBuffer rearViewBuffer;

private void createRearViewWorld() {
rearViewWorld = new World();
Enumeration objects = getWorld().getObjects();
while (objects.hasMoreElements()) {
AbstractEntity element = (AbstractEntity) objects.nextElement();
AbstractEntity clone = new AbstractEntity( element.cloneObject());
[b] element.addSyncObject(clone);
[/b] rearViewWorld.addObject(clone);
}
rearViewWorld.buildAllObjects();

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

[b]rearViewBuffer = new FrameBuffer(300, 100,
FrameBuffer.SAMPLINGMODE_NORMAL);[/b]
rearViewBuffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);

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

}

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

[b] public void afterPaintComponent(Graphics g) {
[/b]
rearViewBuffer.display(g, 30, 30);

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

g.drawString(Integer.toString(lastFPS) + "FPS", 15, 15);
}

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

public void notifyFPS(int fps) {
lastFPS = fps;
}


}

30
Support / rearview mirror
« on: December 02, 2006, 03:27:08 pm »
aha !!!
now is working !!

http://www.athanazio.pro.br/wp-content/uploads/2006/11/testAppletRearView.html

What I made :
1. create a new World with a new FrameBuffer
2. add to my AbstractEntity (copied from the Car sample) some methods to deal with Object3D synchronization, if you change the master one the others are changed

3. and as cyberkilla said, another camera in other direction, hehehe worked fine !!

now I will try to do using an Texture, to offer object reflection :) lets see what happens ...

Pages: 1 [2] 3 4