下面的应用程序显示,inputManager.getCursorPosition()
返回的鼠标X坐标可能是像素。
同时,来自value
的累积analogListener
不是以像素为单位测量的,而是从0
到0.6
不等。
它的单位是什么?是否可以获得相同单位的鼠标坐标(没有显示手动累积)?
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");
}
}