Hi ian,
You want the colorcube to follow the mouse cursor with high-fidelity,
am I right ? Below is a modified version of your original code.
Just check out if this is what you wanted...
HTH,
Vaidya
==========================Modified code ===================================
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Example3 extends Applet {
Canvas3D canvas3D;
Transform3D pos;
TransformGroup tg;
ColorCube mark = new ColorCube(0.05);
public Example3() {
setLayout(new BorderLayout());
canvas3D = new Canvas3D(null);
add("Center", canvas3D);
final BranchGroup scene = new BranchGroup();
pos = new Transform3D();
tg = new TransformGroup(pos);
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
tg.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
scene.addChild(mark);
scene.addChild(tg);
final ColorCube cc = new ColorCube(0.05);
cc.setCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ);
tg.addChild(cc);
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
final Point3d campnt = new Point3d();
MouseMotionAdapter ma = new MouseMotionAdapter() {
Transform3D pos = new Transform3D();
Transform3D ip2vw = new Transform3D();
Transform3D vw2lc = new Transform3D();
Transform3D lc2vw = new Transform3D();
Transform3D ip2lc = new Transform3D();
Transform3D t3d = new Transform3D();
Point3d point = new Point3d();
Vector3d vec = new Vector3d();
public void mouseMoved(MouseEvent e) {
// canvas3D.getCenterEyeInImagePlate(campnt);
// canvas3D.getPixelLocationInImagePlate(e.getX(),e.getY(),point);
// vec.sub(point,campnt);
// vec.normalize();
// pos.setTranslation(vec);
// tg.setTransform(pos);
canvas3D.getPixelLocationInImagePlate(e.getX(),e.getY(),point);
canvas3D.getImagePlateToVworld(ip2vw);
// ip2vw.invert();
tg.getLocalToVworld(lc2vw);
vw2lc.invert(lc2vw);
ip2lc.mul(ip2vw,vw2lc);
ip2lc.transform(point);
vec.sub(point,new Point3d());
pos.setTranslation(vec);
tg.setTransform(pos);
System.out.println("Point Loc: "+point.toString());
campnt.set(point);
}
};
canvas3D.addMouseMotionListener(ma);
}
public static void main(String[] args) {
Frame frame = new MainFrame(new Example3(), 256, 256);
}
}
========================================================================
>On Fri, 15 Feb 2002 13:58:58 +0800, � - - �n +���ng� - - �
><[EMAIL PROTECTED]> wrote:
>sorry abt that. what i was aiming to do is to create a shape,
>say a sphere on the space where the mouse was clicked. the
>z-coor will be fixed so the only problem is to get the
>corresponding x,y coor of the point on the vworld where i
>clicked the mouse. the Example3.java shows me where the points
>of the vworld are on a specific area of the canvas.
>this point is represented by the moving colorcube when you
>move your mouse within the window. the fix colorcube is just
>a marker to the center. as you would see, that was not what i
>wanted.
>
>my first solution is to move the z-coor close enough to the screen
>so that it would seem that the point where the mouse is matches
>with the coordinates on the vworld. but this solution doesnt
>increase the range of the x,y coor (�0.37, �0.37). i could scale
>it but it might not be a good solution all together.
>
>so, any ideas?
>
>thanks again in advance.
>
>- ian
>
>__________________________________
>www.edsamail.com
==========================================================================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".