1. I'm pretty sure I have seen the answer posted here by someone else. Use pickCanvas.pickAll() instead of pickClosest().
2. Are you rotating the scene or the view platform ? In the second case it's obvious what's happening. If you move the mouse from left to right, you compute an "x" increase and you try to add it to your point. BUT, if you are looking from behind the scene because of a view platform rotation, adding "x" to the point position will move it in the correct x axis of the scene, which in that case is displayed in the other direction. Cheers, Florin P.S. Don't post big code here, because nobody will look at it, except if it is a bug report. Sometimes simply giving a good description of the problem is better then posting too many lines of code. -----Urspr�ngliche Nachricht----- Von: Jiafeng Qin [mailto:[EMAIL PROTECTED]] Gesendet: Mittwoch, 29. Januar 2003 17:16 An: [EMAIL PROTECTED] Betreff: Re: [JAVA3D] AW: [JAVA3D] Draw Bezier curve in Java3D Hi Florin: Thank you for your reply! For the first problem, your code worked perfectly, everything seems all right now. For the second one, I tried to modify my code under your suggestion, it worked too. I can move the control points and the curve changed correspondingly. But, it still has some problems. 1. Sometimes the points can't be picked.I mean some can be picked, some others can not. 2. After I rotated the scene, sometimes I found the point I picked moved to the opposite direction of my mouse movement. I'm not sure the reasons for these problems. I post my whole codes below, I will appreciate if you or someone else can read it and give me some advice. The following codes is the behavior class, I think the preblems must exist in it. If you want to see my current result, I will be glad to post the remaining part of my program. Thanks a lot. NEAL import java.awt.*; import java.awt.event.*; import java.util.*; import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.picking.*; public class UpdateBehavior1 extends Behavior { WakeupCriterion[] mouseEvents; WakeupOr mouseCriterion; int x, y, last_x, last_y; double x_factor = .006; double y_factor = .006; Canvas3D canvas3D; BranchGroup branchGroup; TransformGroup pointsTG; BezierCurve3D curve; BezierControlPoint[] points; TransformGroup[] pTG; PickCanvas pickCanvas; TransformGroup tg; Point3d mousePos; UpdateBehavior1(Canvas3D canvas3D, BranchGroup branchGroup, TransformGroup pointsTG, BezierCurve3D curve, BezierControlPoint[] points, TransformGroup[] pTG) { this.canvas3D = canvas3D; this.branchGroup = branchGroup; this.pointsTG = pointsTG; this.curve = curve; this.points = points; this.pTG = pTG; pickCanvas = new PickCanvas(canvas3D, branchGroup); pickCanvas.setTolerance(8.0f); tg = new TransformGroup(); mousePos = new Point3d(); } public void initialize() { x = 0; y = 0; last_x = 0; last_y = 0; mouseEvents = new WakeupCriterion[2]; mouseEvents[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED); mouseEvents[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED); mouseCriterion = new WakeupOr(mouseEvents); wakeupOn (mouseCriterion); } public void processStimulus (Enumeration criteria) { WakeupCriterion wakeup; AWTEvent[] event; int id; int dx, dy; 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 (id == MouseEvent.MOUSE_PRESSED && !((MouseEvent)event[i]).isAltDown() && ((MouseEvent)event[i]).isMetaDown()) { x = ((MouseEvent)event[i]).getX(); y = ((MouseEvent)event[i]).getY(); pickCanvas.setShapeLocation(x, y); PickResult pr = pickCanvas.pickClosest(); if ((pr != null) && ((tg = (TransformGroup)pr.getNode(PickResult.TRANSFORM_GROUP)) != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))){ last_x = x; last_y = y; } } if (id == MouseEvent.MOUSE_DRAGGED && !((MouseEvent)event[i]).isAltDown() && ((MouseEvent)event[i]).isMetaDown()) { x = ((MouseEvent)event[i]).getX(); y = ((MouseEvent)event[i]).getY(); dx = x - last_x; dy = y - last_y; if (((Math.abs(dy) < 100) && (Math.abs(dx) < 100))) { Point3d mousePos = new Point3d(); canvas3D.getPixelLocationInImagePlate(x, y, mousePos); Vector3d moveVec = new Vector3d(); moveVec.x = dx * x_factor; moveVec.y = -dy * y_factor; pickCanvas.setShapeLocation(x, y); PickResult pr = pickCanvas.pickClosest(); if ((pr != null) && ((tg = (TransformGroup)pr.getNode(PickResult.TRANSFORM_GROUP)) != null) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_READ)) && (tg.getCapability(TransformGroup.ALLOW_TRANSFORM_WRITE))){ Transform3D t3d = new Transform3D(); tg.getTransform(t3d); Transform3D current = new Transform3D(); current.setTranslation(moveVec); current.mul(t3d, current); tg.setTransform(current); for (int j=0; j<4; j++) points[j].updatePosition(pTG[j]); curve.updateGeometry(points); last_x = x; last_y = y; } } } } } } wakeupOn (mouseCriterion); } } =========================================================================== 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". ==========================================================================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".
