pspeed
Awesome dodge. Pick the parts of the post You can aggresively comment with Your classic “why this why that” instead of those require You to put an actual effort into an answer. Oh right… I forgot… You expect payment for Your help…
Why do You work on OpenSource Project then? I mean really? Isn’t “better future, great free tools and cookies for everyone” part of the deal?
Or if You simply dislike me (not the whole idea of helping which seems to be the case) why won’t You create good tutorials (I mean “zero to hero” tutorials that will explain every possible detail to people who see jMonkey for the first time in life). You’d have like 10000 times less repetetive questions here…
david
Here’s my code:
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.input.InputManager;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.math.Vector3f;
import com.jme3.scene.CameraNode;
import com.jme3.scene.Node;
import com.jme3.scene.control.CameraControl;
public class AppStateTest1 extends AbstractAppState {
private Node rootNode;
private InputManager inputManager;
public AppStateTest1(SimpleApplication app){
this.rootNode = app.getRootNode();
this.inputManager = app.getInputManager();
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
initKeys();
cameranode = new CameraNode("Main Camera", app.getCamera());
cameranode.setControlDir(CameraControl.ControlDirection.SpatialToCamera);
rootNode.attachChild(cameranode);
cameranode.setLocalTranslation(0, -2, -20);
}
private CameraNode cameranode;
private Boolean drag=false;
private void initKeys() {
inputManager.addMapping("Drag", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping("Left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
inputManager.addMapping("Right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
inputManager.addMapping("Up", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
inputManager.addMapping("Down", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
inputManager.addListener(analogListener,"Left", "Right", "Up", "Down");
inputManager.addListener(actionListener,"Drag");
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Drag") && keyPressed) {
drag = true;
}
if (name.equals("Drag") && !keyPressed) {
drag = false;
}
}
};
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
int speed = 25;
if (drag) {
if (name.equals("Right")) {
Vector3f v = cameranode.getLocalTranslation();
cameranode.setLocalTranslation(v.x + value * speed, v.y, v.z);
}
if (name.equals("Left")) {
Vector3f v = cameranode.getLocalTranslation();
cameranode.setLocalTranslation(v.x - value * speed, v.y, v.z);
}
if (name.equals("Up")) {
Vector3f v = cameranode.getLocalTranslation();
cameranode.setLocalTranslation(v.x, v.y + value * speed, v.z);
}
if (name.equals("Down")) {
Vector3f v = cameranode.getLocalTranslation();
cameranode.setLocalTranslation(v.x, v.y - value * speed, v.z);
}
}
}
};
}
But it doesn’t explain why I need another option because it works (like a charm actually).
As I said to our dearest developer above, I’m just exploring possibilities so I can make a decision what to use based on actual comparison. When I created this topic I hoped for several ready to use examples of solutions to choose from, guess that was too big of an expectation