Main Menu
Menu

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.

Show posts Menu

Messages - tom3001

#1
I have a mesh, only consisting of single-sided polygons.

Thus, when I load the *.3ds model into JPCT, only one side of the mesh is visible.

Is there an option to make all polygons of that mesh visible from both sides?
#2
Support / Re: Creating 3D-Objects "on the fly" ...
August 29, 2011, 01:21:15 AM
I got the solution:

it was: world.removeObject(...);

Thanks anyway.
#3
Support / Creating 3D-Objects "on the fly" ...
August 28, 2011, 11:21:16 PM
Hi.

Here's my problem:

I have a big, empty flat world I can walk around in. So far, everything works fine.

Now I want to put some trees in that world. I have three different "types" of trees. Oak, Fir, and Beech. The placing of all the trees in that world is determined by a fractal algorithm. Therefore, I never know how many trees (or how much of one type) are standing in my current environment, while I'm walking through that world. My visible range in every direction is ~ 1 mile.

Because of the Garbage collector, it seems not efficient to create the trees during runtime.

So, I thought about loading my meshes for Oak, Fir, and Beech on startup into three static 3D-Objects, which are cloned dynamically on runtime as the need arises. Because the clones are references, the memory usage would stay small, right?

The problem is, if I walk from a forest of Oaks into a forest of Firs, what shall I do with all the Oaks? How can I delete the clone objects in order to free some memory? Or is there a way to reassign the mesh-reference of a clone object? And how can I add a new clone object on the fly into the world anyway?

Or would it be better to create three big arrays of trees at startup? For Example:

Oaks[100]; Firs[100]; Beeches[100];

Placing all of them "down under" at startup, and making them visible via xyz-transformation during runtime????

Well ... I think there's a more elegant solution for my problem than that, isn't there?
#4
Support / Re: Vintage Flight-Simulator
September 29, 2009, 04:41:01 PM
 :-\ I see.... is it possible to increase the z-buffers precision instead of increasing the distance between the planes?

I just tried another approach... I put the ground-plane into a new world object. Then, after drawing that world I'm clearing the z-buffer with clearZBufferOnly(). It works quite good, and I don't need to do any spacing anymore to avoid Z-Fighting. But clearZBufferOnly() seems to slow down the whole thing a little bit, right?

Regards
#5
Support / Re: Vintage Flight-Simulator
September 29, 2009, 02:24:24 PM
#6
Support / Vintage Flight-Simulator
September 29, 2009, 02:02:04 PM
Hi.

I improved my Flight-Sim Project a bit. The Horizon is working well now. I'm using a big plane, rotating dynamically with the camera. That solution is IMHO better and simpler than the one with two domes...

You can look around with arrowkeys, and move around with w,a,s,d keys.

One problem is, when you move high above the ground, the landing-pad isn't drawn properly. I suppose it's a math-rounding issue of the painter-algorithm; I tried to lower the ground-plane a little bit, to avoid this problem, but if you fly far away from ground, this "little bit" gets too small...
I tried to play around with the setSortOffset() method on the ground-plane, but it didn't chance anything... do you have any suggestions??

Here is my code:



import com.threed.jpct.*;

import javax.swing.*;



import java.awt.Color;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;



public class HorizonTest implements KeyListener {



private static float PI = (float) Math.PI;



private World world = null;

private FrameBuffer buffer = null;

private Object3D box = null;

private Object3D plane = null;

private Object3D[] grid = null;

private Object3D[] wobjects = null;

private JFrame frame = null;



// half size of the grid

int gridsize_x = 6;

int gridsize_z = 6;



// Rotation control variables

private boolean doLeftRotation = false;

private boolean doRightRotation = false;

private boolean doUpRotation = false;

private boolean doDownRotation = false;

private boolean doMoveForward = false;

private boolean doMoveBackward = false;

private boolean doRollLeft = false;

private boolean doRollRight = false;



float xpos=-200, ypos=-50, zpos=0;

float xangle=0, yangle=0, zangle=0;

int oldcx=0, oldcz=0;



public static void main(String[] args) throws Exception {

new HorizonTest().loop();

}



public HorizonTest() throws Exception {



// Setup the frame

frame = new JFrame("Horizon Test");

frame.setSize(800, 600);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

frame.addKeyListener(this);



Config.farPlane = 1700;



// Set up the worlds

world = new World();



//world.setAmbientLight(127, 127, 127);

world.setAmbientLight(255, 255, 255);



// Define textures

TextureManager.getInstance().addTexture("earth", new Texture(16,16,new Color(0,170,0)));

TextureManager.getInstance().addTexture("sky", new Texture(16,16,new Color(85,255,255)));

TextureManager.getInstance().addTexture("red", new Texture(16,16,new Color(255,0,0)));

TextureManager.getInstance().addTexture("grid", new Texture(16,16,new Color(85,85,85)));

TextureManager.getInstance().addTexture("landingpad", new Texture(16,16,new Color(200,200,200)));



// Some box somewhere else

box = Primitives.getBox(10f, 1f);

box.translate(0, -10f, -100f); // Place it on the ground

box.getPolygonManager().setPolygonTexture(8, 3);

box.rotateY(PI / 4f);

world.addObject(box);



// Add ground-grid

int count = 0;

grid = new Object3D[gridsize_x*gridsize_z*4];

for (int z=-gridsize_z; z<gridsize_z; z++) {

for (int x=-gridsize_x; x<gridsize_x; x++) {

grid[count] = Primitives.getBox(1f, 1f);

grid[count].setTexture("grid");

grid[count].translate(200 * x, -1f, 200 * z); // Place it on the ground

world.addObject(grid[count]);

count++;



}

}



// Horizon plane

plane = Primitives.getPlane(1, 10000);

plane.setTexture("earth");

plane.translate(0, 1f, 0);

plane.rotateX(PI / 2f);

world.addObject(plane);



addLandingPad();



world.buildAllObjects();



// View

Camera cam = world.getCamera();

cam.setFOV(1.5f);

}



private void loop() throws Exception {

buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);



while (frame.isShowing()) {

doMovementUpdate();

buffer.clear(new Color(85,255,255));

world.renderScene(buffer);

world.draw(buffer);

buffer.update();

buffer.display(frame.getGraphics(),0,0);

Thread.sleep(10);

}

buffer.disableRenderer(IRenderer.RENDERER_OPENGL);

buffer.dispose();

frame.dispose();

System.exit(0);

}



private void addLandingPad() {

int numobjects = 1;

wobjects = new Object3D[numobjects];

wobjects[0] = new Object3D(2);

wobjects[0].addTriangle(new SimpleVector(0,0,0),new SimpleVector(100,0,0),new SimpleVector(0,0,1000));

wobjects[0].addTriangle(new SimpleVector(100,0,1000),new SimpleVector(100,0,0),new SimpleVector(0,0,1000));

wobjects[0].rotateY(PI / 2f);

wobjects[0].translate(100,0,-450);

wobjects[0].setTexture("landingpad");

wobjects[0].setCulling(false);



world.addObject(wobjects[0]);

}



private void updateGrid() {

SimpleVector v = world.getCamera().getPosition();



int cx = Math.round(v.x / 200) * 200;

int cz = Math.round(v.z / 200) * 200;



int dx = cx - oldcx;

int dz = cz - oldcz;



for (int i=0; i<grid.length; i++) {

grid[i].translate(dx, 0, dz);

}



plane.translate(dx, 0, dz);



oldcx = cx;

oldcz = cz;

}





// Rotates the horizon plane with the camera

private void updateHorizon(float angle) {

plane.rotateY(angle);

}



private void doMovementUpdate() {



float rotval= 0.01f;

float speed = 1.3f;   // default = 1.3f



if (doLeftRotation) {

yangle -= rotval;

updateHorizon(-rotval);

}

if (doRightRotation) {

yangle += rotval;

updateHorizon(rotval);

}

if (doUpRotation) {

xangle -= rotval;

}

if (doDownRotation) {

xangle += rotval;

}

if (doMoveForward) {

if (ypos > -4) {

world.getCamera().rotateX(xangle);

world.getCamera().rotateZ(zangle);

xangle=0;

zangle=0;

world.getCamera().moveCamera(Camera.CAMERA_MOVEUP, 1);

}

world.getCamera().moveCamera(Camera.CAMERA_MOVEIN, speed);

SimpleVector v = world.getCamera().getPosition();

xpos = v.x;

ypos = v.y;

zpos = v.z;

updateGrid();

}

if (doMoveBackward) {

if (ypos > -4) {

world.getCamera().rotateX(xangle);

world.getCamera().rotateZ(zangle);

xangle=0;

zangle=0;

world.getCamera().moveCamera(Camera.CAMERA_MOVEUP, 1);

}

world.getCamera().moveCamera(Camera.CAMERA_MOVEOUT, speed);

SimpleVector v = world.getCamera().getPosition();

xpos = v.x;

ypos = v.y;

zpos = v.z;

updateGrid();

}

if (doRollLeft) {

zangle += rotval;

}

if (doRollRight) {

zangle -= rotval;

}



world.getCamera().setPosition(xpos,ypos,zpos);

world.getCamera().lookAt(new SimpleVector(xpos+1,ypos,zpos));

world.getCamera().rotateY(-yangle);

world.getCamera().rotateX(-xangle);

world.getCamera().rotateZ(-zangle);



System.out.println("pos(" + Math.round(xpos/100) + "," + Math.round(zpos/100) + ")");

}



@Override

public void keyPressed(KeyEvent e) {



int keyCode = e.getKeyCode();

//System.out.println("key code : " + keyCode);



if (keyCode == 37) { // left arrow

doLeftRotation = true;

}

else if (keyCode == 39) { // right arrow

doRightRotation = true;

}

else if (keyCode == 38) { // up arrow

doUpRotation = true;

}

else if (keyCode == 40) { // down arrow

doDownRotation = true;

}

else if (keyCode == 87) { // "w"

doMoveForward = true;

}

else if (keyCode == 83) { // "s"

doMoveBackward = true;

}

else if (keyCode == 65) { // "a"

doRollLeft = true;

}

else if (keyCode == 68) { // "d"

doRollRight = true;

}

}



@Override

public void keyReleased(KeyEvent e) {

int keyCode = e.getKeyCode();

//System.out.println("key code : " + keyCode);



if (keyCode == 37) { // left arrow

doLeftRotation = false;

}

else if (keyCode == 39) { // right arrow

doRightRotation = false;

}

else if (keyCode == 38) { // up arrow

doUpRotation = false;

}

else if (keyCode == 40) { // down arrow

doDownRotation = false;

}

else if (keyCode == 87) { // "w"

doMoveForward = false;

}

else if (keyCode == 83) { // "s"

doMoveBackward = false;

}

else if (keyCode == 65) { // "a"

doRollLeft = false;

}

else if (keyCode == 68) { // "d"

doRollRight = false;

}

}



@Override

public void keyTyped(KeyEvent e) {

}



private void tileTexture(Object3D obj, float tileFactor) {

PolygonManager pm = obj.getPolygonManager();



int end = pm.getMaxPolygonID();

for (int i = 0; i < end; i++) {

SimpleVector uv0 = pm.getTextureUV(i, 0);

SimpleVector uv1 = pm.getTextureUV(i, 1);

SimpleVector uv2 = pm.getTextureUV(i, 2);



uv0.scalarMul(tileFactor);

uv1.scalarMul(tileFactor);

uv2.scalarMul(tileFactor);



int id = pm.getPolygonTexture(i);



TextureInfo ti = new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y,

uv2.x, uv2.y);

pm.setPolygonTexture(i, ti);

}

}

}

#7
Support / Re: How to create a simple skybox horizon?
September 17, 2009, 02:06:54 AM
Thank you, it's working now!
#8
Support / Re: How to create a simple skybox horizon?
September 16, 2009, 07:26:59 PM
Ok, I tried it, but the behaviour of the domes is somewhat strange. You have to look up and down to the see sky or the horizon...
Here is my source code. You can look around with arrow keys, and alter the Z-Angle with Numblock + and -.

The *.3ds dome-files are here:
sky.3ds : http://www.box.net/shared/o5xuh2g1m8
earth.3ds : http://www.box.net/shared/ilymqjk1mm

What am I doing wrong?  ???


import com.threed.jpct.*;
import javax.swing.*;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public class HorizonTest implements KeyListener {

private static float PI = (float) Math.PI;

private World world = null;
private World horizon = null;
private FrameBuffer buffer = null;
private Object3D box = null;
private Object3D earthdome = null;
private Object3D skydome = null;
private JFrame frame = null;

public static void main(String[] args) throws Exception {
new HorizonTest().loop();
}

public HorizonTest() throws Exception {

// Setup the frame
frame = new JFrame("Horizon Test");
frame.setSize(800, 600);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.addKeyListener(this);

// Set up the worlds
world = new World();
horizon = new World();
world.setAmbientLight(127, 127, 127);
horizon.setAmbientLight(255, 255, 255);

// Define textures
TextureManager.getInstance().addTexture("earth", new Texture(16,16,new Color(0,170,0)));
TextureManager.getInstance().addTexture("sky", new Texture(16,16,new Color(85,255,255)));

// Some box at the origin
box = Primitives.getBox(10f, 1f);
box.translate(0, 0.5f, 0); // Place it on the ground
world.addObject(box);

// Prepare the Earthdome
earthdome = Object3D.mergeAll(Loader.load3DS("earth.3ds", 2));
earthdome.build();
earthdome.rotateX(-PI / 2f);
earthdome.setTexture("earth");
earthdome.calcTextureWrap();
tileTexture(earthdome, 3);
earthdome.translate(box.getTransformedCenter().calcSub(earthdome.getTransformedCenter()));
earthdome.setLighting(Object3D.LIGHTING_NO_LIGHTS);

// Prepare the Skydome
skydome = Object3D.mergeAll(Loader.load3DS("sky.3ds", 2));
skydome.build();
skydome.rotateX(-PI / 2f);
skydome.setTexture("sky");
skydome.calcTextureWrap();
tileTexture(skydome, 3);
skydome.translate(box.getTransformedCenter().calcSub(skydome.getTransformedCenter()));
skydome.setLighting(Object3D.LIGHTING_NO_LIGHTS);

// Build
horizon.addObject(earthdome);
horizon.addObject(skydome);

world.buildAllObjects();

earthdome.compileAndStrip();
skydome.compileAndStrip();

// View
Camera cam = world.getCamera();
cam.setPosition(0,0,-150);
cam.lookAt(new SimpleVector(0,0,0));
cam.setFOV(1.5f);
}

private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);

while (frame.isShowing()) {

// Update the camera
horizon.getCamera().setBack(world.getCamera().getBack().cloneMatrix());

buffer.clear();
horizon.renderScene(buffer);
horizon.draw(buffer);
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.display(frame.getGraphics(),0,0);
Thread.sleep(10);
}

buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
frame.dispose();
System.exit(0);
}

public void keyPressed(KeyEvent e) {

int keyCode = e.getKeyCode();

//System.out.println("key code : " + keyCode);

if (keyCode == 37) { // left arrow
world.getCamera().rotateCameraY(-0.05f);
}
else if (keyCode == 38) { // up arrow
world.getCamera().rotateCameraX(-0.05f);
}
else if (keyCode == 39) { // right arrow
world.getCamera().rotateCameraY(0.05f);
}
else if (keyCode == 40) { // down arrow
world.getCamera().rotateCameraX(0.05f);
}
else if (keyCode == 109) { // numblock "-"
world.getCamera().rotateCameraZ(-0.05f);
}
else if (keyCode == 107) { // numblock "+"
world.getCamera().rotateCameraZ(0.05f);
}
}

public void keyReleased(KeyEvent e) {
}

public void keyTyped(KeyEvent e) {
}

private void tileTexture(Object3D obj, float tileFactor) {
PolygonManager pm = obj.getPolygonManager();

int end = pm.getMaxPolygonID();
for (int i = 0; i < end; i++) {
SimpleVector uv0 = pm.getTextureUV(i, 0);
SimpleVector uv1 = pm.getTextureUV(i, 1);
SimpleVector uv2 = pm.getTextureUV(i, 2);

uv0.scalarMul(tileFactor);
uv1.scalarMul(tileFactor);
uv2.scalarMul(tileFactor);

int id = pm.getPolygonTexture(i);

TextureInfo ti = new TextureInfo(id, uv0.x, uv0.y, uv1.x, uv1.y,
uv2.x, uv2.y);
pm.setPolygonTexture(i, ti);
}
}
}
#9
Support / How to create a simple skybox horizon?
September 16, 2009, 03:58:46 PM
Hi.

What I'm trying to do is to create a simple horizon, as seen in old flightsim games. In fact just a monocolored blue sky and a green earth. I'd like to realize this by a second world called "horizonworld". That world actually contains TWO domes, one for the sky, and the other one for earth. I tried to modify the "AdvancedExample" at the jpct tutorial page, but I didn't succeed.

Can you please help me, or make a suggestion for a different/simpler approach? Thanks.