3

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)?

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");

    }
}
Richard Tingle
  • 16,906
  • 5
  • 52
  • 77
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • I'm glad you asked this. I had exactly the same thought when answering your previous question. Seems pretty arbitrary – Richard Tingle May 17 '14 at 12:45
  • 1
    Playing around with different resolutions it seems to always be approximately the pixel position/1000. I have no idea *why* it would be that and its not precisely that value (although given the manual accumulation thats not too suprising) – Richard Tingle May 17 '14 at 12:56
  • When 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. – Suzan Cioc May 17 '14 at 20:25

0 Answers0