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

Pages: 1 ... 6 7 [8]
Support / texture aliasing
« on: March 23, 2006, 08:50:07 pm »

this is what Egon said in an email:
Texture aliasing is an undersampling artifact that occurs, when only a few samples of a texture (due to the size of the polygon) are taken to draw the image.

Hardware is using mip mapping (i.e. smaller textures for smaller polygons in the distance) to work against this. The software renderer doesn't do this, because determining the correct mipmap level would be quite expensive. To prevent it (well, you can't really prevent it, just try to minimize the effect) use textures with less contrast and/or larger structures.

i guess, no matter how one selects a texture, he cannot avoid texture aliasing for objects like grass, trees etc due to the nature of thier texture.

so how to beat it when using software renderer ?

i thought of emulating mip mapping to some degree by re-assigning objects' textures based on distance, but i'm quite unsure if it worths a try. for trees it may help, but for large objects like ground it wont. (since camera is close to some part of object and far to other) this approach will also break 3DSLoader's multiple texture assignments to a single object. it requires an Object3D.recreateTextureCoords() each time the texture size changed (i dont know how expensive it is)

using PolygonManager to set textures per polygon instead of per object maybe an alternative but i guess doing that for every polygon will be a sure performance killer. also i dont know if there is a way of getting all polyon id's

so is there a nice solution for this ?

Code: [Select]
r a f t

Support / animation loop
« on: March 21, 2006, 04:22:36 am »
well, first of all this is not a jPCT question, it's about the strange behaviour of my animation loop on some rare machines. i have no idea why and when that happens, maybe you may have

i've taken the animation loop below from a book about Java games and slightly modified

as you can see, the main idea is to keep updates per second constant (as much as the desired fps = 1 / period). it works reasonably well on most machines (including my slow one) but on some rare ones, updates per second increases unexpectedly up to 2-3 times.  

i've no idea how that can happen ? i can only blame window's system clock granularity or sleep time inaccuracies (even with sleep time inaccuracies that loop shouldnt expected to run faster ??)

so do you have any ideas why this may happen ?

edit: the mentioned book by Andrew Davison can be found online at

Code: [Select]

            long beforeTime, afterTime, timeDiff, sleepTime;
            long overSleepTime = 0;
            int noDelays = 0;
            long excess = 0;
            running = true;
            while(running) {
                try {
                    beforeTime = System.nanoTime();
                    if (! paused)
                    afterTime = System.nanoTime();
                    timeDiff = afterTime - beforeTime;
                    sleepTime = (period - timeDiff) - overSleepTime;
                    if (sleepTime > 0) { // some time left in this cycle
                        try {
                            Thread.sleep(sleepTime/1000000L); // nano -> ms
                        } catch(InterruptedException ex) {}
                        overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
                    } else { // sleepTime <= 0; frame took longer than period
                        excess -= sleepTime; // store excess time value
                        overSleepTime = 0L;
                        if (++noDelays >= KConfig.noDelaysPerYield) {
                            Thread.yield(); // give another thread a chance to run
                            noDelays = 0;
                    } // if-else (sleepTime > 0)
                    /* If rendering is taking too long, update the game state without rendering it, to get the updates/sec nearer to the required FPS. */
                    int skips = 0;
                    while (running && (excess > period) && (skips < KConfig.maxFrameSkips)) {
                        excess -= period;
                        gameUpdate(); // update state but don't render
                } catch (Throwable t) {
                    logger.warning("exception in timer thread {0}", t);
            } // while running

Code: [Select]
r a f t

Support / sort offset
« on: March 19, 2006, 02:35:37 am »

how should Object3D.setSortOffset(float) be used ? javadoc says it sets on offset for the z-Sorting but i couldnt get it. i guess it's sth like objects are sorted by given float for render but what about the camera ? should one track where the camera is by himself and set the sort offset accordingly ?

i'm having a strange rendering artifact:  it seems like polygons are sliding when camera approachs to them, as can be seen in image below. i have two transparent objects one covering another. the inner one is actually rendered (it has visible pixels) but the outer one is never seen (all black) and used for collision purposes.

strange rendering disappears if i dont put the outer one into to the world.  that made me think this may have something with that sort offset thing.

so how should i use Object3D.setSortOffset() thing ?

Code: [Select]
r a f t
ps: the two objects arent that close, the inner one is fine grained (has a lot of polygons) but the outer one is a simple box with 6 faces.
ps2: infact the invisible one is inside, but their normals are looking inside and the camera in always inside ;)

Support / serial version uid
« on: November 02, 2005, 02:00:08 pm »
egon, can u please add a serial version uid to serializable classes ? it becomes incompatible with the previous version and it breaks loading previously serialized objects. sun suggests it too and it wont hurt for sure

Code: [Select]
private static final long serialVersionUID = 999L; // or whatever long

of course you can change it in time when it is necessary (such as when internal fields are not backward compatible)

and when did you update the site, i must have missed it. it looks nice :wink:

Code: [Select]
r a f t

Support / active rendering with AWTGLRenderer
« on: July 22, 2005, 07:59:44 pm »

how can one do active rendering with AWTGLRenderer. such an animation loop doesnt cause Canvas to be painted immediately
Code: [Select]

Canvas canvas = frameBuffer.enableGLCanvasRenderer(IRenderer.MODE_OPENGL);
while(running) {
    canvas.repaint(); // this wont make the canvas to be painted immediately, but later

if canvas.repaint() is replaced with
Code: [Select]


this also fails since animation loop doesnt run in AWT-Thread's context. If we run these in AWT-Thread then we block the AWT-Thread and cause AWT and Swing events not to be dispatched. i looked for a method to dispatch all waiting AWT events and return but couldnt find.

so what is the solution ? i'm missing something i guess

and one more thing: although GLCanvasRenderer initializes fine on my box, OpenGL renderer doesnt. it complains about the VideoMode. (i tried all available modes FrameBuffer.getVideoModes(..) returns) lwjgl demos also work fine. i find this strange since  both GLCanvasRenderer and OpenGL renderer uses lwgl

Code: [Select]
r a f t

Projects / aptal karga (foolish crow)
« on: March 24, 2005, 01:59:36 am »
in shortest terms, karga is a 3d chat system. it can also be called a simple virtual reality enviroment

similar to multiplayer games, users can move around in 3d places, see and talk to each other, change their appearance, interact with the enviroment and each other (like dancing and kissing)

hopefully, in the future there will be much game elements like puzzles, vehicles, usable items, team based games etc.

Code: [Select]
r a f t

since it still has a long way to complete 3d chat, i somehow changed my direction and updated the site accordingly. i assumed 3d artists would jump onto chat project but this was not the case unfortunately  :shock:

i prepared a demo for web to move user in a 3d model as first person. its almost nothing more than the fps sample but a 'render when necessary' version of it to make it web and cpu friendly. as always its the jpct what creates the magic

i find it a quite cool application for architects. well this is my idea, time will show if people will find it alike

the model is from (unfortunately) an anonymous artist at

wish me luck, i wanna neither to sell my bike nor be a slave again 8)
Code: [Select]
r a f t

edit: added karga definition for newcomers

Support / camera basics
« on: February 25, 2005, 04:27:02 pm »

i am moving camera in a simple world (an xz plane at origin) with

Code: [Select]
SimpleVector normalizedDirection = direction.normalize();
world.checkCameraCollisionEllipsoid(normalizedDirection, COLLISION_ELLIPSOID, moveSpeed, RECURSE_DEPTH);

when i move camera down (+y) i expected it go down to COLLISION_ELLIPSOID.y but this is not the case. independent of ellipsoid.y it moves to ellipsoid.z + a small amount depending on move speed.

couldnt get why ?

Code: [Select]
r a f t
moveSpeed : 2 - 10

Feedback / kind of brain storming
« on: February 16, 2005, 01:52:27 am »

as a dreamer i am trying to develop a chat system in which you may move around. maybe kind of virtual reality system at very very later phases..

well, after toying with jpct and with helge's valuable helps i am not that far from moving in a 3d world and animating characters according to their state. (walking, dancing etc)

here is what i have: a world description with node groups and nodes as leafs. users and world entities (items etc) can only exist in a node. i assumed nodes as parts (mostly rooms) of a building and node groups as buildings.

to minimize network traffic and hence to increase speed, clients are loaded with users' starting node group and its current state (user positions etc). any movement from node to node (in same group) generates a user moved event to user and a one moved event to users of that node group. moving among node groups requires loading of new group and state. (just like switching levels in an fps)

the idea behind this was to optimize network traffic (download size and game speed). downloading and generating event for all of the world both increases the initial download size and event broadcasting amount.

the mechanism is grounded on this: part of world is serialized to client at the beginning and it is reconstructed identical to server's one at client side as need arrives. (moves at node group or jump from group to group)

i planned all that with the idea of no real time graphics: with at most a static image of the node user is in.

now with a desire to fit graphics to it, i am looking for the best way to integrate it with jpct.

one idea is to map karga's nodes to a jpct world and make no change in karga's node definition. genarate 'user moved in node' events and send them to users of that node.

or use octree nodes or portal sectors mapped to karga nodes (this seems harder to implement. by the way, is there any way to define portals in 3dmax, without the need to define portals externally with exact coordinates ?) of course genarate 'user moved in node' events is necessary again.

or is there a way to define nodes as floating but not static. (position in 3d space with a radius etc.) and still generate user moved events ?

another main problem is either to make it fps like (camera at user's eye) or not (camera around user. adjusting itself's position according to user's position in the current scene)
this way or other it comes to problem of network speed and latency. like fps, we need to broadcast every keystroke of user (maybe some optimization is possible) to clients. with outer camera (movement with mouse clicks to destination) it can be implemented with sending only destination point. (say you are moving from one side to other side of a room, like fps it requires lots of movement events (key strokes) to be broadcasted, with outer camera only one event: destination point). does anyone imagine any user friendly way to move with mouse clicks while looking from user's eyes ?

trying to look rationally it seems to chose outer camera and movement with mouse clicks as far more reasonable. but i really wanna it like to be a first person shooter. i am asking myself contsantly, which is the point of optimal trade off ?

well thats are the main questions to answer before going any further. i am open to and in fact looking for any smart and/or efficient ideas.

Code: [Select]
r a f t
maybe it's best to try both and see what   :?:

Support / visible sides
« on: February 09, 2005, 06:23:44 pm »
hi all,

first of all i must mention jpct really seems great :)

i am just a newbea at computer graphics and toying with it to grasp the basics.

i loaded a 3ds model and rotate the camera around it. for a model with one or two objects it is all-well. but with three, four or more objects, i couldnt manage to draw them properly. they are either not drawn or drawn half like the camera at completely different point.

first i suspected if 3dmax exporting fails. i retried it one object in 3ds file and cloning object or by reloading the file. still couldnt manage it.

stranger enough world.getVisibilityList().getSize() seems to remain constant at 4097.

what may be wrong ? below is the complete source. you may try it with any 3ds file.

Code: [Select]

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.threed.jpct.*;

public class Test1 {
private final static SimpleVector STARTING_POS = new SimpleVector(0, 2, -150);
private final static SimpleVector CAMERA_TARGET = new SimpleVector(0, 1, 0);

private World world;
private FrameBuffer buffer;
private RenderPanel panel;
private Timer timer;

private Test1(String[] args) throws Exception {
String fileName = args[0];
float scale = args.length >= 2 ? Float.parseFloat(args[1]) : 1f;
int period = args.length >= 3 ? Integer.parseInt(args[2]) : 100;
int copies = args.length >= 4 ? Integer.parseInt(args[3]) : 3;

world = new World();

for (int i = 0; i < copies; i++) {
FileInputStream fis = new FileInputStream(args[0]);
Object3D[] os = Loader.load3DS(fis, scale);
System.out.println("loaded objects size: " + os.length + " scale: " + scale);

for (int oIndex = 0; oIndex < os.length; oIndex++) {
Object3D o = os[oIndex];
o.rotateX((float) (Math.PI / -2f)); // since 3dmax coordinate system differ
o.translate(new SimpleVector(20 * i, 20 * i, 20 * i)); // move this
System.out.println("added object " + o.getName());


Camera camera = world.getCamera();

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

JFrame frame = new JFrame("testing jpct");

panel = new RenderPanel();
panel.setPreferredSize(new Dimension(600, 400));
panel.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e) {
if (timer.isRunning())
else timer.start();


timer = new Timer(period, new ActionListener(){
// no need to synchronize this stuff since paint and this is both called in awt's thread
public void actionPerformed(java.awt.event.ActionEvent e) {
Camera camera = world.getCamera();

SimpleVector v = camera.getPosition();
v.rotateY((float) (Math.PI / 20));




class RenderPanel extends JPanel {
public void paintComponent(Graphics g) {

world.drawWireframe(buffer, Color.ORANGE);

g.drawImage(buffer.getOutputBuffer(), 0, 0, null);
                  g.drawString("running..", 10, 15);

g.drawString("visible size: " + world.getVisibilityList().getSize(), 10, 30);
g.drawString("camera: " + world.getCamera().getPosition(), 10, 45);

public static void main(String[] args) throws Exception {
System.out.println("usage: test1 <3ds file> [scale] [update period im ms] [# copies]");

Test1 test1 = new Test1(args);

r a f t

Pages: 1 ... 6 7 [8]