Hi Guang,
There is bug in the test program
(1) In renderRight()
gc.clear();
gc.setBufferOverride(true);
gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
clear() will only clear STEREO_LEFT buffer since
it is set before. We should put this after
gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
Best of all, setting GraphicsContext3D.STEREO_BOTH
will only invoke clear() once instead of twice.
(2) There is no need to invoke swap() two times
- one for each buffer. Instead swap() will swap
both left/right buffer.
(3) No need to invoke
gc.setBufferOverride(true);
every frame, only one at the beginning is good
enough.
(4) There is no distingiush between left and right
GraphicsContext3D.
gc = canvas.getGraphicsContext3D();
...
gcLeft = canvas.getGraphicsContext3D();
They are the same.
I've modify your program (see attachment)
and it seems to run fine.
- Kelvin
>Delivered-To: [EMAIL PROTECTED]
>X-Originating-IP: [152.98.198.234]
>Mime-Version: 1.0
>X-OriginalArrivalTime: 14 Nov 2001 05:51:58.0856 (UTC)
FILETIME=[79623080:01C16CD0]
>Date: Wed, 14 Nov 2001 15:51:58 +1000
>From: Guang Bin Liu <[EMAIL PROTECTED]>
>Subject: [JAVA3D] Images not stable
>To: [EMAIL PROTECTED]
>
>Hi Friends:
>
>The attached are files for rendering two images to left/right eyes
>separately. I tested this program on two PCs with Window2000 and Geforce II
>200/400 cards. When I run it on the PC with GeForce II 400, the images
>appear / disappear intermittently (but the left eye can only view the left
>image and the right eye only view right image).
>
>When I tested it on another PC with GeForce II 200, the images appear
>continuously. But this time each eye will view two interchanging images
>intermittently (e.g., the left eye views the left image then righ image then
>left image again ...). Can you please help me diagnise the reason of this
>problem? Whether this is due to my Graphic Card configuration or due to
>bugs in Java3D?
>
>Thank you!
>
>Guang Bin Liu
>
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import javax.media.j3d.PhysicalBody;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
public class BrTestGratings extends Applet implements Runnable
{
View view, viewleft;
private Canvas3D canvas;
private GraphicsContext3D gc = null, gcLeft=null, gcAnu=null;
private Geometry grt0, grt1, grt2, grt3;
private Transform3D cmt = new Transform3D();
private Transform3D cmtleft=new Transform3D();
Transform3D temp=new Transform3D();
RotateGrating grat1=new RotateGrating();
RotateGrating grat2=new RotateGrating();
RotateGrating grat3=new RotateGrating();
private Alpha rotAlpha = new Alpha(-1, 20000);
Appearance appear=new Appearance();
Shape3D shape=new Shape3D();
Graphics grp;
private SimpleUniverse u = null;
static Dimension screenSize =java.awt.
Toolkit.
getDefaultToolkit().
getScreenSize();
Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);
Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
int numOfArray = 200;
double height=1.7, radius=1.2, step=1.0;
double angle;
public void renderLeft()
{
cmtleft.rotZ(Math.PI/2);
cmtleft.mul(cmt);
gc.setModelTransform(cmtleft);
gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
gc.draw(grt1);
// gc.draw(grt3);
}
public void renderRight()
{
gc.setModelTransform(cmt);
gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
gc.draw(grt2);
// gc.draw(grt3);
}
public void run()
{
grat3.setParameter(numOfArray, height, radius, step, red);
grt3=grat3.getRotate();
gc = canvas.getGraphicsContext3D();
view=canvas.getView();
grat2.setParameter(numOfArray, height, radius, step, green);
grt2=grat2.getRotate();
grat1.setParameter(numOfArray, height, radius, step, red);
grt1 =grat1.getRotate();
while (true) {
gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
gc.clear();
angle = rotAlpha.value() * 2.0*Math.PI;
cmt.rotY(-angle);
renderLeft();
renderRight();
canvas.swap();
}
}
public BrTestGratings()
{
}
public void init()
{
setLayout(new BorderLayout());
GraphicsConfigTemplate3D g3d = new GraphicsConfigTemplate3D();
g3d.setStereo(GraphicsConfigTemplate3D.REQUIRED);
GraphicsConfiguration config = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getBestConfiguration(g3d);
canvas = new Canvas3D(config);
canvas.stopRenderer();
canvas.setStereoEnable(true);
canvas.setDoubleBufferEnable(true);
add("Center", canvas);
u = new SimpleUniverse(canvas);
u.getViewingPlatform().setNominalViewingTransform();
new Thread(this).start();
}
public void destroy()
{
u.removeAllLocales();
}
public static void main(String[] args)
{
new MainFrame(new BrTestGratings(),
screenSize.width,
screenSize.height);
}
}
import javax.media.j3d.*;
import javax.vecmath.*;
public class RotateGrating
{
int N;// = 600;
Color3f colour;
double a=0, width, step;
int v;
double height, radius; //height=8.0, radius=4;
double shift=1.0;
QuadArray twistStrip;// = new QuadArray(N,
//QuadArray.COORDINATES | QuadArray.COLOR_3);
public void RotateGrating()
{
for(v = 0; v < N; v+=4, a=v*step*Math.PI/(N/2))
{
twistStrip.setCoordinate(v, new Point3d(radius*Math.cos(a),
height,radius*Math.sin(a)));
twistStrip.setCoordinate(v+1, new Point3d(radius*Math.cos(a),
-height,radius*Math.sin(a)));
twistStrip.setCoordinate(v+2, new Point3d(radius*Math.cos(a+width),
-height, radius*Math.sin(a+width)));
twistStrip.setCoordinate(v+3, new Point3d(radius*Math.cos(a+width),
height, radius*Math.sin(a+width)));
twistStrip.setColor(v, colour);
twistStrip.setColor(v+1, colour);
twistStrip.setColor(v+2, colour);
twistStrip.setColor(v+3, colour);
}
}
public Geometry getRotate()
{
return twistStrip;
}
public void setParameter(int numberOfArrayIn,
double heightIn,
double radiusIn,
double widthIn,
Color3f clr)
{
height=heightIn;
radius=radiusIn;
N=numberOfArrayIn;
step=widthIn;
width=step*Math.PI/(N/4);
twistStrip = new QuadArray(N,
QuadArray.COORDINATES | QuadArray.COLOR_3);
colour=clr;
RotateGrating();
}
}