hm, lang her dass ich mit java3d zu tun hatte.. hab da auf die schnelle diese klasse gefunden.. vielleicht hilfts dir irgendwie
/*
* project: tnc - ciiema3d
* file : NodusPickBehavior.java
* author : Johann Grabner (JG), Markus Toman (MT)
* version:
* history: 2002-04-22: MT: stimulus
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.Sphere;
import ciiema3d.universe.*;
import ciiema3d.data.*;
public class NodusPickBehavior extends Behavior {
WakeupCriterion[] mouseEvents;
WakeupOr mouseCriterion;
int x, y;
int x_last, y_last;
Canvas3D graphCanvas;
BranchGroup scene;
PickRay pickRay = new PickRay();
SceneGraphPath sceneGraphPath[];
boolean enabled = true;
public NodusPickBehavior( Canvas3D graphCanvas, BranchGroup scene ) {
this.graphCanvas = graphCanvas;
this.scene = scene;
}
public Point getMouseLocation() {
return new Point( x, y );
}
/** wake up on mouse press
*/
public void initialize() {
x = 0;
y = 0;
x_last = 0;
y_last = 0;
mouseEvents = new WakeupCriterion[1];
mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
mouseCriterion = new WakeupOr(mouseEvents);
wakeupOn (mouseCriterion);
}
public void setEnabled( boolean enabled ) {
this.enabled = enabled;
}
public boolean getEnabled() {
return enabled;
}
private void handleMousePress( MouseEvent event ) {
x = x_last = event.getX();
y = y_last = event.getY();
Point3d eyePos = new Point3d();
graphCanvas.getCenterEyeInImagePlate( eyePos );
Point3d mousePos = new Point3d();
graphCanvas.getPixelLocationInImagePlate( x, y, mousePos );
Transform3D transform3D = new Transform3D();
graphCanvas.getImagePlateToVworld( transform3D );
transform3D.transform( eyePos );
transform3D.transform( mousePos );
Vector3d mouseVec;
mouseVec = new Vector3d();
mouseVec.sub( mousePos, eyePos );
mouseVec.scale( 10f );
pickRay.set( eyePos, mouseVec );
sceneGraphPath = scene.pickAllSorted( pickRay );
if( sceneGraphPath != null ) {
for( int j = 0; j < sceneGraphPath.length; ++j ) {
if( sceneGraphPath[ j ] != null ) {
Node node = sceneGraphPath[ j ].getObject();
try {
GraphNode graphElement = (GraphNode) node.getUserData();
if ( graphElement != null ) {
if( graphElement.successor.size( ) > 0 ) {
Data.current = graphElement;
NodusWorld.rebuildScene( );
}
}
}
catch (CapabilityNotSetException e) {
}
}
}
}
}
/** This method is invoked when the stimulus (ie, a mouse press) occurs
* @param criteria Wake up criteria
*/
public void processStimulus(Enumeration criteria) {
WakeupCriterion wakeup;
AWTEvent[] event;
int id;
while( criteria.hasMoreElements() ) {
wakeup = (WakeupCriterion) criteria.nextElement();
if( wakeup instanceof WakeupOnAWTEvent ) {
event = ( ( WakeupOnAWTEvent ) wakeup ).getAWTEvent();
for( int i=0; i < event.length; ++i ) {
id = event[i].getID( );
if( enabled && id == MouseEvent.MOUSE_PRESSED ) {
handleMousePress( ( MouseEvent ) event[i] );
}
}
}
}
wakeupOn (mouseCriterion);
}
}