I got problem with this: What I want to implement is making the object moving with the mouse, but my code cannot make the object move to the area where z<0 and x<0… can anyone help to figure this out?
inputManager.addMapping("Right",
new MouseAxisTrigger(MouseInput.AXIS_X, true)
);
inputManager.addMapping("Left",
new MouseAxisTrigger(MouseInput.AXIS_X, false)
);
inputManager.addMapping("Up",
new MouseAxisTrigger(MouseInput.AXIS_Y, false)
);
inputManager.addMapping("Down",
new MouseAxisTrigger(MouseInput.AXIS_Y, true)
);
// Add the names to the action listener.
inputManager.addListener(analogListener,"Right", "Left", "Up","Down");
inputManager.getCursorPosition();
}
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
Vector3f v = tool.getLocalTranslation();
if (name.equals(“Up”)) {
tool.setLocalTranslation(v.x, v.y, v.z - (float)value30speed);
}
else if (name.equals(“Down”)) {
tool.setLocalTranslation(v.x, v.y, v.z + (float)value30speed);
}
else if (name.equals(“Right”)) {
tool.setLocalTranslation(v.x - (float)value30speed, v.y, v.z);
}
else if (name.equals(“Left”)) {
tool.setLocalTranslation(v.x + (float)value30speed, v.y, v.z);
}
}
};
This is a case where very basic debugging will probably tell you what is happening.
For example, I bet if you simply printed out the “value” in your onAnalog() method then you’d see what’s going on. This kind of “verifying assumptions” is the cornerstone to debugging so its important to figure it out early as you learn Java.
Yes, I have printed them out… but they are always not less than -1… I don’t know why…
cam.setLocation(new Vector3f(0.0f,13.0f,28.0f));
cam.lookAt(new Vector3f(0,0,9f), new Vector3f(0,10,0));
this is the camera I have set, is something wrong with then?..
Well, working in one direction and not the other implies that he expects value to always be positive but value will definitely be negative sometimes… for example, going left. I was hoping to show him how to find the problem himself but that’s definitely the issue: + negative = - positive in this case… so the object will only move in one direction.
That’s interesting because the javadoc states the following
void onAnalog(java.lang.String name, float value, float tpf)
Called to notify the implementation that an analog event has occurred. The results of KeyTrigger and MouseButtonTrigger events will have tpf == value.
Parameters:
name - The name of the mapping that was invoked value - Value of the axis, from 0 to 1.
tpf - The time per frame value.
Yeah, you are right… I looked in the code and it looks like it’s passing the deltas directly but then I looked at flybycamera and it’s treating them as always positive.
Anyway, OP, you can look at FlyByCamera.java to see how it does things and then see what’s different.
System.out.println() is still a good idea to find things. An when you do, post the output and the code so that we don’t have to make assumptions.