[ SOLVED ] Mouse Motion (Mouse sensitivity)

hello everyone…



I am using BaseGame class…i want to implement mouse motion events as it does work in SimpleGame class…

like if i move my mouse left, cam rotates left…key events are no problem but facing problem only with motion events of mouse…



i checked flagrush tutorials and others in wiki…but they didn't quite get into my head :wink:

Is there any code related to this in jmetest package(i couldn't find any) …need help(in details)…i want to clear my concept regarding this…

input = new FirstPersonHandler(cam,100,100)

ok i gone through javadoc about FirdtPersonHandler…it behaves as it does in general fps games…



now i want to ask is " do i have to attach input to rootNode ?" but i don't think its a spatial…



i called input=new FirstPersonHandler at initSystem() method…so now how do i use this input  ;)…

inputhandlers dont need to be attached, but they need to be updated in the games update cycle.

input.update(tpf);

thanks…

its working but movement is very fast…

initially i did "mouseInput=new FirstPersonHandler(cam,100,100);" which moves the camera very fast…then i did with 50,50 which still is fast…i experimented with many values but still motion of camera is very fast…



protected void update(float interpolation) {
        // update the time to get the framerate
   timer.update();
   interpolation = timer.getTimePerFrame();
        mouseInput.update(interpolation);
   // if escape was pressed, we exit
   if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
      finished = true;
   }
    }



any help............

hello everyone…i am not having problem with "w,a,s,d" key movements of camera…when i move my mouse then camera moves so fast that i am not able to adjust my objects rendered in the scene…my problem is regarding mouse sensitivity. How to decrease the mouse sensitivity ?..

i m trying a lot but till now success…



here is a code


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package proxywar.prototype;

import com.jme.app.BaseGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.FirstPersonHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.terrain.TerrainBlock;
import com.jmex.terrain.util.MidPointHeightMap;
import com.jmex.terrain.util.ProceduralTextureGenerator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;

/**
 *
 * @author Netbeans
 */
public class War extends BaseGame{

    private static final Logger logger = Logger.getLogger(War.class.getName());
    private FirstPersonHandler mouseInput;
    protected Timer timer;
   
    //our camera for viewing the scene
    private Camera cam;
   
    //our rootnode of scene graph
    private Node scene;
   
    // display attributes for the window. We will keep these values
    // to allow the user to change them
    private int width, height, depth, freq;
   
    private boolean fullscreen;
   
    private TerrainBlock tb;
   
    public static void main(String[] args)
    {
        War app=new War();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }
   
    @Override
    protected void update(float interpolation) {
        // update the time to get the framerate
   timer.update();
   interpolation = timer.getTimePerFrame();
        mouseInput.update(interpolation);
   // if escape was pressed, we exit
   if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit")) {
      finished = true;
   }
    }

    @Override
    protected void render(float interpolation) {
        // Clear the screen
   display.getRenderer().clearBuffers();

   display.getRenderer().draw(scene);
    }

    @Override
    protected void initSystem() {
        // store the settings information
   width = settings.getWidth();
   height = settings.getHeight();
   depth = settings.getDepth();
   freq = settings.getFrequency();
   fullscreen = settings.isFullscreen();
       
        try{
            display=DisplaySystem.getDisplaySystem(settings.getRenderer());
            display.createWindow(width, height, depth, freq, fullscreen);
           
            cam=display.getRenderer().createCamera(width, height);
        }
        catch(JmeException e)
        {
         logger.log(Level.SEVERE, "could not create displaySystem", e);   
         System.exit(1);
        }
       
        //set the background to black
        display.getRenderer().setBackgroundColor(ColorRGBA.black.clone());
       
        // initialize the camera
   cam.setFrustumPerspective(45.0f, (float) width / (float) height, 1,1000);
   Vector3f loc = new Vector3f(500.0f, 150.0f, 500.0f);
   Vector3f left = new Vector3f(1.0f, 0.0f, 0.0f);
   Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
   Vector3f dir = new Vector3f(0.0f, 0.0f, -1.0f);
       
        // Move our camera to a correct place and orientation.
   cam.setFrame(loc, left, up, dir);
   /** Signal that we've changed our camera's location/frustum. */
   cam.update();

   /** Get a high resolution timer for FPS updates. */
   timer = Timer.getTimer();
        mouseInput=new FirstPersonHandler(cam,50,50);
   display.getRenderer().setCamera(cam);
       
       
   KeyBindingManager.getKeyBindingManager().set("exit",KeyInput.KEY_ESCAPE);
    }

    @Override
    protected void initGame() {
       
         scene=new Node("scene graph node");
       
//        Box b= new Box("box",new Vector3f(-2,-2,0),new Vector3f(5,3,5));
//        b.setDefaultColor(ColorRGBA.red);
//       
//        scene.attachChild(b);
       
        buildTerrain();
        // update the scene graph for rendering
   scene.updateGeometricState(0.0f, true);
   scene.updateRenderState();
    }

    @Override
    protected void reinit() {
       
    }

    @Override
    protected void cleanup() {
       
    }

    @Override
    protected void quit() {
        super.quit();
        System.exit(0);
    }
   
    void buildTerrain()
    {
        MidPointHeightMap heightMap = new MidPointHeightMap(128, 8.9f);
   
    Vector3f terrainScale = new Vector3f(25,1,25);
   
    tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
                                       heightMap.getHeightMap(),
                                       new Vector3f(0, 0, 0));
    tb.setDetailTexture(1, 16);
    tb.setModelBound(new BoundingBox());
    tb.updateModelBound();
    tb.setLocalTranslation(new Vector3f(0,0,0));
    scene.attachChild(tb);
    //scene.setRenderState(cs);

    ProceduralTextureGenerator pt = new ProceduralTextureGenerator(
        heightMap);
    pt.addTexture(new ImageIcon(War.class.getClassLoader()
                                .getResource("jmetest/data/texture/grassb.png")),
                  -128, 0, 128);
    pt.addTexture(new ImageIcon(War.class.getClassLoader()
                                .getResource("jmetest/data/texture/dirt.jpg")),
                  0, 128, 255);
    pt.addTexture(new ImageIcon(War.class.getClassLoader()
                                .getResource("jmetest/data/texture/highest.jpg")),
                  128, 255,
                  384);

    pt.createTexture(64);

    TextureState ts = display.getRenderer().createTextureState();
    ts.setEnabled(true);
   
    Texture t1 = TextureManager.loadTexture(
        pt.getImageIcon().getImage(),
        Texture.MinificationFilter.Trilinear,
        Texture.MagnificationFilter.Bilinear, true);
    t1.setStoreTexture(true);
    ts.setTexture(t1, 0);

    Texture t2 = TextureManager.loadTexture(
        War.class.getClassLoader().getResource(
        "jmetest/data/texture/Detail.jpg"),
        Texture.MinificationFilter.Trilinear,
        Texture.MagnificationFilter.Bilinear);

    ts.setTexture(t2, 1);
    t2.setWrap(Texture.WrapMode.Repeat);

    t1.setApply(Texture.ApplyMode.Combine);
    t1.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
    t1.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
    t1.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    t1.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
    t1.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

    t2.setApply(Texture.ApplyMode.Combine);
    t2.setCombineFuncRGB(Texture.CombinerFunctionRGB.AddSigned);
    t2.setCombineSrc0RGB(Texture.CombinerSource.CurrentTexture);
    t2.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    t2.setCombineSrc1RGB(Texture.CombinerSource.Previous);
    t2.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
    scene.setRenderState(ts);

    scene.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
    }
   
}



any help...........
"JavaDoc" wrote:
com.jme.input.FirstPersonHandler.FirstPersonHandler(Camera cam, float moveSpeed, float turnSpeed)
Creates a first person handler.

Parameters:
cam The camera to move by this handler.
moveSpeed action speed for move actions
turnSpeed action speed for rotating actions

maybe try a smaller value for turnSpeed?

thanks…  :slight_smile: