 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Thomas Partsch Guest
|
Posted: Tue Oct 17, 2006 3:06 pm Post subject: SimpleUniverse VS VirtualUniverse |
|
|
Hi!
In my current project I am using the VirtualUniverse class instead of
the SimpleUniverse, because I need two views that are displayed
simultaneously (for a stereoscopic view). So the views are working fine,
but I obviously got a problem with PickBehaviors.
With SimpleUniverse the PickBehaviors are working fine (picking and
rotating, translating and scaling of two boxes). But in my
VirtualUniverse the PickBehaviors don't work fine at all: You have to
pick the box somewhere else in the Canvas, e.g. if the box is in the
middle of the screen, you have to pick it on the left side of it. This
is quite strange to me.
So my question is: What is so special about the SimpleUniverse that the
Behaviors work there just fine and in the VirtualUniverse they don't?
Greetings
Thomas |
|
| Back to top |
|
 |
Alexander Gran Guest
|
Posted: Wed Oct 18, 2006 5:22 am Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Thomas Partsch schrieb:
| Quote: | So my question is: What is so special about the SimpleUniverse that the
Behaviors work there just fine and in the VirtualUniverse they don't?
|
No Idea. But SimpleUniverse just does:
locale = new Locale(this, origin);
viewingPlatform.setUniverse( this );
// Assign object references.
this.viewer = new Viewer[1];
this.viewer[0] = viewer;
// Add the ViewingPlatform to the Viewer object.
this.viewer[0].setViewingPlatform(viewingPlatform);
// Add the ViewingPlatform to the locale - the scene
// graph is now "live".
locale.addBranchGraph(viewingPlatform);
and in public static GraphicsConfiguration getPreferredConfiguration() {
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
String stereo;
// Check if the user has set the Java 3D stereo option.
// Getting the system properties causes appletviewer to fail with a
// security exception without a try/catch.
stereo = (String) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
return System.getProperty("j3d.stereo");
}
});
// update template based on properties.
if (stereo != null) {
if (stereo.equals("REQUIRED"))
template.setStereo(template.REQUIRED);
else if (stereo.equals("PREFERRED"))
template.setStereo(template.PREFERRED);
}
// Return the GraphicsConfiguration that best fits our needs.
return GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getBestConfiguration(template);
}
(quick look in the sources. You should try to act similar and then perhaps
do a bissect search?)
regards
Alex
--
Some operating systems are called `user friendly',
Linux however is `expert friendly'.
Encrypted Mails welcome. Send spam to toZodiac (AT) gmx (DOT) net, please.
PGP-Key at http://www.grans.eu/misc/pgpkey.asc | Key-ID: 0x6D7DD291 |
|
| Back to top |
|
 |
Thomas Partsch Guest
|
Posted: Wed Oct 18, 2006 3:00 pm Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Ok, thanks. There are some differences to my VirtualUniverse. First, I
haven't defined a ViewingPlatform at all, neither a Viewer object. But I
have got two ViewPlatforms. Actually I am a bit confused.
If I have 2 ViewPlatforms do there have to be 2 ViewingPlatforms, too?
And 2 Viewer objects?
I have got 2 windows. One for the left and one for the right eye.
Currently there is a ViewPlatform for each eye. And they are both in the
same universe, of course. All that is set in each window, is
- tgView.addChild(viewPlatform); //where tgView is connected to the
ViewBranch of the Scenegraph.
- view.attachViewPlatform(viewPlatform);
- view.setLeftProjection(camera);//where camera is a Transform3D with a
set frustum.
- other things like PhysicalBody(), PhysicalEnvironment(),
GraphicsConfiguration I considered not imporant for this problem.
How do I add the other stuff from the SimpleUniverse?
yours,
Thomas
Alexander Gran schrieb:
| Quote: | Thomas Partsch schrieb:
So my question is: What is so special about the SimpleUniverse that the
Behaviors work there just fine and in the VirtualUniverse they don't?
No Idea. But SimpleUniverse just does:
locale = new Locale(this, origin);
viewingPlatform.setUniverse( this );
// Assign object references.
this.viewer = new Viewer[1];
this.viewer[0] = viewer;
// Add the ViewingPlatform to the Viewer object.
this.viewer[0].setViewingPlatform(viewingPlatform);
// Add the ViewingPlatform to the locale - the scene
// graph is now "live".
locale.addBranchGraph(viewingPlatform);
and in public static GraphicsConfiguration getPreferredConfiguration() {
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
String stereo;
// Check if the user has set the Java 3D stereo option.
// Getting the system properties causes appletviewer to fail with a
// security exception without a try/catch.
stereo = (String) java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction() {
public Object run() {
return System.getProperty("j3d.stereo");
}
});
// update template based on properties.
if (stereo != null) {
if (stereo.equals("REQUIRED"))
template.setStereo(template.REQUIRED);
else if (stereo.equals("PREFERRED"))
template.setStereo(template.PREFERRED);
}
// Return the GraphicsConfiguration that best fits our needs.
return GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getBestConfiguration(template);
}
(quick look in the sources. You should try to act similar and then perhaps
do a bissect search?)
regards
Alex
|
|
|
| Back to top |
|
 |
Alexander Gran Guest
|
Posted: Thu Oct 19, 2006 7:14 pm Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Thomas Partsch schrieb:
| Quote: | Ok, thanks. There are some differences to my VirtualUniverse. First, I
haven't defined a ViewingPlatform at all, neither a Viewer object. But I
have got two ViewPlatforms. Actually I am a bit confused.
If I have 2 ViewPlatforms do there have to be 2 ViewingPlatforms, too?
And 2 Viewer objects?
|
Sorry, I have no Idea whatsoever ;)
regards
Alex
--
Some operating systems are called `user friendly',
Linux however is `expert friendly'.
Encrypted Mails welcome. Send spam to toZodiac (AT) gmx (DOT) net, please.
PGP-Key at http://www.grans.eu/misc/pgpkey.asc | Key-ID: 0x6D7DD291 |
|
| Back to top |
|
 |
Mark Hood Guest
|
Posted: Sat Oct 21, 2006 7:10 am Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Thomas Partsch <thomas (AT) thomepage (DOT) de> writes:
| Quote: | Ok, thanks. There are some differences to my VirtualUniverse. First, I
haven't defined a ViewingPlatform at all, neither a Viewer object. But
I have got two ViewPlatforms. Actually I am a bit confused.
If I have 2 ViewPlatforms do there have to be 2 ViewingPlatforms, too?
And 2 Viewer objects?
|
Your confusion is understandable given the similar names.
The ViewingPlatform is a Java 3D utility class
(com.sun.j3d.utils.universe.ViewingPlatform) that extends BranchGroup
and contains a ViewPlatform Java 3D core class
(javax.media.j3d.ViewPlatform). It's simply a convenient base for
building a bunch of other utility classes and behaviors (such as
SimpleUniverse), and if you're not going to use any of the utility
classes you don't need it.
Viewer is also a universe utility and simply wraps a View along with
some other stuff like a Canvas3D list and an Avatar. If you use Views
directly you don't need it.
| Quote: | I have got 2 windows. One for the left and one for the right
eye. Currently there is a ViewPlatform for each eye. And they are both
in the same universe, of course. All that is set in each window, is
- tgView.addChild(viewPlatform); //where tgView is connected to the
ViewBranch of the Scenegraph.
- view.attachViewPlatform(viewPlatform);
- view.setLeftProjection(camera);//where camera is a Transform3D with
a set frustum.
|
The setLeftProjection() method of View is a low level compatibility
mode method for porting camera-model apps and disables the standard
built-in Java 3D view model (which is not based on a camera, but
rather the locations of the user's eyes in the VirtualUniverse). The
Pick behaviors are utility classes that rely on the standard Java 3D
view model and won't work if you set the projection yourself. You'll
need to use the core Java 3D picking methods in Locale instead, which
are all view-independent, geometry-based methods.
The standard Java 3D view model is capable of generating stereo pairs
on 2 windows by using the the setMonoscopicViewPolicy() method of
Canvas3D with View.LEFT_EYE_VIEW and View.RIGHT_EYE_VIEW respectively
(normally the policy is set to View.CYCLOPEAN_EYE_VIEW). By default
these use the eye positions as set in the PhysicalBody. The
PhysicalBody models the user's head, with its origin set to middle of
the two eye positions. The view model defaults set the origin and
orientation of the PhysicalBody to be the same as the ViewPlatform,
but in units of physical meters instead of virtual units; the scaling
is controlled by View.setScreenScalePolicy() and whatever scaling is
composed into the transform above the ViewPlatform. You only need to
use a single View and ViewPlatform with these two Canvas3D instances.
| Quote: | - other things like PhysicalBody(), PhysicalEnvironment(),
GraphicsConfiguration I considered not imporant for this problem.
|
They're essential to using the standard Java 3D view model and the
Picking utility behaviors though. If you have specific projection
matrices that you must use, then you'll have to code your own picking
behaviors to construct PickShapes that align with your view direction
and individual projection frustums.
The Java 3D view model isn't very well documented unfortunately. I
suggest subscribing to the Java 3D interest forum at
http://forums.java.net/jive/forum.jspa?forumID=70 and searching for
the info you need. To get the real details of what's going on, you
could also try reading the source code to the utility class
com.sun.j3d.utils.universe.ViewInfo, which documents the standard view
model with code.
Good luck -- Mark |
|
| Back to top |
|
 |
Thomas Partsch Guest
|
Posted: Sat Oct 21, 2006 2:01 pm Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Wow, thats lots of information. Thank you very much. I already posted a
question in this forum. I'll have to think about your words later, last
night was too much ;)
greetings
Thomas
Mark Hood schrieb:
| Quote: | Thomas Partsch <thomas (AT) thomepage (DOT) de> writes:
Ok, thanks. There are some differences to my VirtualUniverse. First, I
haven't defined a ViewingPlatform at all, neither a Viewer object. But
I have got two ViewPlatforms. Actually I am a bit confused.
If I have 2 ViewPlatforms do there have to be 2 ViewingPlatforms, too?
And 2 Viewer objects?
Your confusion is understandable given the similar names.
The ViewingPlatform is a Java 3D utility class
(com.sun.j3d.utils.universe.ViewingPlatform) that extends BranchGroup
and contains a ViewPlatform Java 3D core class
(javax.media.j3d.ViewPlatform). It's simply a convenient base for
building a bunch of other utility classes and behaviors (such as
SimpleUniverse), and if you're not going to use any of the utility
classes you don't need it.
Viewer is also a universe utility and simply wraps a View along with
some other stuff like a Canvas3D list and an Avatar. If you use Views
directly you don't need it.
I have got 2 windows. One for the left and one for the right
eye. Currently there is a ViewPlatform for each eye. And they are both
in the same universe, of course. All that is set in each window, is
- tgView.addChild(viewPlatform); //where tgView is connected to the
ViewBranch of the Scenegraph.
- view.attachViewPlatform(viewPlatform);
- view.setLeftProjection(camera);//where camera is a Transform3D with
a set frustum.
The setLeftProjection() method of View is a low level compatibility
mode method for porting camera-model apps and disables the standard
built-in Java 3D view model (which is not based on a camera, but
rather the locations of the user's eyes in the VirtualUniverse). The
Pick behaviors are utility classes that rely on the standard Java 3D
view model and won't work if you set the projection yourself. You'll
need to use the core Java 3D picking methods in Locale instead, which
are all view-independent, geometry-based methods.
The standard Java 3D view model is capable of generating stereo pairs
on 2 windows by using the the setMonoscopicViewPolicy() method of
Canvas3D with View.LEFT_EYE_VIEW and View.RIGHT_EYE_VIEW respectively
(normally the policy is set to View.CYCLOPEAN_EYE_VIEW). By default
these use the eye positions as set in the PhysicalBody. The
PhysicalBody models the user's head, with its origin set to middle of
the two eye positions. The view model defaults set the origin and
orientation of the PhysicalBody to be the same as the ViewPlatform,
but in units of physical meters instead of virtual units; the scaling
is controlled by View.setScreenScalePolicy() and whatever scaling is
composed into the transform above the ViewPlatform. You only need to
use a single View and ViewPlatform with these two Canvas3D instances.
- other things like PhysicalBody(), PhysicalEnvironment(),
GraphicsConfiguration I considered not imporant for this problem.
They're essential to using the standard Java 3D view model and the
Picking utility behaviors though. If you have specific projection
matrices that you must use, then you'll have to code your own picking
behaviors to construct PickShapes that align with your view direction
and individual projection frustums.
The Java 3D view model isn't very well documented unfortunately. I
suggest subscribing to the Java 3D interest forum at
http://forums.java.net/jive/forum.jspa?forumID=70 and searching for
the info you need. To get the real details of what's going on, you
could also try reading the source code to the utility class
com.sun.j3d.utils.universe.ViewInfo, which documents the standard view
model with code.
Good luck -- Mark |
|
|
| Back to top |
|
 |
Thomas Partsch Guest
|
Posted: Sun Oct 22, 2006 9:02 pm Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
Hi Mark!
| Quote: | You only need to
use a single View and ViewPlatform with these two Canvas3D instances.
|
If that is correct, then it should be possible to use the SimpleUniverse
like this:
public class TwoBoxes {
private SimpleUniverse universe;
private EyeFrame leftFrame, rightFrame;
private Canvas3D leftCanvas3D, rightCanvas3D;
//PhysXBehavior physXBehavior = new PhysXBehavior();
public TwoBoxes()
{
this.universe = new SimpleUniverse();
//Create the two canvases in a left and right frame
leftFrame = new EyeFrame(EyeFrame.LEFT_EYE,leftCanvas3D);
rightFrame = new EyeFrame(EyeFrame.RIGHT_EYE,rightCanvas3D);
universe.getViewer().getView().addCanvas3D(leftCanvas3D);
universe.getViewer().getView().addCanvas3D(rightCanvas3D);
BranchGroup bgScene = createScene();
//Bounds for Behaviors
BoundingSphere behaviorBounds = new BoundingSphere(new Point3d(0.0,
0.0, 0.0), 100.0);
setupPickBehaviors(bgScene, behaviorBounds);
this.universe.addBranchGraph(bgScene);
}
public BranchGroup createScene() {
// Create the root of the branch graph
BranchGroup scene = new BranchGroup();
[...]
return scene;
}
public static void main(String[] args) {
new TwoBoxes();
}
}
The Canvas3Ds are initialized in the class EyeFrame, where the
MonoscopicViewPolicy is also set.
Unfortunately, the program produces only a white frame, the scenegraph
is obviously not painted. I can't tell why, the code for the scene part
is almost exactly the same as before (with two views and so on...).
Full source code you'll find at
http://www.thomepage.de/kram/java3d/2ndViewTest/
Hope, you can help.
greetings
Thomas |
|
| Back to top |
|
 |
Thomas Partsch Guest
|
Posted: Sun Oct 22, 2006 9:41 pm Post subject: Re: SimpleUniverse VS VirtualUniverse |
|
|
And solved!
Sorry, that really was kind of a 'newbie mistake'... You can't hand over
a null-pointer and then expect a created object.
So now I've got some kind of default view on the scene and can hopefully
change the view by scaling it or something without killing the behaviors...
Thanks, so far.
Thomas
| Quote: | Hi Mark!
You only need to
use a single View and ViewPlatform with these two Canvas3D instances.
If that is correct, then it should be possible to use the SimpleUniverse
like this:
public class TwoBoxes {
private SimpleUniverse universe;
private EyeFrame leftFrame, rightFrame;
private Canvas3D leftCanvas3D, rightCanvas3D;
//PhysXBehavior physXBehavior = new PhysXBehavior();
public TwoBoxes()
{
this.universe = new SimpleUniverse();
//Create the two canvases in a left and right frame
leftFrame = new EyeFrame(EyeFrame.LEFT_EYE,leftCanvas3D);
rightFrame = new EyeFrame(EyeFrame.RIGHT_EYE,rightCanvas3D);
universe.getViewer().getView().addCanvas3D(leftCanvas3D);
universe.getViewer().getView().addCanvas3D(rightCanvas3D);
BranchGroup bgScene = createScene();
//Bounds for Behaviors
BoundingSphere behaviorBounds = new BoundingSphere(new
Point3d(0.0, 0.0, 0.0), 100.0);
setupPickBehaviors(bgScene, behaviorBounds);
this.universe.addBranchGraph(bgScene);
}
public BranchGroup createScene() {
// Create the root of the branch graph
BranchGroup scene = new BranchGroup();
[...]
return scene;
}
public static void main(String[] args) {
new TwoBoxes();
}
}
The Canvas3Ds are initialized in the class EyeFrame, where the
MonoscopicViewPolicy is also set.
Unfortunately, the program produces only a white frame, the scenegraph
is obviously not painted. I can't tell why, the code for the scene part
is almost exactly the same as before (with two views and so on...).
Full source code you'll find at
http://www.thomepage.de/kram/java3d/2ndViewTest/
Hope, you can help.
greetings
Thomas |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|