merge dev/client_koppe into dev/client_beck for camera movement
This commit is contained in:
		@@ -11,8 +11,8 @@ public class InputSynchronizer {
 | 
			
		||||
    private InputManager inputManager;
 | 
			
		||||
 | 
			
		||||
    protected boolean rightMousePressed = false;
 | 
			
		||||
    private float rotationAngle = 0f;
 | 
			
		||||
    private int scrollValue = 50;
 | 
			
		||||
    private float rotationAngle = 180f;
 | 
			
		||||
    private int scrollValue = 0;
 | 
			
		||||
 | 
			
		||||
    InputSynchronizer(MdgaApp app) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
@@ -22,11 +22,6 @@ public class InputSynchronizer {
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ public class MdgaApp extends SimpleApplication {
 | 
			
		||||
    MdgaView view = null;
 | 
			
		||||
    private MdgaState state = MdgaState.GAME;
 | 
			
		||||
 | 
			
		||||
    private static float resolutionFactor = 1f;
 | 
			
		||||
    private static float resolutionFactor = 1.8f;
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        AppSettings settings = new AppSettings(true);
 | 
			
		||||
@@ -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) {
 | 
			
		||||
        inputSynchronizer.update();
 | 
			
		||||
        view.update();
 | 
			
		||||
        acousticHandler.update();
 | 
			
		||||
        notificationSynchronizer.update();
 | 
			
		||||
@@ -114,4 +117,6 @@ public MdgaView getView() {
 | 
			
		||||
    public ModelSyncronizer getModelSyncronizer() {
 | 
			
		||||
        return modelSyncronizer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public InputSynchronizer getInputSyncronizer() { return inputSynchronizer; }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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,11 +33,6 @@ 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.getRootNode().addLight(sun);
 | 
			
		||||
        app.getRootNode().addLight(ambient);
 | 
			
		||||
    }
 | 
			
		||||
@@ -45,4 +41,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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,15 @@
 | 
			
		||||
package pp.mdga.client.dialog;
 | 
			
		||||
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
public class GetPercentRunnable {
 | 
			
		||||
    private final Supplier<Float> action;
 | 
			
		||||
 | 
			
		||||
    public GetPercentRunnable(Supplier<Float> action) {
 | 
			
		||||
        this.action = action;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float get() {
 | 
			
		||||
        return action.get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -26,7 +26,7 @@ public HostDialog(MdgaApp app, Node node, Runnable backAction) {
 | 
			
		||||
        Panel imagePanel = new Panel();
 | 
			
		||||
        imagePanel.setBackground(b);
 | 
			
		||||
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 0));
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0));
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ public JoinDialog(MdgaApp app, Node node, Runnable backAction) {
 | 
			
		||||
        Panel imagePanel = new Panel();
 | 
			
		||||
        imagePanel.setBackground(b);
 | 
			
		||||
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4, texture.getImage().getHeight() / 4, 0));
 | 
			
		||||
        container.addChild(imagePanel).setPreferredSize(new Vector3f(texture.getImage().getWidth() / 4 * app.getResolutionFactor(), texture.getImage().getHeight() / 4 * app.getResolutionFactor(), 0));
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(100 * app.getResolutionFactor(), 50 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,7 @@ public class SettingsDialog extends Dialog {
 | 
			
		||||
    private TextField nameInput;
 | 
			
		||||
 | 
			
		||||
    private HashMap<Slider, PercentRunnable> map = new HashMap<Slider, PercentRunnable>();
 | 
			
		||||
    private HashMap<Slider, GetPercentRunnable> map2 = new HashMap<Slider, GetPercentRunnable>();
 | 
			
		||||
 | 
			
		||||
    public SettingsDialog(MdgaApp app, Node node, String path) {
 | 
			
		||||
        super(app, node);
 | 
			
		||||
@@ -62,7 +63,7 @@ public void addButton(String label, Runnable action, Vector3f size) {
 | 
			
		||||
        createButton(label, action, size);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addSlider(String label, PercentRunnable action, Vector3f size, int start) {
 | 
			
		||||
    public void addSlider(String label, PercentRunnable action, GetPercentRunnable action2, Vector3f size, int start) {
 | 
			
		||||
        Container subContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
 | 
			
		||||
 | 
			
		||||
        Slider slider = new Slider("slider");
 | 
			
		||||
@@ -71,7 +72,7 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
 | 
			
		||||
        slider.setBackground(background);
 | 
			
		||||
 | 
			
		||||
        slider.setPreferredSize(size);
 | 
			
		||||
        slider.setModel(new DefaultRangedValueModel(0, 10, start));
 | 
			
		||||
        slider.setModel(new DefaultRangedValueModel(0, 100, start));
 | 
			
		||||
        slider.setPreferredSize(new Vector3f(150 * app.getResolutionFactor(), 30 * app.getResolutionFactor(), 0));
 | 
			
		||||
        slider.getDecrementButton().setText(" - ");
 | 
			
		||||
        slider.getIncrementButton().setText(" + ");
 | 
			
		||||
@@ -89,11 +90,19 @@ public void addSlider(String label, PercentRunnable action, Vector3f size, int s
 | 
			
		||||
        container.addChild(subContainer);
 | 
			
		||||
 | 
			
		||||
        map.put(slider, action);
 | 
			
		||||
        map2.put(slider, action2);
 | 
			
		||||
 | 
			
		||||
        //abstandshalter
 | 
			
		||||
        container.addChild(new Panel(20 * app.getResolutionFactor(), 10 * app.getResolutionFactor(), ColorRGBA.Gray));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void initVolume() {
 | 
			
		||||
        map2.forEach((slider, runnable) -> {
 | 
			
		||||
            double val = (double) runnable.get();
 | 
			
		||||
            slider.getModel().setPercent(val);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void update() {
 | 
			
		||||
        map.forEach((slider, runnable) -> {
 | 
			
		||||
            float val = (float) slider.getModel().getPercent();
 | 
			
		||||
 
 | 
			
		||||
@@ -95,6 +95,11 @@ public void onLeave() {
 | 
			
		||||
        boardHandler.shutdown();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onUpdate() {
 | 
			
		||||
        camera.update(app.getInputSyncronizer().getScroll(), app.getInputSyncronizer().getRotation());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void enterExtendedSettings() {
 | 
			
		||||
        leaveButton.show();
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@
 | 
			
		||||
import com.jme3.scene.Node;
 | 
			
		||||
import com.jme3.scene.shape.Quad;
 | 
			
		||||
import com.jme3.texture.Texture;
 | 
			
		||||
import pp.mdga.client.dialog.GetPercentRunnable;
 | 
			
		||||
import pp.mdga.client.dialog.PercentRunnable;
 | 
			
		||||
import pp.mdga.client.dialog.SettingsButtonDialog;
 | 
			
		||||
import pp.mdga.client.MdgaApp;
 | 
			
		||||
@@ -34,6 +35,8 @@ public abstract class MdgaView {
 | 
			
		||||
    private SettingsDialog audio;
 | 
			
		||||
    private SettingsDialog video;
 | 
			
		||||
 | 
			
		||||
    private static final String IMAGE_ROOT = "Images/";
 | 
			
		||||
 | 
			
		||||
    public MdgaView(MdgaApp app) {
 | 
			
		||||
        this.app = app;
 | 
			
		||||
        this.node = new Node();
 | 
			
		||||
@@ -44,29 +47,29 @@ public MdgaView(MdgaApp app) {
 | 
			
		||||
 | 
			
		||||
        this.settingsButton = new SettingsButtonDialog(app, node, "", () -> enterSettings(false));
 | 
			
		||||
 | 
			
		||||
        this.settingsBackground = createBackground("Images/background/zahnräder.png");
 | 
			
		||||
        this.settingsBackground = createBackground(IMAGE_ROOT + "background/zahnräder.png");
 | 
			
		||||
        settingsNode.attachChild(settingsBackground);
 | 
			
		||||
 | 
			
		||||
        this.audioBackground = createBackground("Images/background/lautsprecher.png");
 | 
			
		||||
        this.audioBackground = createBackground(IMAGE_ROOT + "background/lautsprecher.png");
 | 
			
		||||
        audioSettingsNode.attachChild(audioBackground);
 | 
			
		||||
 | 
			
		||||
        this.videoBackground = createBackground("Images/background/monitors.png");
 | 
			
		||||
        this.videoBackground = createBackground(IMAGE_ROOT + "background/monitors.png");
 | 
			
		||||
        videoSettingsNode.attachChild(videoBackground);
 | 
			
		||||
 | 
			
		||||
        Vector3f size = new Vector3f(280, 60, 0);
 | 
			
		||||
 | 
			
		||||
        this.settings = new SettingsDialog(app, settingsNode, "Images/zahnrad.png");
 | 
			
		||||
        this.settings = new SettingsDialog(app, settingsNode, IMAGE_ROOT + "zahnrad.png");
 | 
			
		||||
        this.settings.addButton("Video", () -> enterVideo(), size);
 | 
			
		||||
        this.settings.addButton("Audio", () -> enterAudio(), size);
 | 
			
		||||
        this.settings.addButton("Zurück", () -> leaveSettings(false), size);
 | 
			
		||||
 | 
			
		||||
        this.audio = new SettingsDialog(app, audioSettingsNode, "Images/audio_icon.png");
 | 
			
		||||
        this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), size, 5);
 | 
			
		||||
        this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), size, 10);
 | 
			
		||||
        this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), size, 10);
 | 
			
		||||
        this.audio = new SettingsDialog(app, audioSettingsNode, IMAGE_ROOT + "audio_icon.png");
 | 
			
		||||
        this.audio.addSlider("Lautstärke", new PercentRunnable(app.getAcousticHandler()::setMainVolume), new GetPercentRunnable(app.getAcousticHandler()::getMainVolume), size, (int) app.getAcousticHandler().getMainVolume() * 100);
 | 
			
		||||
        this.audio.addSlider("Musik", new PercentRunnable(app.getAcousticHandler()::setMusicVolume), new GetPercentRunnable(app.getAcousticHandler()::getMusicVolume), size, (int) app.getAcousticHandler().getMusicVolume() * 100);
 | 
			
		||||
        this.audio.addSlider("Sound", new PercentRunnable(app.getAcousticHandler()::setSoundVolume), new GetPercentRunnable(app.getAcousticHandler()::getSoundVolume), size, (int) app.getAcousticHandler().getSoundVolume() * 100);
 | 
			
		||||
        this.audio.addButton("Zurück", () -> leaveAudio(), size);
 | 
			
		||||
 | 
			
		||||
        this.video = new SettingsDialog(app, videoSettingsNode, "Images/monitor.png");
 | 
			
		||||
        this.video = new SettingsDialog(app, videoSettingsNode, IMAGE_ROOT + "monitor.png");
 | 
			
		||||
        this.video.addButton("A", () -> System.out.println("A"), size);
 | 
			
		||||
        this.video.addButton("B", () -> System.out.println("B"), size);
 | 
			
		||||
        this.video.addButton("Zurück", () -> leaveVideo(), size);
 | 
			
		||||
@@ -75,6 +78,8 @@ public MdgaView(MdgaApp app) {
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        app.getGuiNode().attachChild(node);
 | 
			
		||||
 | 
			
		||||
        audio.initVolume();
 | 
			
		||||
 | 
			
		||||
        settingsButton.show();
 | 
			
		||||
 | 
			
		||||
        onEnter();
 | 
			
		||||
@@ -90,10 +95,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