Add rotateable cam
This commit is contained in:
@@ -11,8 +11,8 @@ public class InputSyncronizer {
|
|||||||
private InputManager inputManager;
|
private InputManager inputManager;
|
||||||
|
|
||||||
protected boolean rightMousePressed = false;
|
protected boolean rightMousePressed = false;
|
||||||
private float rotationAngle = 0f;
|
private float rotationAngle = 180f;
|
||||||
private int scrollValue = 50;
|
private int scrollValue = 0;
|
||||||
|
|
||||||
InputSyncronizer(MdgaApp app) {
|
InputSyncronizer(MdgaApp app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
@@ -22,11 +22,6 @@ public class InputSyncronizer {
|
|||||||
setupInput();
|
setupInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
|
||||||
rotateModel();
|
|
||||||
updateScrollValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupInput() {
|
private void setupInput() {
|
||||||
inputManager.addMapping("Settings", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
inputManager.addMapping("Settings", new KeyTrigger(KeyInput.KEY_ESCAPE));
|
||||||
|
|
||||||
@@ -57,25 +52,21 @@ public void onAction(String name, boolean isPressed, float tpf) {
|
|||||||
public void onAnalog(String name, float value, float tpf) {
|
public void onAnalog(String name, float value, float tpf) {
|
||||||
if (name.equals("MouseLeft") && rightMousePressed) {
|
if (name.equals("MouseLeft") && rightMousePressed) {
|
||||||
rotationAngle -= value * 360f;
|
rotationAngle -= value * 360f;
|
||||||
rotateModel();
|
|
||||||
} else if (name.equals("MouseRight") && rightMousePressed) {
|
} else if (name.equals("MouseRight") && rightMousePressed) {
|
||||||
rotationAngle += value * 360f;
|
rotationAngle += value * 360f;
|
||||||
rotateModel();
|
|
||||||
} else if (name.equals("MouseScrollUp")) {
|
} else if (name.equals("MouseScrollUp")) {
|
||||||
scrollValue = Math.min(100, scrollValue + 1);
|
scrollValue = Math.max(1, scrollValue - 5);
|
||||||
updateScrollValue();
|
|
||||||
} else if (name.equals("MouseScrollDown")) {
|
} else if (name.equals("MouseScrollDown")) {
|
||||||
scrollValue = Math.max(1, scrollValue - 1);
|
scrollValue = Math.min(100, scrollValue + 5);
|
||||||
updateScrollValue();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void rotateModel() {
|
public float getRotation() {
|
||||||
//System.out.println("Rotation Angle: " + rotationAngle);
|
return (rotationAngle / 2) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateScrollValue() {
|
public int getScroll() {
|
||||||
//System.out.println("Scroll Value: " + scrollValue);
|
return scrollValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ public void simpleInitApp() {
|
|||||||
modelSyncronizer = new ModelSyncronizer(this);
|
modelSyncronizer = new ModelSyncronizer(this);
|
||||||
|
|
||||||
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
||||||
|
inputManager.deleteMapping("FLYCAM_ZoomIn");
|
||||||
|
inputManager.deleteMapping("FLYCAM_ZoomOut");
|
||||||
|
inputManager.deleteMapping("FLYCAM_RotateDrag");
|
||||||
|
flyCam.setEnabled(false);
|
||||||
GuiGlobals.initialize(this);
|
GuiGlobals.initialize(this);
|
||||||
|
|
||||||
enter(state);
|
enter(state);
|
||||||
@@ -54,7 +58,6 @@ public void simpleInitApp() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
inputSyncronizer.update();
|
|
||||||
view.update();
|
view.update();
|
||||||
acousticHandler.update();
|
acousticHandler.update();
|
||||||
notificationSynchronizer.update();
|
notificationSynchronizer.update();
|
||||||
@@ -114,4 +117,6 @@ public MdgaView getView() {
|
|||||||
public ModelSyncronizer getModelSyncronizer() {
|
public ModelSyncronizer getModelSyncronizer() {
|
||||||
return modelSyncronizer;
|
return modelSyncronizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputSyncronizer getInputSyncronizer() { return inputSyncronizer; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import com.jme3.light.AmbientLight;
|
import com.jme3.light.AmbientLight;
|
||||||
import com.jme3.light.DirectionalLight;
|
import com.jme3.light.DirectionalLight;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.post.FilterPostProcessor;
|
import com.jme3.post.FilterPostProcessor;
|
||||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||||
@@ -32,10 +33,10 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
app.getFlyByCamera().setEnabled(true);
|
//app.getFlyByCamera().setEnabled(true);
|
||||||
int zoom = 20;
|
//int zoom = 20;
|
||||||
app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
//app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
||||||
app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
//app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
||||||
|
|
||||||
app.getRootNode().addLight(sun);
|
app.getRootNode().addLight(sun);
|
||||||
app.getRootNode().addLight(ambient);
|
app.getRootNode().addLight(ambient);
|
||||||
@@ -45,4 +46,37 @@ public void shutdown() {
|
|||||||
app.getRootNode().removeLight(sun);
|
app.getRootNode().removeLight(sun);
|
||||||
app.getRootNode().removeLight(ambient);
|
app.getRootNode().removeLight(ambient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void update(float scroll, float rotation) {
|
||||||
|
float scrollValue = Math.max(0, Math.min(scroll, 100));
|
||||||
|
|
||||||
|
float rotationValue = rotation % 360;
|
||||||
|
if (rotationValue < 0) {
|
||||||
|
rotationValue += 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
float radius;
|
||||||
|
|
||||||
|
float verticalAngle;
|
||||||
|
if (scroll < 100f) {
|
||||||
|
verticalAngle = 20f + (scrollValue / 100f) * 45f;
|
||||||
|
radius = 30f;
|
||||||
|
} else {
|
||||||
|
verticalAngle = 90f;
|
||||||
|
rotationValue = 270f;
|
||||||
|
radius = 50f;
|
||||||
|
}
|
||||||
|
|
||||||
|
float verticalAngleRadians = FastMath.DEG_TO_RAD * verticalAngle;
|
||||||
|
|
||||||
|
float z = radius * FastMath.sin(verticalAngleRadians);
|
||||||
|
float x = radius * FastMath.cos(verticalAngleRadians) * FastMath.sin(FastMath.DEG_TO_RAD * rotationValue);
|
||||||
|
float y = radius * FastMath.cos(verticalAngleRadians) * FastMath.cos(FastMath.DEG_TO_RAD * rotationValue);
|
||||||
|
|
||||||
|
Vector3f cameraPosition = new Vector3f(x, y, z);
|
||||||
|
app.getCamera().setLocation(cameraPosition);
|
||||||
|
|
||||||
|
app.getCamera().lookAt(Vector3f.ZERO, Vector3f.UNIT_Z);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,11 @@ public void onLeave() {
|
|||||||
boardHandler.shutdown();
|
boardHandler.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onUpdate() {
|
||||||
|
camera.update(app.getInputSyncronizer().getScroll(), app.getInputSyncronizer().getRotation());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enterExtendedSettings() {
|
protected void enterExtendedSettings() {
|
||||||
leaveButton.show();
|
leaveButton.show();
|
||||||
|
|||||||
@@ -93,10 +93,12 @@ public void leave() {
|
|||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
audio.update();
|
audio.update();
|
||||||
|
onUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void onEnter();
|
protected abstract void onEnter();
|
||||||
protected abstract void onLeave();
|
protected abstract void onLeave();
|
||||||
|
protected void onUpdate() {}
|
||||||
|
|
||||||
protected Geometry createBackground(String texturePath) {
|
protected Geometry createBackground(String texturePath) {
|
||||||
TextureKey key = new TextureKey(texturePath, true);
|
TextureKey key = new TextureKey(texturePath, true);
|
||||||
|
|||||||
BIN
Projekte/mdga/client/src/main/resources/test.png~
Normal file
BIN
Projekte/mdga/client/src/main/resources/test.png~
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 MiB |
Reference in New Issue
Block a user