Hi, I appreciate the help, I suspect the problem does lie in the picking area (i.e getNode) but not sure what the solution is.
Perhaps I should explain the context; I am moving a shape within a room, I don't wish to move the camera, just the shape... The code has the effect I want, it just doesn't seem to stick from pick to pick! Thanks again >-----Original Message----- >From: Brian McCormick [mailto:[EMAIL PROTECTED] >Sent: 11 December 2003 15:35 >To: [EMAIL PROTECTED] >Subject: Re: [JAVA3D] real problems with a translate behavior > >Hello, > >I looked over your code and it looks like the problem is the >getNode() function is always returning the same thing. I've >never used this function so I can't really say much more than >that about it. > >I must say, however, that if you want to move your camera each >time from its current position, you should probably not be >setting the initial camera position by picking. I'm no expert, >but here is what I suggest you do. > >First, get the current location of your camera. Next, >determine the local coordinate movement wrt the camera that >you want to perform. >After this, use the convertLocalToVWorld() function to convert >the local camera movement into a global coordinate movement. >Finally, add the global coordinate movement to the current >camera location and you are done. > >Hope this helps. > >best, >Brian McCormick > >-----Original Message----- >From: Discussion list for Java 3D API >[mailto:[EMAIL PROTECTED] On Behalf Of Ben Logan >Sent: Thursday, December 11, 2003 6:22 AM >To: [EMAIL PROTECTED] >Subject: [JAVA3D] real problems with a translate behavior > >import java.util.*; >import javax.media.j3d.*; >import javax.vecmath.*; > >import java.awt.*; >import java.awt.event.*; > >import com.sun.j3d.utils.geometry.*; > >import com.sun.j3d.utils.picking.*; >import com.sun.j3d.utils.picking.behaviors.*; > >Can someone please help with this? I have a translate behavior >that successfully moves a shape through a scene while the user >drags the mouse with the right mouse button, it works fine >until you try and do it a second time, at which point the >shape returns to its original position and translates from >there. I am calling setTransform where I think I should be, >I'm totally stuck, would really appreciate any help. > >Here is some sample output from the program: > >mouse pressed : MODEL TRANS: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, >0.0 0.0, 0.0, 1.0, 2.5 0.0, 0.0, 0.0, 1.0 mouse dragged : >MODEL TRANS: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, 0.0 0.0, 0.0, >1.0, 2.5 0.0, 0.0, 0.0, 1.0 CALLING UPDATE SCENE CURRENT SHAPE >TRANSFORM: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, 0.0 0.0, 0.0, >1.0, 2.5 0.0, 0.0, 0.0, 1.0 CURRENT SHAPE TRANSFORM: 1.0, 0.0, >0.0, 2.508 0.0, 1.0, 0.0, 0.0 0.0, 0.0, 1.0, 2.5 0.0, 0.0, >0.0, 1.0 CURRENT SHAPE TRANSFORM: 1.0, 0.0, 0.0, 2.516 0.0, >1.0, 0.0, 0.0 0.0, 0.0, 1.0, 2.5 0.0, 0.0, 0.0, 1.0 CURRENT >SHAPE TRANSFORM: 1.0, 0.0, 0.0, 2.524 0.0, 1.0, 0.0, 0.0 0.0, >0.0, 1.0, 2.5 0.0, 0.0, 0.0, 1.0 mouse dragged : MODEL TRANS: >1.0, 0.0, 0.0, 2.532 0.0, 1.0, 0.0, 0.0 0.0, 0.0, 1.0, 2.5 >0.0, 0.0, 0.0, 1.0 CALLING UPDATE SCENE CURRENT SHAPE >TRANSFORM: 1.0, 0.0, 0.0, 2.532 0.0, 1.0, 0.0, 0.0 0.0, 0.0, >1.0, 2.5 0.0, 0.0, 0.0, 1.0 > >Etc etc etc :) > >Then, the second time you try and do it: > >mouse pressed : MODEL TRANS: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, >0.0 0.0, 0.0, 1.0, 2.5 0.0, 0.0, 0.0, 1.0 mouse dragged : >MODEL TRANS: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, 0.0 0.0, 0.0, >1.0, 2.5 0.0, 0.0, 0.0, 1.0 CALLING UPDATE SCENE CURRENT SHAPE >TRANSFORM: 1.0, 0.0, 0.0, 2.5 0.0, 1.0, 0.0, 0.0 0.0, 0.0, >1.0, 2.5 0.0, 0.0, 0.0, 1.0 CURRENT SHAPE TRANSFORM: 1.0, 0.0, >0.0, 2.508 0.0, 1.0, 0.0, 0.0 0.0, 0.0, 1.0, 2.5 0.0, 0.0, 0.0, 1.0 > >It starts again from the shapes original starting position. > >I would really appreciate some help, thanks in advance, Ben > > > >public class MyPickTranslateBehavior > extends PickTranslateBehavior > implements Constants { > protected WakeupCondition m_WakeupCondition = null; > > private int x = 0; > private int y = 0; > private int x_last = 0; > private int y_last = 0; > > private double y_angle = 0.0; > private double x_factor = 0.02; > > int changeX; > int changeY; > > Appearance appear; > ColoringAttributes ca; > > private Transform3D modelTrans = null; > private Transform3D transformY = null; > private PickResult pickResult = null; > private Node pickNode = null; > private TransformGroup transformGroup = null; > > Canvas3D canvas; > BranchGroup objRoot; > Java3DFrame frame; > > BranchGroup guideShape; > > double step = 0.008; > > public MyPickTranslateBehavior(Java3DFrame f, BranchGroup objRoot, > Canvas3D canvas, > BoundingSphere bounds) { > > super(objRoot, canvas, bounds); > this.frame = f; > this.setBounds(bounds); > this.canvas = canvas; > this.objRoot = objRoot; > > modelTrans = new Transform3D(); > transformY = new Transform3D(); > > transformGroup = new TransformGroup(); > transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); > transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); > > transformGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE); > > //create the wakeupCriterion for the behavior > WakeupCriterion criterionArray[] = new WakeupCriterion[2]; > criterionArray[0] = new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED); > criterionArray[1] = new WakeupOnAWTEvent(MouseEvent.MOUSE_DRAGGED); > > //save the WakeupCriterion for the behavior > m_WakeupCondition = new WakeupOr(criterionArray); > } > > public void initialize() { // initialize > wakeupOn(m_WakeupCondition); //Apply the initial WakeupCriterion > } > > public void processStimulus(Enumeration criteria) { // >processStimulus > > while (criteria.hasMoreElements()) { > WakeupCriterion wakeUp = (WakeupCriterion) >criteria.nextElement(); > > if (wakeUp instanceof WakeupOnAWTEvent) { > AWTEvent[] evt = ( (WakeupOnAWTEvent) wakeUp).getAWTEvent(); > try { > processAWTEvent(evt); > } > catch (Exception e) { > > } > } > } > //Assign the next WakeupCondition, so we are notified again > wakeupOn(m_WakeupCondition); > } > > private void processAWTEvent(AWTEvent[] events) { > > for (int n = 0; n < events.length; n++) { > > if (events[n] instanceof MouseEvent) { > > MouseEvent eventPress = (MouseEvent) events[n]; > > if (eventPress.getModifiers() == MouseEvent.BUTTON3_MASK) { > //System.out.println("RIGHT MOUSE PRESSED _ DOING >TRANSLATION"); > > if (eventPress.getID() == MouseEvent.MOUSE_PRESSED) { > pickCanvas.setShapeLocation(eventPress); > pickResult = pickCanvas.pickClosest(); > > if (pickResult != null) { > pickNode = pickResult.getObject(); > transformGroup = (TransformGroup) pickResult.getNode( > PickResult. > TRANSFORM_GROUP); > > transformGroup.getTransform(modelTrans); > > System.out.println("mouse pressed : MODEL TRANS: " + > modelTrans.toString()); > > > x = x_last = eventPress.getX(); > y = y_last = eventPress.getY(); > > > } > } > > if ( (eventPress.getID() == MouseEvent.MOUSE_DRAGGED)) { > > System.out.println("mouse dragged : MODEL TRANS: " + > modelTrans.toString()); > > transformGroup.setTransform(modelTrans); > > //transformGroup.getTransform(modelTrans); > > //System.out.println("mouse dragged 2 : MODEL >TRANS: " + modelTrans.toString()); > > // Translating the object on both the X and Y axis > x = eventPress.getX(); > y = eventPress.getY(); > > changeX = x - x_last; > changeY = y - y_last; > > updateScene(); > > x_last = x; > y_last = y; > > > } > > } > } > } > } > > public void updateScene() { > > System.out.println("CALLING UPDATE SCENE"); > > int loopCount = changeX; > > if (changeX < 0) { > loopCount = changeX * -1; //make pos > } > > loopCount = loopCount * 4; > > boolean rightCollision = false; > boolean leftCollision = false; > > int stepCountRight = 0; > int stepCountLeft = 0; > > for (int i = 0; i < loopCount; i++) { > > //transformGroup.getTransform(modelTrans); > > System.out.println("CURRENT SHAPE TRANSFORM: " + >modelTrans.toString()); > > Vector3d temp = new Vector3d(); > modelTrans.get(temp); > > Vector3d temp2 = new Vector3d(); > > if (frame.inCollision() && (leftCollision == false) && >(rightCollision == false)) { > if (changeX < 0) { > > temp2 = new Vector3d(step, 0.0, 0.0); > > > leftCollision = true; > } > else { > > temp2 = new Vector3d( -step, 0.0, 0.0); > > rightCollision = true; > } > } > > else { > > if (changeX > 0) { > if ( (rightCollision == true) && (stepCountRight == 0)) { > > temp2 = new Vector3d( -step, 0.0, 0.0); > > stepCountRight--; > } > > else { > > > temp2 = new Vector3d(step, 0.0, 0.0); > > > } > if (rightCollision && (stepCountRight != 0)) { > stepCountRight++; > } > } > > else { > if ( (leftCollision == true) && (stepCountLeft == 0)) { > > > temp2 = new Vector3d(step, 0.0, 0.0); > > stepCountLeft--; > } > else { > > temp2 = new Vector3d( -step, 0.0, 0.0); > > } > if (leftCollision && (stepCountLeft != 0)) { > stepCountLeft++; > } > } > > } > > > Transform3D t2 = new Transform3D(); > t2.setTranslation(temp2); > > modelTrans.mul(modelTrans, t2); > > transformGroup.setTransform(modelTrans); > } > > } >} > > > > > > > > > > >******************************************** >Ben Logan - Graduate Software Engineer >RCID >Stephenson Building >Newcastle Upon Tyne >NE1 7RU >www.rcid.ncl.ac.uk >******************************************** > >=============================================================== >========= >=== >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". > > =========================================================================== 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".