Login  Register

Re: Objects fall outside simpleuniverse

Posted by philjord on Jul 26, 2018; 6:39am
URL: https://forum.jogamp.org/Objects-fall-outside-simpleuniverse-tp4039062p4039070.html

If you add this line:
                u.getViewer().getView().setFieldOfView(Math.PI/2);
below this line:
u.getViewingPlatform().setNominalViewingTransform();


You will set the field of view to 90 degrees, 90 degrees is exactly PI/2 radians which is the units accepted by setFieldOfView
If you look at the source here:
https://github.com/hharrison/java3d-core/blob/master/src/javax/media/j3d/View.java#L851
you'll see the default field of view is set to 45 degrees (with the maths to make that a radian figure)

This is a bit low for most applications and 60-70 is probably a better default value.

You could also get your object on screen by moving the virtual "camera" backwards, this is done by setting the TransformGroup of the view platform like this:

                //move viewer platform back a bit
                ViewingPlatform viewingPlatform = u.getViewingPlatform();
                // View model from top
                TransformGroup viewPlatformTransform = viewingPlatform.getViewPlatformTransform();
                Transform3D transform = new Transform3D();
                transform.setTranslation(new Vector3f(0, 0, 10));
                viewPlatformTransform.setTransform(transform);


Notice that positive Z is "out of the screen", and this is an absolute move, so we are not altering the position by an amount  but setting it to that exact figure.

The setNominalViewingTransform call that's in your code now is attempts to get the sphere on screen by moving the platform back.
If you put this code
                ViewingPlatform viewingPlatform = u.getViewingPlatform();
                // View model from top
                TransformGroup viewPlatformTransform = viewingPlatform.getViewPlatformTransform();
                Transform3D transform = new Transform3D();
                viewPlatformTransform.getTransform(transform);
                System.out.println("" + transform );

 after the line:
u.getViewingPlatform().setNominalViewingTransform();

on my system this shows the platform to be at 0,0,2.414 (for matrices just read the right hand column for the x,y,z figures) which on my system makes the test color cube visible.

Can you confirm that when you use color cubes instead of your sphere Shape3D that you can see the objects? Can you see the 3 grid reference cubes I put in the demo code? Can you orbit with the mouse and see everything rotating?

Thansk.