我目前正在学习我的学生项目。其中一部分是在立体视图中渲染加载的.OBJ文件(真正的立体镜,而不是红色/蓝色阴影)。我能够加载.OBJ文件并在两个视图中呈现它:对于左眼和右眼,但我坚持在双缓冲区上渲染它。这是它的样子:
以下是代码:
public class ObjStereoscope extends JFrame{
Canvas3D c1 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
Canvas3D c2 = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
private SimpleUniverse u = null;
private BranchGroup scene = null;
private JPanel mainPanel = null;
public ObjStereoscope() {
super();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
init(device);
}
public void init(GraphicsDevice dev) {
this.setUndecorated(true);
//this.setIgnoreRepaint(true);
try {
dev.setFullScreenWindow(this);
} finally {
dev.setFullScreenWindow(null);
}
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainPanel = new JPanel();
mainPanel.setLayout(new FlowLayout());
this.setLayout(new FlowLayout());
this.add(mainPanel);
setExtendedState(this.getExtendedState() | JFrame.MAXIMIZED_BOTH);
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
c1.setSize(500, 500);
c1.setMonoscopicViewPolicy(View.LEFT_EYE_VIEW);
mainPanel.add(c1);
c2.setSize(500, 500);
c2.setMonoscopicViewPolicy(View.RIGHT_EYE_VIEW);
mainPanel.add(c2);
mainPanel.repaint();
scene = makeScene();
u = new SimpleUniverse(c1);
View view0 = u.getViewer().getView();
View view = new View();
PhysicalBody myBod = view0.getPhysicalBody();
myBod.setLeftEyePosition(new Point3d(-.006, 0.0, 0.0)); // default
// is(-0.033,
// 0.0, 0.0)
myBod.setRightEyePosition(new Point3d(+.006, 0.0, 0.0));
view.setPhysicalBody(myBod);
view.setPhysicalEnvironment(view0.getPhysicalEnvironment());
view.attachViewPlatform(u.getViewingPlatform().getViewPlatform());
view.addCanvas3D(c2);
view.repaint();
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
private BranchGroup makeScene() {
BranchGroup branchGroup = new BranchGroup();
Transform3D rotation1 = new Transform3D();
Transform3D ratation2 = new Transform3D();
rotation1.rotX(Math.PI / 4.0d);
ratation2.rotY(Math.PI / 5.0d);
rotation1.mul(ratation2);
TransformGroup objTrans = new TransformGroup(rotation1);
objTrans.setCapability(17); // 17
objTrans.setCapability(18); // 18
ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
Scene scene = null;
try {
scene = file.load(ClassLoader.getSystemResource("penguin.obj"));
} catch (FileNotFoundException e) {
System.err.println(e);
} catch (ParsingErrorException e) {
System.err.println(e);
} catch (IncorrectFormatException e) {
System.err.println(e);
} catch (Exception e) {
System.err.println(e);
}
objTrans.addChild(scene.getSceneGroup());
DirectionalLight d_Licht = new DirectionalLight(new Color3f(0.7f, 1.5f, 0.3f), new Vector3f(1.0f, -10.0f, 1.0f));
d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d));
objTrans.addChild(d_Licht);
BoundingSphere bounds = new BoundingSphere();
MouseRotate spin = new MouseRotate();
spin.setTransformGroup(objTrans);
spin.setSchedulingBounds(bounds);
branchGroup.addChild(spin);
branchGroup.addChild(objTrans);
return branchGroup;
}
public static void main(String[] args) {
new ObjStereoscope();
}
}
我的问题是:
1)是否可以在Java3D中使用多个缓冲区进行立体渲染?如果是,怎么样?
2)我是否需要一些额外的硬件来实现立体声?我需要实现它,应用程序将在带有主动眼镜的立体显眼镜上呈现。这个例子在我的电脑上运行正常:
3)提前感谢您的帮助。我将非常感激。