hi,
I am sorry if I miss the point, but I use the
following transform3d multiplication to get the
compound tranformation:
cpTransform = translate * refptInv * scale * rotation
* refPT
where
* refptInv is the inverse translation of refPT;
* refPT is the tuple3f coordinates of center of
rotation - take it as a translation transform;
* translate, scale, rotation are the transformations
to be applied on the object.
Alessandro
--- Jean-Robert D'Amore <[EMAIL PROTECTED]>
escreveu: > Try by inverting the matrix
multiplication.
> Let say you've got the matric M for the scene, and T
> for the transform.
> If you do M=M*T then the transform will be in local
> coordinatyes. If you
> do M=T*M then you have the transform in global
> coordinates...
> JR
>
> Ben Logan wrote:
>
> >Could someone take a quick look at the following
> class. The problem is
> >that when a rotation is performed and then a
> translation the translation
> >takes place on the local coordinates. i.e it moves
> the shape in the
> >direction of the rotation. I want the shape to be
> moved in the same
> >direction whatever the rotation. Any help would be
> much appreciated.
> >Thanks
> >Ben
> >
> >
> >public class MyPickTranslateBehavior extends
> PickTranslateBehavior {
> > 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;
> >
> > 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;
> >
> > float step = 0.005f; // was 0.01
> >
> > 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;
> >
> > transformGroup = new TransformGroup();
> > modelTrans = new Transform3D();
> > transformY = new Transform3D();
> >
>
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
> >
>
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_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.BUTTON1_MASK) {
> > //System.out.println("LEFT MOUSE PRESSED
> _ DOING ROTATION");
> >
> > 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);
> >
> > //System.out.println("DELETE MODE? "
> +
> >frame.deleteMode());
> >
> > if (frame.deleteMode() == true) { //
> So delete that shape
> >
> > try {
> > //no capability to detact the
> branchgroup
> >
> transformGroup.removeAllChildren(); // Not yet
> working
> >
> > }
> > catch (Exception ex) {
> > System.out.println("DELETE
> EXCEPTION : " +
> >ex.toString());
> > }
> >
> > }
> >
> > else { // Setup rotation of that
> shape
> >
> >
> transformGroup.getTransform(modelTrans);
> >
> > x = x_last = eventPress.getX();
> > }
> > }
> > }
> >
> > if (eventPress.getID() ==
> MouseEvent.MOUSE_DRAGGED) {
> > // Rotating the object around the Y
> axis only
> > x = eventPress.getX();
> >
> > y_angle = (x - x_last) * x_factor;
> >
> > transformY.rotY(y_angle);
> >
> > modelTrans.mul(modelTrans, transformY);
> >
> >
> transformGroup.setTransform(modelTrans);
> >
> > x_last = x;
> > }
> > }
> >
> >
> > if (eventPress.getModifiers() ==
> MouseEvent.BUTTON3_MASK) {
> > //System.out.println("RIGHT MOUSE PRESSED
> _ DOING
> >TRANSLATION");
> >
>
=== message truncated ===
Yahoo! Mail - 6MB, anti-spam e antiv�rus gratuito. Crie sua conta agora:
http://mail.yahoo.com.br
===========================================================================
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".