- fixed key event dispatching from sceneViewer to oglpanel
- added a useCameraControl to avoid to have to override the onAnalog in each cameraController
- added alternate way to rotate camera wuth the third mouse button
- changed position of the view toolbar


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7929 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 654ee5f0db
commit 2fe3bc6dc6
  1. 14
      sdk/jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java
  2. 5
      sdk/jme3-core/src/com/jme3/gde/core/scene/SceneCameraController.java
  3. 106
      sdk/jme3-core/src/com/jme3/gde/core/scene/controller/AbstractCameraController.java
  4. 2
      sdk/jme3-core/src/com/jme3/gde/core/scene/controller/toolbars/CameraToolbar.java
  5. 45
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/SceneViewerTopComponent.java
  6. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBackViewAction.java
  7. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchBottomViewAction.java
  8. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchFrontViewAction.java
  9. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchLeftViewAction.java
  10. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchRightViewAction.java
  11. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/SwitchTopViewAction.java
  12. 2
      sdk/jme3-core/src/com/jme3/gde/core/sceneviewer/actions/ToggleOrthoPerspAction.java

@ -136,11 +136,7 @@ public class SceneApplication extends Application implements LookupProvider, Loo
} }
} }
public SceneCameraController getActiveCameraController() {
stateManager.getState(null);
return camController;
}
private void loadFPSText() { private void loadFPSText() {
@ -385,8 +381,8 @@ public class SceneApplication extends Application implements LookupProvider, Loo
} }
toolsNode.detachAllChildren(); toolsNode.detachAllChildren();
rootNode.detachAllChildren(); rootNode.detachAllChildren();
setHelpContext(null); setHelpContext(null);
resetCam(); // resetCam();
currentSceneRequest = null; currentSceneRequest = null;
lastError = ""; lastError = "";
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
@ -536,11 +532,11 @@ public class SceneApplication extends Application implements LookupProvider, Loo
return progressHandle; return progressHandle;
} }
public AbstractCameraController getActiveCamController() { public AbstractCameraController getActiveCameraController() {
return activeCamController; return activeCamController;
} }
public void setActiveCamController(AbstractCameraController activeCamController) { public void setActiveCameraController(AbstractCameraController activeCamController) {
this.activeCamController = activeCamController; this.activeCamController = activeCamController;
} }

@ -49,4 +49,9 @@ public class SceneCameraController extends AbstractCameraController {
protected void checkClick(int button, boolean pressed) { protected void checkClick(int button, boolean pressed) {
} }
@Override
public boolean useCameraControls() {
return true;
}
} }

@ -32,6 +32,7 @@ import com.jme3.gde.core.scene.controller.toolbars.CameraToolbar;
import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent; import com.jme3.gde.core.sceneviewer.SceneViewerTopComponent;
import com.jme3.gde.core.util.CameraUtil.View; import com.jme3.gde.core.util.CameraUtil.View;
import com.jme3.input.InputManager; import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.RawInputListener; import com.jme3.input.RawInputListener;
import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener; import com.jme3.input.controls.AnalogListener;
@ -81,6 +82,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
protected boolean checkDraggedR = false; protected boolean checkDraggedR = false;
protected boolean checkReleaseLeft = false; protected boolean checkReleaseLeft = false;
protected boolean checkReleaseRight = false; protected boolean checkReleaseRight = false;
protected boolean shiftModifier = false;
public AbstractCameraController(Camera cam, InputManager inputManager) { public AbstractCameraController(Camera cam, InputManager inputManager) {
this.cam = cam; this.cam = cam;
@ -96,35 +98,51 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
inputManager.addRawInputListener(this); inputManager.addRawInputListener(this);
inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight"); inputManager.addListener(this, "MouseAxisX", "MouseAxisY", "MouseAxisX-", "MouseAxisY-", "MouseWheel", "MouseWheel-", "MouseButtonLeft", "MouseButtonMiddle", "MouseButtonRight");
SceneApplication.getApplication().getStateManager().attach(this); SceneApplication.getApplication().getStateManager().attach(this);
SceneApplication.getApplication().setActiveCamController(this); AbstractCameraController cc = SceneApplication.getApplication().getActiveCameraController();
if (cc != null) {
cam.setLocation(cc.cam.getLocation());
focus.set(cc.focus);
}
SceneApplication.getApplication().setActiveCameraController(this);
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
addAdditionnalToolbar();
SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance();
if (svtc != null) {
svtc.addAdditionnalToolbar(CameraToolbar.getInstance());
}
} }
}); });
} }
private void addAdditionnalToolbar() {
SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance();
if (svtc != null) {
svtc.add(CameraToolbar.getInstance(), java.awt.BorderLayout.SOUTH);;
}
}
public void removeAdditionnalToolbar() {
SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance();
System.out.println("test remove" + svtc);
if (svtc != null) {
svtc.remove(CameraToolbar.getInstance());
}
}
public void disable() { public void disable() {
inputManager.removeRawInputListener(this); inputManager.removeRawInputListener(this);
inputManager.removeListener(this); inputManager.removeListener(this);
SceneApplication.getApplication().getStateManager().detach(this); SceneApplication.getApplication().getStateManager().detach(this);
java.awt.EventQueue.invokeLater(new Runnable() { if (SceneApplication.getApplication().getActiveCameraController() == this) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
removeAdditionnalToolbar();
SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance();
if (svtc != null) {
svtc.removeAdditionnalToolbar(CameraToolbar.getInstance());
} }
});
} }
});
} }
public void setCamFocus(final Vector3f focus) { public void setCamFocus(final Vector3f focus) {
@ -160,7 +178,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
Quaternion curRot = cam.getRotation().clone(); Quaternion curRot = cam.getRotation().clone();
cam.setRotation(rot.mult(curRot)); cam.setRotation(rot.mult(curRot));
java.awt.EventQueue.invokeLater(new Runnable() { java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
@ -225,32 +243,32 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
float dist = cam.getLocation().distance(focus); float dist = cam.getLocation().distance(focus);
switch (view) { switch (view) {
case Front: case Front:
cam.setLocation(new Vector3f(focus.x, focus.y, focus.z+dist)); cam.setLocation(new Vector3f(focus.x, focus.y, focus.z + dist));
cam.lookAt(focus, Vector3f.UNIT_Y); cam.lookAt(focus, Vector3f.UNIT_Y);
break; break;
case Left: case Left:
cam.setLocation(new Vector3f(focus.x+dist, focus.y, focus.z)); cam.setLocation(new Vector3f(focus.x + dist, focus.y, focus.z));
cam.lookAt(focus, Vector3f.UNIT_Y); cam.lookAt(focus, Vector3f.UNIT_Y);
break; break;
case Right: case Right:
cam.setLocation(new Vector3f(focus.x-dist, focus.y, focus.z)); cam.setLocation(new Vector3f(focus.x - dist, focus.y, focus.z));
cam.lookAt(focus, Vector3f.UNIT_Y); cam.lookAt(focus, Vector3f.UNIT_Y);
break; break;
case Back: case Back:
cam.setLocation(new Vector3f(focus.x, focus.y, focus.z-dist)); cam.setLocation(new Vector3f(focus.x, focus.y, focus.z - dist));
cam.lookAt(focus, Vector3f.UNIT_Y); cam.lookAt(focus, Vector3f.UNIT_Y);
break; break;
case Top: case Top:
cam.setLocation(new Vector3f(focus.x, focus.y+dist, focus.z)); cam.setLocation(new Vector3f(focus.x, focus.y + dist, focus.z));
cam.lookAt(focus, Vector3f.UNIT_Z.mult(-1)); cam.lookAt(focus, Vector3f.UNIT_Z.mult(-1));
break; break;
case Bottom: case Bottom:
cam.setLocation(new Vector3f(focus.x, focus.y-dist, focus.z)); cam.setLocation(new Vector3f(focus.x, focus.y - dist, focus.z));
cam.lookAt(focus, Vector3f.UNIT_Z); cam.lookAt(focus, Vector3f.UNIT_Z);
break; break;
case User: case User:
default: default:
} }
return null; return null;
} }
@ -279,43 +297,53 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
} }
} }
public abstract boolean useCameraControls();
public void onAnalog(String string, float f1, float f) { public void onAnalog(String string, float f1, float f) {
if ("MouseAxisX".equals(string)) { if ("MouseAxisX".equals(string)) {
moved = true; moved = true;
movedR = true; movedR = true;
if (buttonDownL || buttonDownM) {
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f); rotateCamera(Vector3f.UNIT_Y, -f1 * 2.5f);
} }
if (buttonDownR) { if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(f1 * 2.5f, 0); panCamera(f1 * 2.5f, 0);
} }
} else if ("MouseAxisY".equals(string)) { } else if ("MouseAxisY".equals(string)) {
moved = true; moved = true;
movedR = true; movedR = true;
if (buttonDownL || buttonDownM) {
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(cam.getLeft(), -f1 * 2.5f); rotateCamera(cam.getLeft(), -f1 * 2.5f);
} }
if (buttonDownR) { if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(0, -f1 * 2.5f); panCamera(0, -f1 * 2.5f);
} }
} else if ("MouseAxisX-".equals(string)) { } else if ("MouseAxisX-".equals(string)) {
moved = true; moved = true;
movedR = true; movedR = true;
if (buttonDownL || buttonDownM) {
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f); rotateCamera(Vector3f.UNIT_Y, f1 * 2.5f);
} }
if (buttonDownR) { if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(-f1 * 2.5f, 0); panCamera(-f1 * 2.5f, 0);
} }
} else if ("MouseAxisY-".equals(string)) { } else if ("MouseAxisY-".equals(string)) {
moved = true; moved = true;
movedR = true; movedR = true;
if (buttonDownL || buttonDownM) {
if ((buttonDownL && useCameraControls()) || (buttonDownM && !shiftModifier)) {
rotateCamera(cam.getLeft(), f1 * 2.5f); rotateCamera(cam.getLeft(), f1 * 2.5f);
} }
if (buttonDownR) { if ((buttonDownR && useCameraControls()) || (buttonDownM && shiftModifier)) {
panCamera(0, f1 * 2.5f); panCamera(0, f1 * 2.5f);
} }
} else if ("MouseWheel".equals(string)) { } else if ("MouseWheel".equals(string)) {
zoomCamera(.1f); zoomCamera(.1f);
} else if ("MouseWheel-".equals(string)) { } else if ("MouseWheel-".equals(string)) {
@ -355,6 +383,7 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
buttonDownR = pressed; buttonDownR = pressed;
} }
if ("MouseButtonMiddle".equals(string)) { if ("MouseButtonMiddle".equals(string)) {
if (pressed) { if (pressed) {
if (!buttonDownM) { // mouse clicked if (!buttonDownM) { // mouse clicked
checkClickM = true; checkClickM = true;
@ -398,6 +427,15 @@ public abstract class AbstractCameraController extends AbstractAppState implemen
} }
public void onKeyEvent(KeyInputEvent kie) { public void onKeyEvent(KeyInputEvent kie) {
if (kie.isPressed()) {
if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
shiftModifier = true;
}
} else if (kie.isReleased()) {
if (KeyInput.KEY_LSHIFT == kie.getKeyCode()) {
shiftModifier = false;
}
}
} }
public void onTouchEvent(TouchEvent evt) { public void onTouchEvent(TouchEvent evt) {

@ -177,7 +177,7 @@ public class CameraToolbar extends javax.swing.JToolBar {
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void viewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewButtonActionPerformed private void viewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewButtonActionPerformed
viewMenu.show(viewButton, viewButton.getX(), viewButton.getY() + viewButton.getHeight()); viewMenu.show(viewButton, 0,- viewMenu.getHeight());
}//GEN-LAST:event_viewButtonActionPerformed }//GEN-LAST:event_viewButtonActionPerformed
private void frontMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_frontMenuItemActionPerformed private void frontMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_frontMenuItemActionPerformed

@ -28,8 +28,12 @@ import com.jme3.gde.core.filters.FilterExplorerTopComponent;
import com.jme3.gde.core.scene.SceneApplication; import com.jme3.gde.core.scene.SceneApplication;
import com.jme3.gde.core.scene.controller.toolbars.CameraToolbar; import com.jme3.gde.core.scene.controller.toolbars.CameraToolbar;
import com.jme3.gde.core.sceneviewer.actions.ToggleOrthoPerspAction; import com.jme3.gde.core.sceneviewer.actions.ToggleOrthoPerspAction;
import com.jme3.input.awt.AwtKeyInput;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.system.JmeCanvasContext; import com.jme3.system.JmeCanvasContext;
import java.awt.Canvas; import java.awt.Canvas;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener; import java.awt.event.MouseWheelListener;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -63,7 +67,6 @@ public final class SceneViewerTopComponent extends TopComponent {
private SceneApplication app; private SceneApplication app;
private HelpCtx helpContext = new HelpCtx("com.jme3.gde.core.sceneviewer"); private HelpCtx helpContext = new HelpCtx("com.jme3.gde.core.sceneviewer");
private Canvas oglCanvas; private Canvas oglCanvas;
public SceneViewerTopComponent() { public SceneViewerTopComponent() {
initComponents(); initComponents();
@ -71,12 +74,12 @@ public final class SceneViewerTopComponent extends TopComponent {
setFocusable(true); setFocusable(true);
setName(NbBundle.getMessage(SceneViewerTopComponent.class, "CTL_SceneViewerTopComponent")); setName(NbBundle.getMessage(SceneViewerTopComponent.class, "CTL_SceneViewerTopComponent"));
setToolTipText(NbBundle.getMessage(SceneViewerTopComponent.class, "HINT_SceneViewerTopComponent")); setToolTipText(NbBundle.getMessage(SceneViewerTopComponent.class, "HINT_SceneViewerTopComponent"));
setIcon(ImageUtilities.loadImage(ICON_PATH, true)); setIcon(ImageUtilities.loadImage(ICON_PATH, true));
try { try {
app = SceneApplication.getApplication(); app = SceneApplication.getApplication();
oglCanvas = ((JmeCanvasContext) app.getContext()).getCanvas(); oglCanvas = ((JmeCanvasContext) app.getContext()).getCanvas();
oGLPanel.add(oglCanvas); oGLPanel.add(oglCanvas);
} catch (Exception e) { } catch (Exception e) {
Exceptions.printStackTrace(e); Exceptions.printStackTrace(e);
showOpenGLError(e.toString()); showOpenGLError(e.toString());
@ -94,11 +97,30 @@ public final class SceneViewerTopComponent extends TopComponent {
if (e.getWheelRotation() < 0) { if (e.getWheelRotation() < 0) {
action = "MouseWheel"; action = "MouseWheel";
} }
app.getActiveCamController().onAnalog(action, e.getWheelRotation(), 0); app.getActiveCameraController().onAnalog(action, e.getWheelRotation(), 0);
}
});
addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent evt) {
}
public void keyPressed(KeyEvent evt) {
int code = AwtKeyInput.convertAwtKey(evt.getKeyCode());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
keyEvent.setTime(evt.getWhen());
app.getActiveCameraController().onKeyEvent(keyEvent);
}
public void keyReleased(KeyEvent evt) {
int code = AwtKeyInput.convertAwtKey(evt.getKeyCode());
KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
keyEvent.setTime(evt.getWhen());
app.getActiveCameraController().onKeyEvent(keyEvent);
} }
}); });
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to
@ -200,7 +222,6 @@ public final class SceneViewerTopComponent extends TopComponent {
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
FilterExplorerTopComponent.findInstance().setFilterEnabled(jToggleButton1.isSelected()); FilterExplorerTopComponent.findInstance().setFilterEnabled(jToggleButton1.isSelected());
}//GEN-LAST:event_jToggleButton1ActionPerformed }//GEN-LAST:event_jToggleButton1ActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JToggleButton enableCamLight; private javax.swing.JToggleButton enableCamLight;
private javax.swing.JToggleButton enableStats; private javax.swing.JToggleButton enableStats;
@ -212,7 +233,6 @@ public final class SceneViewerTopComponent extends TopComponent {
private javax.swing.JPanel oGLPanel; private javax.swing.JPanel oGLPanel;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
/** /**
* Gets default instance. Do not use directly: reserved for *.settings files only, * Gets default instance. Do not use directly: reserved for *.settings files only,
* i.e. deserialization routines; otherwise you could get a non-deserialized instance. * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
@ -324,13 +344,4 @@ public final class SceneViewerTopComponent extends TopComponent {
public UndoRedo getUndoRedo() { public UndoRedo getUndoRedo() {
return Lookup.getDefault().lookup(UndoRedo.class); return Lookup.getDefault().lookup(UndoRedo.class);
} }
public void addAdditionnalToolbar(JToolBar tb){
jToolBar1.add(tb,4);
}
public void removeAdditionnalToolbar(JToolBar tb){
jToolBar1.remove(tb);
}
} }

@ -25,7 +25,7 @@ public final class SwitchBackViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Back); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Back);
} }
} }
} }

@ -25,7 +25,7 @@ public final class SwitchBottomViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Bottom); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Bottom);
} }
} }
} }

@ -26,7 +26,7 @@ public final class SwitchFrontViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Front); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Front);
} }
} }
} }

@ -25,7 +25,7 @@ public final class SwitchLeftViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Left); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Left);
} }
} }
} }

@ -25,7 +25,7 @@ public final class SwitchRightViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Right); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Right);
} }
} }
} }

@ -25,7 +25,7 @@ public final class SwitchTopViewAction implements ActionListener {
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().switchToView(View.Top); SceneApplication.getApplication().getActiveCameraController().switchToView(View.Top);
} }
} }
} }

@ -28,7 +28,7 @@ public final class ToggleOrthoPerspAction implements ActionListener {
SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance(); SceneViewerTopComponent svtc = SceneViewerTopComponent.findInstance();
if (svtc.hasFocus()) { if (svtc.hasFocus()) {
SceneApplication.getApplication().getActiveCamController().toggleOrthoPerspMode(); SceneApplication.getApplication().getActiveCameraController().toggleOrthoPerspMode();
} }
} }

Loading…
Cancel
Save