Somthing is wrong with the view and I don't know how to fix it. The first
attached image (java3d.gif) is how it looks using Java3D. The perspective
seems be drawn "backwards". The other attached image (rhino.gif) is how it's
suppossed to look.

All the view settings are default as far as I can tell. I've included the
source code for your examination (icosa.java).

I've looked into this and haven't made any headway. (I just finished
spending a day and a half figuring out why my object was rendering as solid
white.) My guess at the moment is that somehow the order of the view items
and the object goes in this order:

You               (The person viewing the display)
The display       (The virtual screen that is rendered to)
The scene         (The objects you are viewing)
The point of view (The reference point from which rays would be cast
                   in ray-tracing)

The "correct" order should be:

Both you and the point of view (Should be one and the same)
The display
The scene

I hope I explained this decently. Any help of pointers would be appriciated.

Ouroborus


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com

java3d.gif

rhino.gif

   import javax.media.j3d.*;
   import javax.vecmath.*;
   import java.applet.*;
   import java.awt.*;
   import com.sun.j3d.utils.geometry.*;
   import com.sun.j3d.utils.universe.*;

   public class icosa extends Object
   {
      public static void main( String[] args ) {
         Frame frame = new Frame( );
         frame.setSize( 400, 400 );
         frame.setLayout( new BorderLayout( ) );

         Canvas3D canvas = new Canvas3D( null );
         frame.add( "Center", canvas );

         SimpleUniverse univ = new SimpleUniverse( canvas );
         univ.getViewingPlatform( ).setNominalViewingTransform( );

         BranchGroup scene = createSceneGraph( );
         scene.compile( );
         univ.addBranchGraph( scene );

         frame.show( );
      }

      private static BranchGroup createSceneGraph( )
      {
      // Make a scene graph branch
         BranchGroup branch = new BranchGroup( );

      // Generic bounding sphere
         BoundingSphere myBounds = new BoundingSphere( new Point3d(), 1000.0 );

      // Make background
         Background myBackground = new Background(0.0f, 0.5f, 0.5f);
         myBackground.setApplicationBounds( myBounds );
         branch.addChild( myBackground );

      // Make a directional light
         DirectionalLight myLight = new DirectionalLight( );
         myLight.setEnable( true );
         myLight.setColor( new Color3f( 1.0f, 1.0f, 1.0f ) );
         Vector3f lightdir = new Vector3f( -1.0f, 1.0f, -1.0f );
         lightdir.normalize();
         myLight.setDirection( lightdir );
         myLight.setInfluencingBounds( myBounds );
         branch.addChild( myLight );

      // Make an ambient light
         AmbientLight myLight2 = new AmbientLight();
         myLight2.setEnable(true);
         myLight2.setColor( new Color3f( 0.5f, 0.5f, 0.5f ) );
         myLight2.setInfluencingBounds( myBounds );
         branch.addChild( myLight2 );

      // Scale the object
         TransformGroup trans = new TransformGroup( );
         Transform3D trans3d = new Transform3D( );
         trans.getTransform( trans3d );
         Matrix3d rotation = new Matrix3d();
         trans3d.getRotationScale(rotation);
        // Match the angle in the ray tracer
         rotation.rotY(180.0d - 38.8028d);
         trans3d.setRotationScale(rotation);
         trans3d.setScale( 0.5d );
         trans.setTransform( trans3d );
         branch.addChild( trans );

      // Make a changeable 3D transform
         TransformGroup trans2 = new TransformGroup( );
         trans2.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE );
         trans.addChild( trans2 );

      // Make a shape
         trans2.addChild( constructIsoca() );
      /*
      // Make a behavor to spin the shape
         Alpha spinAlpha = new Alpha( -1, 4000 );
         RotationInterpolator spinner = new RotationInterpolator( spinAlpha, trans2 );
         spinner.setSchedulingBounds( new BoundingSphere( new Point3d( ), 1000.0 ) );
         trans2.addChild( spinner );
      */
         return branch;
      }

      private static Point3d[] vertices;
      private static int[] indices = {
         0,2,1,10, 9,6,
         0,3,2,11,10,6,
         0,4,3, 7,11,6,
         0,5,4, 8, 7,6,
         0,1,5, 9, 8,6 };
      private static int[] stripCounts = { 6, 6, 6, 6, 6 };

      private static Shape3D constructIsoca() {
         if (vertices == null)
         {
            double a = Math.sqrt(0.8d);//
            double b = Math.sqrt(0.2d);//
            double c = Math.sqrt(0.05d);//
            double d = Math.sqrt(0.5d + c);//
            double e = Math.sqrt(0.5d - c);//
            double h = -b;
            double i = -d;
            double j = -e;

            vertices = new Point3d[12];
            vertices[ 0] = new Point3d(0.0d, 0.0d, 1.0d);
            vertices[ 1] = new Point3d(   a, 0.0d,    b);
            vertices[ 2] = new Point3d(   e,    d,    b);
            vertices[ 3] = new Point3d(   i,    e,    b);
            vertices[ 4] = new Point3d(   i,    j,    b);
            vertices[ 5] = new Point3d(   e,    i,    b);
            vertices[ 6] = new Point3d(0.0d, 0.0d,-1.0d);
            vertices[ 7] = new Point3d(  -a, 0.0d,    h);
            vertices[ 8] = new Point3d(   j,    i,    h);
            vertices[ 9] = new Point3d(   d,    j,    h);
            vertices[10] = new Point3d(   d,    e,    h);
            vertices[11] = new Point3d(   j,    d,    h);
         }

         GeometryInfo shape = new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
         shape.setCoordinates(vertices);
         shape.setCoordinateIndices(indices);
         shape.setStripCounts(stripCounts);

      // Use 0 instead of Math.PI to get sharp edges.
         new NormalGenerator(Math.PI).generateNormals(shape);

         Shape3D shape3d = new Shape3D(shape.getIndexedGeometryArray(true));
         Appearance app = new Appearance();

         app.setMaterial(new Material());

         shape3d.setAppearance(app);

         return shape3d;
      }
   }

Reply via email to