# current viewposition



## Guest (27. Dez 2007)

hi leute!

hab schon die suche gequält und auch einiges gefunden, nur nichts was funktioniert so wie ich es gerne hätte. 

wie finde ich heraus, wo die aktuelle viewposition ist? ich würde gern ein element, von wo es sich befindet(positionpathinterpolator), bis zur viewposition bewegen.

den vorschlag von marco13 mit "vom transform3d die matrix3f holen und dann getcolumn(3,vector)" funktioniert nicht.
mit getcolumn2 komm ich immerhin zur alten viewposition(bevor ich mein element etwas gedreht habe) zurück.

mit der transformgroup der view kann ich mir leider auch nicht weiterhelfen.

vielleicht weiß ja jemand von euch bescheid, schön langsam werd ich wahnsinnig :autsch: 

lg


----------



## Illuvatar (27. Dez 2007)

```
Transform3D t3d = new Transform3D();
simpleUniverse.getViewingPlatform().getViewPlatformTransform().getTransform (t3d);
```


----------



## Guest (28. Dez 2007)

danke für die antwort.
ich werds nochmal so versuchen. ich habs schon so ähnlich probiert aber nicht genau so.


----------



## Guest (28. Dez 2007)

nein, das geht leider auch nicht. das transform3d bewegt sich gleichermaßen mit dem gedrehten objekt mit.
irgendwelche anderen lösungsansätze?


----------



## Illuvatar (28. Dez 2007)

Sorry, vielleicht versteh ich auch nicht so ganz, was du meinst 

Bewegt sich mit dem gedrehten Objekt mit? Also das Transform3D, das du (so wie ichs geschrieben hab) von der ViewingPlatform kriegst, ist immer die exakte Position (+Rotation) der "Kamera" zu dem Moment wo du die Methode aufrufst.


----------



## Guest (28. Dez 2007)

ok, ist glaub ich besser wenn ich den code reinkopiere 


```
import java.applet.*;
import java.awt.BorderLayout;

import javax.media.j3d.Alpha;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;

public class Homepage3D extends Applet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2707836382924126259L;

	private Canvas3D canvas3D;
	SimpleUniverse simpleU;

	/**
	 * Proof of concept for a java3d homepage.
	 */
	public Homepage3D() {
		setLayout(new BorderLayout());
		canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
		add("Center", canvas3D);

		// SimpleUniverse is a Convenience Utility class
		simpleU = new SimpleUniverse(canvas3D);

		// This moves the ViewPlatform back a bit so the
		// objects in the scene can be viewed.
		ViewingPlatform vp = simpleU.getViewingPlatform();
		TransformGroup steerTG = vp.getViewPlatformTransform();
		
		Transform3D t3d = new Transform3D();
		steerTG.getTransform(t3d);
		
		t3d.lookAt(new Point3d(0,0,2.4),new Point3d(0,0,0),new Vector3d(0,1,0));
		t3d.invert();
		
		steerTG.setTransform(t3d);
		
		BranchGroup scene = createSceneGraph();
		scene.setCapability(BranchGroup.ENABLE_PICK_REPORTING);

		// create Light

		AmbientLight al = new AmbientLight(new Color3f(128f, 10f, 70f));
		al.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
		DirectionalLight dl = new DirectionalLight(new Color3f(1f, 1f, 1f),
				new Vector3f(0.5f, 0.5f, -1f));
		dl.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
		scene.addChild(dl);
		scene.addChild(al);

		simpleU.addBranchGraph(scene);
	}

	public BranchGroup createSceneGraph() {
		// Create the root of the branch graph
		BranchGroup objRoot = new BranchGroup();

		// START MAIN ELEMENT

		TransformGroup objSpin = new TransformGroup();
		objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

		Appearance boxAppearance = new Appearance();
		boxAppearance.setMaterial(new Material(new Color3f(0.2f, 0.2f, 0.2f),
				new Color3f(0.2f, 0.2f, 0.2f), new Color3f(1.0f, 0.0f, 1.0f),
				new Color3f(0.3f, 0.3f, 0.3f), 1f));
		boxAppearance.setTexture(new TextureLoader("src/02.jpg", null)
				.getTexture());
		boxAppearance.setTextureAttributes(new TextureAttributes(
				TextureAttributes.COMBINE, new Transform3D(), new Color4f(),
				TextureAttributes.NICEST));

		Box box = new Box(0.4f, 0.4f, 0.4f, Primitive.GENERATE_NORMALS
				| Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

		objSpin.addChild(box);

		// /MOUSE ROTATOR FOR TRANSFORMGROUP

		MouseRotate myMouseRotate = new MouseRotate();

		myMouseRotate.setTransformGroup(objSpin);
		myMouseRotate.setSchedulingBounds(new BoundingSphere());
		objRoot.addChild(myMouseRotate);

		// /END MAIN ELEMENT

		// /1. child element

		Box box1 = new Box(0.1f, 0.1f, 0.1f, Primitive.GENERATE_NORMALS
				| Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

		TransformGroup transformGroup = new TransformGroup();
		Transform3D transform3D = new Transform3D();
		transform3D.setTranslation(new Vector3f(0f, 0f, box.getZdimension()
				+ box1.getZdimension()));
		transformGroup.setTransform(transform3D);
		transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
		transformGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

		boxAppearance = new Appearance();
		boxAppearance.setTexture(new TextureLoader("src/chris.jpg", null)
				.getTexture());
		boxAppearance.setTextureAttributes(new TextureAttributes(
				TextureAttributes.REPLACE, new Transform3D(), new Color4f(),
				TextureAttributes.NICEST));
		box1.setAppearance(boxAppearance);
		box1.setUserData("chris");
		transformGroup.addChild(box1);

		// end 1. child element

		// /2. child element

		Box box2 = new Box(0.1f, 0.1f, 0.1f, Primitive.GENERATE_NORMALS
				| Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

		TransformGroup transformGroup2 = new TransformGroup();
		Transform3D transform3D2 = new Transform3D();
		transform3D2.setTranslation(new Vector3f(0f, 0f,
				-(box.getZdimension() + box1.getZdimension())));
		transformGroup2.setTransform(transform3D2);

		Appearance boxAppearance2 = new Appearance();
		boxAppearance2.setTexture(new TextureLoader("src/maria.jpg", null)
				.getTexture());
		boxAppearance2.setTextureAttributes(new TextureAttributes(
				TextureAttributes.REPLACE, new Transform3D(), new Color4f(),
				TextureAttributes.NICEST));
		box2.setAppearance(boxAppearance2);
		transformGroup2.addChild(box2);

		// end 1. child element

		// add child elements to spinning transformgroup
		objSpin.addChild(transformGroup);
		objSpin.addChild(transformGroup2);

		Alpha aPos = new Alpha(1,
							Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
							0, 
							0,
							3000,
							1500,
							0, 
							3000,
							1500,
							0);
		aPos.setStartTime(0);
		
		// TRANSLATION
        float [] knots = new float[2];
        knots[0] = 0.0f;
        knots[1] = 1.0f;
        Point3f [] positions = new Point3f[2];
        
        Vector3f vec = new Vector3f();
        transform3D.get(vec);
        
        positions[0] = new Point3f(vec.getX(),vec.getY(),vec.getZ());
        positions[1] = new Point3f(vec.getX(),vec.getY(),vec.getZ());
        PositionPathInterpolator pi =
        new PositionPathInterpolator(aPos, transformGroup, transform3D, knots, positions);
		
        
        System.out.println();
        
		pi.setSchedulingBounds(new BoundingSphere(new Point3d(), 100000));
		transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		transformGroup.addChild(pi);

		// ADD PICKTRANSLATEBEHAVIOR

		AnimationPickMouseBehaviour pickBehavior = new AnimationPickMouseBehaviour(canvas3D, objRoot, new BoundingSphere(new Point3d(), 100000), pi, simpleU);
		
		
		objRoot.addChild(pickBehavior);

		objRoot.addChild(objSpin);

		return objRoot;
	}

	public static void main(String[] args) {
		new MainFrame(new Homepage3D(), 256, 256);
	}
}
```



```
import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.picking.PickCanvas;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class AnimationPickMouseBehaviour extends PickMouseBehavior{
   private PositionPathInterpolator pi;
   private SimpleUniverse simpleU;
   Canvas3D pCanvas;
   BranchGroup root;
   
   public AnimationPickMouseBehaviour(Canvas3D pCanvas,
		   							  BranchGroup root,
		   							  Bounds pBounds,
		   							  PositionPathInterpolator pi,
		   							  SimpleUniverse simpleU){
      super(pCanvas,root,pBounds);
      setSchedulingBounds(pBounds);
      this.pCanvas = pCanvas;
      this.root = root;
      this.simpleU = simpleU;
      this.pi = pi;
     }

     //Definition der Reaktion, wenn etwas ausgewaehlt wurde.
   public void updateScene(int xpos, int ypos){
	      Primitive pickedShape = null;
	      pickCanvas = new PickCanvas(pCanvas,root);
	      pickCanvas.setShapeLocation(xpos,ypos);
	      System.out.println(pickCanvas);
	      PickResult pResult = pickCanvas.pickClosest();
	      if (pResult != null){
	         pickedShape = (Primitive) pResult.getNode(PickResult.PRIMITIVE);
	      }
	      if (pickedShape != null && pickedShape.getUserData()==("chris")){
	    	  
	    	  //Point3d eyepos = pickCanvas.getStartPosition();
	    	  Transform3D t1 = new Transform3D();
	    	  simpleU.getViewingPlatform().getViewPlatformTransform().getTransform(t1);
	    	  
	    	  Vector3f vecEyepos = new Vector3f();
 	    	  
	    	  t1.get(vecEyepos);
	    	  
	    	  float [] knots = new float[2];
	          Point3f [] positions = new Point3f[2];
	         
	          knots[0] = 0.0f;
	          knots[1] = 1.0f;
	          
	          Transform3D t = pi.getTransformAxis();
	          Vector3f vec = new Vector3f();
	          t.get(vec);
	          
	          positions[0] = new Point3f(vec.getX(),vec.getY(), vec.getZ());
	          positions[1] = new Point3f(vecEyepos.x,vecEyepos.y,vecEyepos.z);
	          
	          pi.setPathArrays(knots, positions);
	    	  
	    	  new AlphaThread(pi.getAlpha());
	      }
   }
}
```


```
import javax.media.j3d.Alpha;


public class AlphaThread implements Runnable {

	Alpha alpha;
	boolean finished;
	
	public AlphaThread(Alpha alpha){
		this.alpha = alpha;
		this.alpha.resume();
		Thread thread = new Thread(this);
		thread.start();
	}

	@Override
	public void run() {
		finished = false;
		while (!alpha.finished()){}
		finished = true;
		alpha.setStartTime(System.currentTimeMillis());
		//alpha.pause();
	}
	
	public boolean finished(){
		return finished;
	}
	
}
```

hab hier mal die drei klassen reinkopiert die ich zur zeit verwende. kannst du sie bitte mal ausführen dann weißt du was ich mein. 
einer der beiden kleinen würfel ist, mit einem pickbehaviour versehen.
der würfel soll beim draufklicken auf mich zukommen.

lg
[/code]


----------



## Illuvatar (28. Dez 2007)

Also...

dein Problem war, dass dein MouseRotate ja überhaupt nicht die Kamera bewegt, sondern deine TransformGroup rotiert. Ich hab das MouseRotate also durch ein OrbitBehavior ersetzt, der die Kamera manipuliert.

Das andere Problem war ja, dass der Würfel "zu nah" rankommt. Ich hab beim View die frontClipPolicy auf VIRTUAL_EYE geändert, damit ich das im Behavior besser berechnen kann, und hab dann deinen vecEyepos Vektor ein bisschen verschoben, so dass der Würfel selbst im Extremfall die frontClipPlane nur mit der Spitze berühren kann.

Mir war noch aufgefallen, dass du für die ganzen Groups die ENABLE_PICK_REPORTING capability gesetzt hast, die benötigst du aber nicht. Das musst du nur anmachen, wenn du für die Group noch ein _Extra_ - Pickergebnis haben willst. (Falls du das willst, kannst du das ja wieder reinmachen  )

Die Dateinamen stimmen nicht mehr, die hab ich zum Testen auf ein paar Testtexturen umgewandelt, die grade rumlagen.


```
import java.applet.*;
import java.awt.BorderLayout;

import javax.media.j3d.Alpha;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.View;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3d;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;

public class Homepage3D extends Applet {
   /**
    *
    */
   private static final long serialVersionUID = -2707836382924126259L;

   private Canvas3D canvas3D;
   SimpleUniverse simpleU;

   /**
    * Proof of concept for a java3d homepage.
    */
   public Homepage3D() {
      setLayout(new BorderLayout());
      canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
      add("Center", canvas3D);

      // SimpleUniverse is a Convenience Utility class
      simpleU = new SimpleUniverse(canvas3D);
      
      canvas3D.getView().setFrontClipPolicy (View.VIRTUAL_EYE);

      // This moves the ViewPlatform back a bit so the
      // objects in the scene can be viewed.
      ViewingPlatform vp = simpleU.getViewingPlatform();
      TransformGroup steerTG = vp.getViewPlatformTransform();

      Transform3D t3d = new Transform3D();
      steerTG.getTransform(t3d);

      t3d.lookAt(new Point3d(0,0,2.4),new Point3d(0,0,0),new Vector3d(0,1,0));
      t3d.invert();

      steerTG.setTransform(t3d);

      BranchGroup scene = createSceneGraph();

      // create Light

      AmbientLight al = new AmbientLight(new Color3f(128f, 10f, 70f));
      al.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
      DirectionalLight dl = new DirectionalLight(new Color3f(1f, 1f, 1f),
            new Vector3f(0.5f, 0.5f, -1f));
      dl.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
      scene.addChild(dl);
      scene.addChild(al);
      
      OrbitBehavior orbit = new OrbitBehavior(canvas3D, OrbitBehavior.DISABLE_TRANSLATE | OrbitBehavior.DISABLE_ZOOM);
      orbit.setSchedulingBounds (new BoundingSphere ());
      simpleU.getViewingPlatform().setViewPlatformBehavior (orbit);
      
      scene.compile();

      simpleU.addBranchGraph(scene);
   }

   public BranchGroup createSceneGraph() {
      // Create the root of the branch graph
      BranchGroup objRoot = new BranchGroup();

      // START MAIN ELEMENT

      TransformGroup objSpin = new TransformGroup();
      objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
      objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

      Appearance boxAppearance = new Appearance();
      boxAppearance.setMaterial(new Material(new Color3f(0.2f, 0.2f, 0.2f),
            new Color3f(0.2f, 0.2f, 0.2f), new Color3f(1.0f, 0.0f, 1.0f),
            new Color3f(0.3f, 0.3f, 0.3f), 1f));
      boxAppearance.setTexture(new TextureLoader("src/back.png", null)
            .getTexture());
      boxAppearance.setTextureAttributes(new TextureAttributes(
            TextureAttributes.COMBINE, new Transform3D(), new Color4f(),
            TextureAttributes.NICEST));

      Box box = new Box(0.4f, 0.4f, 0.4f, Primitive.GENERATE_NORMALS
            | Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

      objSpin.addChild(box);

      // /MOUSE ROTATOR FOR TRANSFORMGROUP

      /*MouseRotate myMouseRotate = new MouseRotate();

      myMouseRotate.setTransformGroup(objSpin);
      myMouseRotate.setSchedulingBounds(new BoundingSphere());
      objRoot.addChild(myMouseRotate);*/

      // /END MAIN ELEMENT

      // /1. child element

      Box box1 = new Box(0.1f, 0.1f, 0.1f, Primitive.GENERATE_NORMALS
            | Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

      TransformGroup transformGroup = new TransformGroup();
      Transform3D transform3D = new Transform3D();
      transform3D.setTranslation(new Vector3f(0f, 0f, box.getZdimension()
            + box1.getZdimension()));
      transformGroup.setTransform(transform3D);
      transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
      transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

      boxAppearance = new Appearance();
      boxAppearance.setTexture(new TextureLoader("src/browser.png", null)
            .getTexture());
      boxAppearance.setTextureAttributes(new TextureAttributes(
            TextureAttributes.REPLACE, new Transform3D(), new Color4f(),
            TextureAttributes.NICEST));
      box1.setAppearance(boxAppearance);
      box1.setUserData("chris");
      transformGroup.addChild(box1);

      // end 1. child element

      // /2. child element

      Box box2 = new Box(0.1f, 0.1f, 0.1f, Primitive.GENERATE_NORMALS
            | Primitive.GENERATE_TEXTURE_COORDS, boxAppearance);

      TransformGroup transformGroup2 = new TransformGroup();
      Transform3D transform3D2 = new Transform3D();
      transform3D2.setTranslation(new Vector3f(0f, 0f,
            -(box.getZdimension() + box1.getZdimension())));
      transformGroup2.setTransform(transform3D2);

      Appearance boxAppearance2 = new Appearance();
      boxAppearance2.setTexture(new TextureLoader("src/clock.png", null)
            .getTexture());
      boxAppearance2.setTextureAttributes(new TextureAttributes(
            TextureAttributes.REPLACE, new Transform3D(), new Color4f(),
            TextureAttributes.NICEST));
      box2.setAppearance(boxAppearance2);
      transformGroup2.addChild(box2);

      // end 1. child element

      // add child elements to spinning transformgroup
      objSpin.addChild(transformGroup);
      objSpin.addChild(transformGroup2);

      Alpha aPos = new Alpha(1,
                     Alpha.INCREASING_ENABLE + Alpha.DECREASING_ENABLE,
                     0,
                     0,
                     3000,
                     1500,
                     0,
                     3000,
                     1500,
                     0);
      aPos.setStartTime(0);

      // TRANSLATION
        float [] knots = new float[2];
        knots[0] = 0.0f;
        knots[1] = 1.0f;
        Point3f [] positions = new Point3f[2];

        Vector3f vec = new Vector3f();
        transform3D.get(vec);

        positions[0] = new Point3f(vec.getX(),vec.getY(),vec.getZ());
        positions[1] = new Point3f(vec.getX(),vec.getY(),vec.getZ());
        PositionPathInterpolator pi =
        new PositionPathInterpolator(aPos, transformGroup, transform3D, knots, positions);


        System.out.println();

      pi.setSchedulingBounds(new BoundingSphere(new Point3d(), 100000));
      pi.setCapability (javax.media.j3d.Node.ALLOW_LOCAL_TO_VWORLD_READ);
      transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
      transformGroup.addChild(pi);

      // ADD PICKTRANSLATEBEHAVIOR

      AnimationPickMouseBehaviour pickBehavior = new AnimationPickMouseBehaviour
            (canvas3D, objRoot, new BoundingSphere(new Point3d(), 100000), pi, simpleU);


      objRoot.addChild(pickBehavior);

      objRoot.addChild(objSpin);

      return objRoot;
   }

   public static void main(String[] args) {
      new MainFrame(new Homepage3D(), 256, 256);
   }
}
```


```
import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.PositionPathInterpolator;
import javax.media.j3d.Transform3D;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;

import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.picking.PickCanvas;
import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class AnimationPickMouseBehaviour extends PickMouseBehavior{
   private PositionPathInterpolator pi;
   private SimpleUniverse simpleU;
   Canvas3D pCanvas;
   BranchGroup root;

   public AnimationPickMouseBehaviour(Canvas3D pCanvas,
                                BranchGroup root,
                                Bounds pBounds,
                                PositionPathInterpolator pi,
                                SimpleUniverse simpleU){
      super(pCanvas,root,pBounds);
      setSchedulingBounds(pBounds);
      this.pCanvas = pCanvas;
      this.root = root;
      this.simpleU = simpleU;
      this.pi = pi;
     }

     //Definition der Reaktion, wenn etwas ausgewaehlt wurde.
   public void updateScene(int xpos, int ypos){
         Primitive pickedShape = null;
         pickCanvas = new PickCanvas(pCanvas,root);
         pickCanvas.setShapeLocation(xpos,ypos);
         System.out.println(pickCanvas);
         PickResult pResult = pickCanvas.pickClosest();
         if (pResult != null){
            pickedShape = (Primitive) pResult.getNode(PickResult.PRIMITIVE);
         }
         if (pickedShape != null && pickedShape.getUserData()==("chris")){

            //Point3d eyepos = pickCanvas.getStartPosition();
            Transform3D t1 = new Transform3D();
            simpleU.getViewingPlatform().getViewPlatformTransform().getTransform(t1);

            Vector3f vecEyepos = new Vector3f();
            t1.get(vecEyepos);

            float [] knots = new float[2];
             Point3f [] positions = new Point3f[2];

             knots[0] = 0.0f;
             knots[1] = 1.0f;

             Transform3D t = pi.getTransformAxis();
             Vector3f vec = new Vector3f();
             t.get(vec);
             
             // we need to change the eyeposition so that the box won't fly "into" the cam
             // new pos: eyepos + (vec - eyepos) / |(vec - eyepos)| * (length of box diagonal + near clipping plane)
             // since it is a cube, the diagonal length = sqrt (3*zdimension²)
             
             Vector3f normal = new Vector3f (vec);
             normal.sub (vecEyepos);
             normal.normalize();
             double boxDim = Math.sqrt(3 * Math.pow(((Box)pickedShape).getZdimension(), 2));
             normal.scale ((float) (boxDim + pCanvas.getView().getFrontClipDistance()));
             vecEyepos.add (normal);

             positions[0] = new Point3f(vec.getX(),vec.getY(), vec.getZ());
             positions[1] = new Point3f(vecEyepos.x,vecEyepos.y,vecEyepos.z);

             pi.setPathArrays(knots, positions);

            new AlphaThread(pi.getAlpha());
         }
   }
}
```

Die dritte Klasse hat sich nicht geändert.


----------



## Guest (28. Dez 2007)

danke, ich werde es morgen testen. sitze gerade nicht mehr am homepc.
wenn es das ist was ich suche, werde ich mich morgen anmelden, und mit dir zwecks der bezahlung in verbindung setzen.

lg

chris


----------



## optimusprime1982 (29. Dez 2007)

hi! ich bins wieder 

funktioniert fast so wie ich mir das vorstelle :applaus:  , 2 kleinigkeiten noch:

-die drehrichtung ist jetzt klarerweise umgekehrt, gibt es irgendetwas mit dem ich das inverten kann? edit: hab ich schon gefunden!!!
- wenn ich "das element drehe" (klarerweise jetzt die cam), ist auf der rückseite schatten. kann man das wirklich nicht mit dem mouserotate machen(ich glaub dir schon, ich frag nur mal nach  )?. muss ich jetzt das licht auch mitdrehen?
wie koppel ich das am besten mit der kamera?

lg
chris

you've got PM


----------



## Illuvatar (29. Dez 2007)

Man hätte es auch mit dem MouseRotate machen können, aber es wäre ungeschickter gewesen 

Es gibt schon einen vorgefertigten Behavior der Sachen mit der Kamera mitdrehen kann namens Billboard, ich hab beim Licht noch so einen eingebaut.


```
// create Light

            AmbientLight al = new AmbientLight(new Color3f(128f, 10f, 70f));
      al.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
      DirectionalLight dl = new DirectionalLight(new Color3f(1f, 1f, 1f),
            new Vector3f(0.5f, 0.5f, -1f));
      dl.setInfluencingBounds(new BoundingSphere(new Point3d(), 100000));
      scene.addChild(al);
      
      TransformGroup billboardTG = new TransformGroup ();
      billboardTG.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE);
      billboardTG.addChild(dl);
      scene.addChild(billboardTG);
      Billboard billboard = new Billboard (billboardTG, Billboard.ROTATE_ABOUT_POINT, new Point3f());
      billboard.setSchedulingBounds (new BoundingSphere());
      scene.addChild (billboard);
```


----------

