merge after refactoring #16
@@ -11,8 +11,8 @@ public class InputSyncronizer {
|
||||
private InputManager inputManager;
|
||||
|
||||
protected boolean rightMousePressed = false;
|
||||
private float rotationAngle = 0f;
|
||||
private int scrollValue = 50;
|
||||
private float rotationAngle = 180f;
|
||||
private int scrollValue = 0;
|
||||
|
||||
InputSyncronizer(MdgaApp app) {
|
||||
this.app = app;
|
||||
@@ -22,11 +22,6 @@ public class InputSyncronizer {
|
||||
setupInput();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
rotateModel();
|
||||
updateScrollValue();
|
||||
}
|
||||
|
||||
private void setupInput() {
|
||||
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) {
|
||||
if (name.equals("MouseLeft") && rightMousePressed) {
|
||||
rotationAngle -= value * 360f;
|
||||
rotateModel();
|
||||
} else if (name.equals("MouseRight") && rightMousePressed) {
|
||||
rotationAngle += value * 360f;
|
||||
rotateModel();
|
||||
} else if (name.equals("MouseScrollUp")) {
|
||||
scrollValue = Math.min(100, scrollValue + 1);
|
||||
updateScrollValue();
|
||||
scrollValue = Math.max(1, scrollValue - 5);
|
||||
} else if (name.equals("MouseScrollDown")) {
|
||||
scrollValue = Math.max(1, scrollValue - 1);
|
||||
updateScrollValue();
|
||||
scrollValue = Math.min(100, scrollValue + 5);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void rotateModel() {
|
||||
//System.out.println("Rotation Angle: " + rotationAngle);
|
||||
public float getRotation() {
|
||||
return (rotationAngle / 2) % 360;
|
||||
}
|
||||
|
||||
private void updateScrollValue() {
|
||||
//System.out.println("Scroll Value: " + scrollValue);
|
||||
public int getScroll() {
|
||||
return scrollValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,10 @@ public void simpleInitApp() {
|
||||
modelSyncronizer = new ModelSyncronizer(this);
|
||||
|
||||
inputManager.deleteMapping("SIMPLEAPP_Exit");
|
||||
inputManager.deleteMapping("FLYCAM_ZoomIn");
|
||||
inputManager.deleteMapping("FLYCAM_ZoomOut");
|
||||
inputManager.deleteMapping("FLYCAM_RotateDrag");
|
||||
flyCam.setEnabled(false);
|
||||
GuiGlobals.initialize(this);
|
||||
|
||||
enter(state);
|
||||
@@ -54,7 +58,6 @@ public void simpleInitApp() {
|
||||
|
||||
@Override
|
||||
public void simpleUpdate(float tpf) {
|
||||
inputSyncronizer.update();
|
||||
view.update();
|
||||
acousticHandler.update();
|
||||
notificationSynchronizer.update();
|
||||
@@ -114,4 +117,6 @@ public MdgaView getView() {
|
||||
public ModelSyncronizer getModelSyncronizer() {
|
||||
return modelSyncronizer;
|
||||
}
|
||||
|
||||
public InputSyncronizer getInputSyncronizer() { return inputSyncronizer; }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import com.jme3.light.AmbientLight;
|
||||
import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.post.FilterPostProcessor;
|
||||
import com.jme3.shadow.DirectionalLightShadowFilter;
|
||||
@@ -32,10 +33,10 @@ public CameraHandler(MdgaApp app, FilterPostProcessor fpp){
|
||||
}
|
||||
|
||||
public void init() {
|
||||
app.getFlyByCamera().setEnabled(true);
|
||||
int zoom = 20;
|
||||
app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
||||
app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
||||
//app.getFlyByCamera().setEnabled(true);
|
||||
//int zoom = 20;
|
||||
//app.getCamera().setLocation(new Vector3f(-zoom, 0, zoom));
|
||||
//app.getCamera().lookAt(new Vector3f(0, 0, 0), new Vector3f(0, 0, 1));
|
||||
|
||||
app.getRootNode().addLight(sun);
|
||||
app.getRootNode().addLight(ambient);
|
||||
@@ -45,4 +46,37 @@ public void shutdown() {
|
||||
app.getRootNode().removeLight(sun);
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
camera.update(app.getInputSyncronizer().getScroll(), app.getInputSyncronizer().getRotation());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enterExtendedSettings() {
|
||||
leaveButton.show();
|
||||
|
||||
@@ -93,10 +93,12 @@ public void leave() {
|
||||
|
||||
public void update() {
|
||||
audio.update();
|
||||
onUpdate();
|
||||
}
|
||||
|
||||
protected abstract void onEnter();
|
||||
protected abstract void onLeave();
|
||||
protected void onUpdate() {}
|
||||
|
||||
protected Geometry createBackground(String texturePath) {
|
||||
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