My model is a Object3d which extends Node. When I select it(it works by the way), I want to be able to move it. I have an internal frame with a panel and 3 JSpinners for X, Y and Z values and a JButton. When I click on it, I'm trying to move my model by the (x, y, z) offset.
It works when I select a value for the first time. Let's say I select 5 units for the X value, 0 for the rest. When I click the button, it moves my object, but when I select a different value, it goes wierd. :? Any ideas?
Can you provide a little more explaination about the wierd behavior? Maybe a screen shot or a cade snip.
nymon said:
Can you provide a little more explaination about the wierd behavior? Maybe a screen shot or a cade snip.
Like I said, selecting 5 units to move the first time. After clicking ok, my object moves that amount. But when I try to move it again by 5 units, it does nothing. Selecting 10 units will move it by only 5 units. After doing so, I tried again doing the 5 units translation, but it does the translation in the opposite direction, like the first few movements were never there. :| Creating the object :

After moving it by 5 units

After moving it by 10 units(actually just 5 as far as I can tell)

Some code:
Creating that window
// MOVE dialog
final JDesktopPane desktopPane = jmeDesktop.getJDesktop();
//final JOptionPane moveOptionDialog = new JOptionPane("");
JPanel moveDialogPanel = new JPanel();
JPanel absolutePoz = createNewPanel("Absolute (cm)", false, "move");
JPanel moveBy = createNewPanel("Offset (cm)", true, "move");
JButton okMoveButton = new JButton("OK");
JButton cancelMoveButton = new JButton("Cancel");
//moveDialog.setBounds(200,200,300,180);
moveDialog.add(moveDialogPanel);
GroupLayout moveDialogLayout = new GroupLayout(moveDialogPanel);
moveDialogPanel.setLayout(moveDialogLayout);
moveDialogLayout.setHorizontalGroup(
moveDialogLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(moveDialogLayout.createSequentialGroup()
.addContainerGap(5,5)
.addComponent(absolutePoz,GroupLayout.DEFAULT_SIZE,120,GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(moveDialogLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.CENTER, moveDialogLayout.createSequentialGroup()
.addGap(5)
.addComponent(okMoveButton)
.addGap(5)
.addComponent(cancelMoveButton)
)
.addComponent(moveBy,GroupLayout.DEFAULT_SIZE,120,GroupLayout.PREFERRED_SIZE)
)
.addContainerGap(5,5)
)
);
moveDialogLayout.setVerticalGroup(
moveDialogLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(moveDialogLayout.createSequentialGroup()
.addGroup(moveDialogLayout.createParallelGroup()
.addComponent(absolutePoz,GroupLayout.DEFAULT_SIZE,100,GroupLayout.PREFERRED_SIZE)
.addComponent(moveBy,GroupLayout.DEFAULT_SIZE,100,GroupLayout.PREFERRED_SIZE)
.addGap(5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(moveDialogLayout.createParallelGroup()
.addComponent(okMoveButton)
.addComponent(cancelMoveButton)
)
)
);
desktopPane.add( moveDialog );
moveDialog.setVisible( true );
moveDialog.setSize( moveDialog.getPreferredSize() );
jmeDesktop.setFocusOwner( okMoveButton );
ActionListener[] listeners = okMoveButton.getActionListeners();
if(listeners != null)
for (int i = 0; i < listeners.length; i++) {
okMoveButton.removeActionListener(listeners[i]);
}
okMoveButton.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
JButton okButton = (JButton)e.getSource();
JPanel tempMoveDialog = (JPanel)okButton.getParent();
JPanel moveBy = (JPanel)tempMoveDialog.getComponent(3);
float x, y, z;
x = Float.valueOf((((JSpinner)moveBy.getComponent(1)).getValue().toString()));
y = Float.valueOf((((JSpinner)moveBy.getComponent(3)).getValue().toString()));
z = Float.valueOf((((JSpinner)moveBy.getComponent(5)).getValue().toString()));
System.out.println("ok button x = " + x + " y = " + y + " z = " + z);
if(mousePick.getPickedObject().getModel() != null) {
//mousePick.getPickedObject().setLocalTranslation(x, y, z);
mousePick.getPickedObject().getLocalTranslation().set(x, y, z);
}
((JSpinner)moveBy.getComponent(1)).setValue(0f);
((JSpinner)moveBy.getComponent(3)).setValue(0f);
((JSpinner)moveBy.getComponent(5)).setValue(0f);
//moveDialog.setVisible( false );
//desktopPane.remove( moveDialog );
}
} );
cancelMoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
moveDialog.setVisible( false );
desktopPane.remove( moveDialog );
}
});
Anybody any ideas?
What if you try using:
mousePick.getPickedObject().getLocalTranslation().addLocal(x, y, z);
instead of:
mousePick.getPickedObject().getLocalTranslation().set(x, y, z);
Does that give you the desired effect?
nymon said:
What if you try using:
mousePick.getPickedObject().getLocalTranslation().addLocal(x, y, z);
instead of:
mousePick.getPickedObject().getLocalTranslation().set(x, y, z);
Does that give you the desired effect?
:D :-o IT works. Thanks a million times. Now I have to check the world coordinates and to figure out how to be able to rotate and scale the object
Glad to help.
You should be able to accomplish that in a similar fashion, using getLocalScale().addLocal() and getLocalRotation()…
nymon said:
Glad to help.
You should be able to accomplish that in a similar fashion, using getLocalScale().addLocal() and getLocalRotation()...
I've got a bit of a problem now with scaling the object. As you've seen in the pictures above, every object3d in the scene has a name above it's head. When I scale the object, it affects the name too. How can I stop that? I want the name to remain the same size, no matter how big or small the object gets.
Are you attaching the name to the object? If so, you could try scaling the node down as you scale up your object, but thats ugly. Or you could Attach a node above your object, add the text to that node. You could rotate/translate on the parent node and then scale on your object. That would do it.
Or you can try something completely different…
Maintain a separate node with all you text labels attached to it, then attach a controller for each which will sync the text location with the node its associated with. You'll probably have to write this controller, but it will be simple.
That give something go on?
nymon said:
Are you attaching the name to the object? If so, you could try scaling the node down as you scale up your object, but thats ugly. Or you could Attach a node above your object, add the text to that node. You could rotate/translate on the parent node and then scale on your object. That would do it.
You gave me an idea and it worked. I did not apply the scale to the object3d, but to its children( the model, the name and the selection box) Something like this.model.getLocalScale().multLocal(1f + localScale); (for uniform scale). It seems it works rather well.
I need now to figure out how to rotate my object along the X, Y and Z axis. Still dunno yet.