code:
---------------------------------------------------------------------------
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Movement{
 private BoundingSphere boundsSphere;
 private double bounds = 10000;
 private TransformGroup vpTrans = null;
 private MouseRotate mRotate;
 private MouseTranslate mTranslate;
 private MouseZoom mZoom;
 private KeyNavigatorBehavior kBehavior;

 public Movement(SimpleUniverse su, TransformGroup TG){
  boundsSphere = new BoundingSphere(new Point3d(), bounds);
  Transform3D T3D = new Transform3D();
  Vector3f translate = new Vector3f();

  vpTrans = su.getViewingPlatform().getViewPlatformTransform
();
       translate.set( 0.0f, 0.0f, 69f);
   // Observers position
        T3D.setTranslation(translate);
        vpTrans.setTransform(T3D);

  mRotate = new MouseRotate(MouseBehavior.INVERT_INPUT);
  mRotate.setTransformGroup(vpTrans);
  mRotate.setSchedulingBounds(boundsSphere);

  mTranslate = new MouseTranslate();
  mTranslate.setTransformGroup(vpTrans);
  mTranslate.setSchedulingBounds(boundsSphere);

  mZoom = new MouseZoom(MouseBehavior.INVERT_INPUT);
  mZoom.setFactor(1);
  mZoom.setTransformGroup(vpTrans);
  mZoom.setSchedulingBounds(boundsSphere);

  kBehavior = new KeyNavigatorBehavior(vpTrans);
  kBehavior.setSchedulingBounds(boundsSphere);
 }
 public MouseRotate getMouseRotate(){
  return mRotate; }
 public MouseTranslate getMouseTranslate(){
  return mTranslate; }
 public MouseZoom getMouseZoom(){
  return mZoom; }
 public KeyNavigatorBehavior getKeyNavigator(){
  return kBehavior; }
}

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.util.Enumeration;
import com.sun.j3d.utils.image.TextureLoader;

public class Ray3dApp extends Applet{
    Appearance createTwistAppearance(){
        Appearance twistAppear = new Appearance();
  TextureLoader loader = new TextureLoader("TEST.jpg", this);
  ImageComponent2D image = loader.getImage();
  Texture2D texture = new Texture2D(Texture.BASE_LEVEL

  //Texture.ALLOW_LOD_RANGE_READ

 //| Texture.ALLOW_LOD_RANGE_WRITE

 , Texture.RGBA

 , image.getWidth()

 , image.getHeight());

  texture.setImage(0,image);
  texture.setEnable(true);
  twistAppear.setTexture(texture);

        twistAppear.setTransparencyAttributes(
    new TransparencyAttributes
(TransparencyAttributes.FASTEST, 0.1f));

  // ALTERNATIVE WITH MIPMAP
  /*final int SMALLEST = 1;
  int imageWidth, imageHeight, imageLevel;
        String filename = "earth0.jpg";
        System.out.println("attempt to load texture from file: "+filename);
        TextureLoader loader = new TextureLoader(filename, this);
        ImageComponent2D image = loader.getImage();

        if(image == null) {
            System.out.println("load failed for texture: "+filename);
        }

        imageWidth = image.getWidth();
        imageHeight = image.getHeight();

  Texture2D texture = new Texture2D
(Texture.MULTI_LEVEL_MIPMAP

 //| Texture.ALLOW_MIPMAP_MODE_READ

 //| Texture.ALLOW_LOD_RANGE_WRITE

   //Texture.BASE_LEVEL

 //| Texture.ALLOW_ENABLE_READ

 //| Texture.ALLOW_ENABLE_WRITE

 //| Texture.ALLOW_MIPMAP_MODE_READ

 //| Texture.ALLOW_IMAGE_READ

 ,Texture.RGBA,
                                imageWidth, imageHeight);
  imageLevel = 0;
  System.out.println("set image level: "+imageLevel+"
width: "+imageWidth
                    +"  height: "+imageHeight);
  texture.setImage(imageLevel, image);

     while (imageWidth > SMALLEST || imageWidth > SMALLEST){
   imageLevel++;
   if (imageWidth > SMALLEST) imageWidth /= 2;
   if (imageHeight > SMALLEST) imageHeight /= 2;
   System.out.print("load image
level: "+imageLevel+"  width: "+imageWidth
                  +"
height: "+imageHeight+" :: ");
   //filename = "earth"+(imageLevel+4)+".jpg";
   filename = "earth"+imageLevel+".jpg";
   System.out.print(filename + " ... ");
   loader = new TextureLoader(filename, this);
   image = loader.getImage();

   System.out.println("set image");
            texture.setImage(imageLevel, image);
  }
        texture.setMagFilter(Texture.BASE_LEVEL_POINT);
        texture.setMinFilter(Texture.MULTI_LEVEL_POINT);
        twistAppear.setTexture(texture);
        //TextureAttributes tAtt = new TextureAttributes();

        //tAtt.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE);
        //twistAppear.setTextureAttributes(tAtt);

        twistAppear.setTransparencyAttributes(
    new TransparencyAttributes
(TransparencyAttributes.FASTEST, 0.1f));
   //texture.setEnable(true);
      */
      //END OF MIPMAP

      return twistAppear;
    }
//
 public BranchGroup createSceneGraph(SimpleUniverse su) {
  BranchGroup objRoot = new BranchGroup();
  Appearance app = new Appearance();
  BoundingSphere bounds = new BoundingSphere(new Point3d
(),1000);


 TransformGroup TG = new TransformGroup();
 TG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    TG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    //TG.setBounds(new BoundingSphere(new Point3d(),200));
 objRoot.addChild(TG);
  Appearance appear = createTwistAppearance();
  Sphere earth = new Sphere
(63.78137f,Primitive.GENERATE_NORMALS |

  Primitive.GENERATE_TEXTURE_COORDS |

  Primitive.GEOMETRY_NOT_SHARED,200, appear);
  //objRoot.addChild(earth);
  Movement movement = new Movement(su,TG);
  /*   Alpha rotationAlpha = new Alpha(-1, 16000);

        RotationInterpolator rotator =
                 new RotationInterpolator(rotationAlpha, TG);
                         BoundingSphere mbounds = new BoundingSphere(new
Point3d(),637.8137f);
            rotator.setSchedulingBounds(mbounds);
        TG.addChild(rotator);
*/
  TG.addChild(earth);

  objRoot.addChild(movement.getMouseRotate());
  objRoot.addChild(movement.getMouseTranslate());
  objRoot.addChild(movement.getMouseZoom());
  objRoot.addChild(movement.getKeyNavigator());

  Background background = new Background(1.0f, 1.0f, 1.0f);
  background.setApplicationBounds(bounds);
        objRoot.addChild(background);
  objRoot.compile();
  return objRoot;
 }


 public Ray3dApp(){
  setLayout(new BorderLayout());
  GraphicsConfiguration gConfig =
SimpleUniverse.getPreferredConfiguration();
  Canvas3D canvas3D = new Canvas3D(gConfig);
  add("Center",canvas3D);
     canvas3D.setStereoEnable(false);

  SimpleUniverse sUniverse = new SimpleUniverse(canvas3D);
  sUniverse.getViewingPlatform().setNominalViewingTransform
();
  //sUniverse.setActivationRadius(40);
  BranchGroup scene = createSceneGraph(sUniverse);
  sUniverse.addBranchGraph(scene);
 }
 public static void main(String[] args) {
  //Frame frame = new MainFrame(new Ray3dApp(), 2048,1024 );
  Frame frame = new MainFrame(new Ray3dApp(), 512,512 );
    }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to