Problem where two surfaces meet

If ya run the attached code/demo, you will notice that the edge where blue and green/white surfaces meet is flickering... it is not solid as I would expect it to be and this my concern since it is a lot more noticable in my program. I am not sure how to get around with this and would appreciate any suggestions.

Thanx All,

import java.awt.*;

import javax.vecmath.*;

import javax.media.j3d.*;

import com.sun.j3d.utils.universe.*;

public class TestFrame extends java.awt.Frame {

public TestFrame() {

Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

add(canvas3D);

SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

simpleU.getViewingPlatform().setNominalViewingTransform();

simpleU.addBranchGraph(createBranchGroup());

}

protected BranchGroup createBranchGroup(){

BranchGroup branchGroup = new BranchGroup();

Transform3D transform = new Transform3D();

transform.set(new Vector3f(-3, 2, -20));

TransformGroup group = new TransformGroup(transform);

TransformGroup rotGroup = new TransformGroup();

rotGroup.addChild(new Shape());

rotGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

group.addChild(rotGroup);

RotationInterpolator interpolator = new RotationInterpolator(new Alpha(-1, 10000), rotGroup);

interpolator.setSchedulingBounds(new BoundingSphere());

group.addChild(interpolator);

branchGroup.addChild(group);

return branchGroup;

}

public static void main(String[] arg){

TestFrame frame = new TestFrame();

frame.setSize(300,300);

frame.setVisible(true);

}

class Shape extends Shape3D {

float [][] vertices = {

{-1.6667603f, -5.0f, 3.535534f}, {-1.6667603f, -5.0f, -3.535534f},

{-1.6667603f, -3.0f, -3.535534f}, {-1.6667603f, 5.0f, -3.535534f},

{-1.0893776f, 3.267949f, -2.7190602f} };

int [][] triangles = {{0, 1, 2}, {0, 2, 1}, {1, 4, 3}, {1, 3, 4}};

Color[] colors = {Color.red, Color.blue, Color.green, Color.white};

Shape(){

int format = TriangleArray.COORDINATES | TriangleArray.COLOR_3;// | GeometryArray.TEXTURE_COORDINATE_2;

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

TriangleArray triangle = new TriangleArray(3, format);

for(int k = 0; k < 3; k++) {

triangle.setCoordinates(k, vertices[triangles[k]]);

triangle.setColor(k, new Color3f(colors));

}

addGeometry(triangle);

}

}

}

}

[2586 byte] By [Appolloa] at [2007-9-19]
# 1

how much does it flicker?

the flickering is caused by z-buffer inaccuracy, and will always be present - however it is almost impossible to spot when using a 24 or 32bit zbuffer.

Normally the zbuffer bit depth is tied to the color bit depth of the display, are you running in 16bit color? if so, increase it to 32bit, and it should solve your flicker.

The problem of flicker is not directly linked to j3d, it is an issue with the underlying api (openGL, or D3D) and ultimatly the hardware.

rob,

Abusea at 2007-7-8 > top of java,Security,Cryptography...
# 2

thanx for your reply Abuse, (what a nick!:))

Im running in 32bit color. "flickering" is probably not the right word ... In fact it does not flicker ... the problem is that the edge where the two planes meet is not "solid" - it constantly changes. This is not very evident in the above demo. The demo shows only a part of the problem:the edge between blue and green/white planes moves (like in an on-off state), although it does not change the shape. Fixing this problem, I believe, would fix the other one too.

Thanx

Appolloa at 2007-7-8 > top of java,Security,Cryptography...
# 3

does it constantly change, even when the camera and objects are not moving? (i.e. everything stationary)

rob,

> thanx for your reply Abuse, (what a nick!:))

>

> Im running in 32bit color. "flickering" is probably

> not the right word ... In fact it does not flicker ...

> the problem is that the edge where the two planes meet

> is not "solid" - it constantly changes. This is not

> very evident in the above demo. The demo shows only a

> part of the problem:the edge between blue and

> green/white planes moves (like in an on-off state),

> although it does not change the shape. Fixing this

> problem, I believe, would fix the other one too.

>

> Thanx

>

Abusea at 2007-7-8 > top of java,Security,Cryptography...
# 4
i would test your code... but i dont have j3d sdk installed :-/
Abusea at 2007-7-8 > top of java,Security,Cryptography...
# 5
the edge changes its shape only when the object is moving ...
Appolloa at 2007-7-8 > top of java,Security,Cryptography...
# 6

thats definitly zbuffer inaccuracies then.

what gfx card are you using? have u tried using a different computer?

also, are you using the opengl or d3d version of j3d?

there must be a way of querying j3d to find out what bit depth zbuffer it is using... though i dont know how myself :P

rob,

Abusea at 2007-7-8 > top of java,Security,Cryptography...