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 hereand this is the game class, with what I tried
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 :
![](http://www.riogdug.org/files/rearview_creation_black_rectangle_211.jpg)