The application below shows, that mouse X coordinates, returned by inputManager.getCursorPosition()
are probably pixels.
Simultaneously, the accumulated value
from analogListener
is not measured in pixels, and varies from 0
to 0.6
.
What are units for it? And is it possible to obtain mouse coordinates in the same units (without shown manual accumulation)?
[java] package tests.com.jme3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseAxisTrigger;
import com.jme3.math.ColorRGBA;
public class Try_MouseUnits extends SimpleApplication {
private static final Logger log = LoggerFactory.getLogger(Try_MouseUnits.class);
public static void main(String[] args) {
Try_MouseUnits app = new Try_MouseUnits();
app.setShowSettings(false);
app.start(); // start the game
}
@Override
public void simpleInitApp() {
flyCam.setEnabled(false);
setDisplayStatView(false);
setDisplayFps(false);
final BitmapText hudText = new BitmapText(guiFont, false);
hudText.setSize(guiFont.getCharSet().getRenderedSize()); // font size
hudText.setColor(ColorRGBA.Blue); // font color
hudText.setText(""); // the text
hudText.setLocalTranslation(300, hudText.getLineHeight(), 0); // position
guiNode.attachChild(hudText);
inputManager.addMapping("RotateX", new MouseAxisTrigger(MouseInput.AXIS_X, true));
inputManager.addMapping("RotateX_negative", new MouseAxisTrigger(MouseInput.AXIS_X, false));
/*
inputManager.addMapping("RotateY", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
inputManager.addMapping("RotateY_negative", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
*/
AnalogListener analogListener = new AnalogListener() {
float total = 0;
@Override
public void onAnalog(String name, float value, float tpf) {
if ("RotateX".equals(name)) {
total += value;
} else if ("RotateX_negative".equals(name)) {
total -= value;
}
hudText.setText(String.format("total = %f; x = %f", total, inputManager.getCursorPosition().x));
}
};
inputManager.addListener(analogListener, "RotateX", "RotateX_negative", "RotateY", "RotateY_negative");
}
}
[/java]
When experimenting with rotating a sphere, I noticed, that if speed is set to 10, then rotation was occurring visually exactly as if I was dragging the surface by the mouse. Since initial setup contains camera at a distance of 10 from origin, then the units are probably radians relative to origin, but I see no confirmation for this yet.