FirstPersonHandler setting mouse/camera constraints

I'm setting up a small game for my programming class, and am implementing the FirstPersonHandler to make things easier. My problem is that when looking up and down you can go all the way around, going upside down. I want to constrain this so that it stops once you are looking straight up or straight down.  I've tried looking through the wiki or searching for how to fix it, but can't find anything. Any help is appreciated.



Austin

I changed KeyLookUpAction and KeyLookDownAction to prevent the turnover:



package com.jme.input.action;

import com.jme.math.Matrix3f;
import com.jme.renderer.Camera;

/**
 * <code>KeyLookUpAction</code> tilts a camera up a given angle. This angle
 * should be represented as a radian.
 *
 * @author Mark Powell
 * @edited by Christian Teister
 * @version $Id: KeyLookUpAction.java,v 1.15 2009/02/20 21:30:10 nca Exp $
 */
public class KeyLookUpAction extends KeyInputAction {
    //the rotation matrix
    private static final Matrix3f incr = new Matrix3f();
    //the camera to manipulate
    private Camera camera;

    /**
     * Constructor instantiates a new <code>KeyLookUpAction</code> object.
     *
     * @param camera
     *            the camera to tilt.
     * @param speed
     *            the speed at which the camera tilts.
     */
    public KeyLookUpAction(Camera camera, float speed) {
        this.camera = camera;
        this.speed = speed;
    }

    /**
     * <code>performAction</code> adjusts the view of the camera to tilt up a
     * given angle. This angle is determined by the camera's speed and the time
     * which has passed.
     *
     * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
     */   
    public void performAction(InputActionEvent evt) {
       incr.fromAngleNormalAxis(-speed * evt.getTime(), camera.getLeft());
        incr.mult(camera.getLeft(), camera.getLeft());
        incr.mult(camera.getDirection(), camera.getDirection());
        incr.mult(camera.getUp(), camera.getUp());
        camera.normalize();
       
        if(camera.getUp().y < 0) {
           incr.fromAngleNormalAxis(speed * evt.getTime(), camera.getLeft());
            incr.mult(camera.getLeft(), camera.getLeft());
            incr.mult(camera.getDirection(), camera.getDirection());
            incr.mult(camera.getUp(), camera.getUp());
            camera.normalize();
        }
          
       camera.update();
       
    }
}




package com.jme.input.action;

import com.jme.math.Matrix3f;
import com.jme.renderer.Camera;

/**
 * <code>KeyLookDownAction</code> tilts a camera down a given angle. This
 * angle should be represented as a radian.
 *
 * @author Mark Powell
 * @edited by Christian Teister
 * @version $Id: KeyLookUpAction.java,v 1.15 2009/02/20 21:30:10 nca Exp $
 */
public class KeyLookDownAction extends KeyInputAction {
    //maintains the rotation matrix
    private static final Matrix3f incr = new Matrix3f();
    //the camera to manipulate
    private Camera camera;

    /**
     * Constructor instantiates a new <code>KeyLookDownAction</code> object.
     *
     * @param camera
     *            the camera to tilt.
     * @param speed
     *            the speed at which the camera tilts.
     */
    public KeyLookDownAction(Camera camera, float speed) {
        this.camera = camera;
        this.speed = speed;
    }

    /**
     * <code>performAction</code> adjusts the view of the camera to tilt down
     * a given angle. This angle is determined by the camera's speed and the
     * time which has passed.
     *
     * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
     */
    public void performAction(InputActionEvent evt) {
       incr.fromAngleNormalAxis(speed * evt.getTime(), camera.getLeft());
       incr.mult(camera.getLeft(), camera.getLeft());
       incr.mult(camera.getDirection(), camera.getDirection());
       incr.mult(camera.getUp(), camera.getUp());
       camera.normalize();
      
       if(camera.getUp().y < 0) {
          incr.fromAngleNormalAxis(-speed * evt.getTime(), camera.getLeft());
          incr.mult(camera.getLeft(), camera.getLeft());
          incr.mult(camera.getDirection(), camera.getDirection());
          incr.mult(camera.getUp(), camera.getUp());
          camera.normalize();
       }
      
       camera.update();
    }
}




Perhaps someone wants to add this with a flag to the original class.

Thank you!



Austin

Sorry if there is some rule about bringing up old threads but I’m trying to implement this same characteristic and am having trouble with where to begin? I don’t see these files within the jME3 jars. Is this implemented somewhere by default now?

This thread was concentrating on jME2, I would create a new thread with the problem you’re having and make sure to specify that you’re using jME3 :slight_smile: