KeyUpAction / KeyDownAction and camera handler

For a game I'm working on I'll need a freely moveable camera, a bit like the one possible with FirstPersonHandler:

With the middle mouse button (or scroll wheel) pressed, you can do mouse looking.

With the right mouse pressed, you can move left/right/up/down.

Using the mouse wheel, you can scroll in/out.



Within this handler, I'll need KeyUpAction and KeyDownAction, much like KeyStrafeLeftAction.



I feel that KeyUpAction and KeyDownAction (or KeyStrafeUpAction and KeyStrafeDownAction, if you like) are missing for completeness.



What do you think?

If needed, I'll post the code here so it can be checked in.

I second the sentiment.

Sounds useful

Alright, I just copied KeyStrafeLeftAction and KeyStrafeRightAction and modified them to use the other axis.



I don't mind if I don't show up as the author, and someone should maybe sort out the version - I wasn't sure wether to start at 1.00 or count up from 1.10. :wink:



The Handler will be here within the next few days. Any suggestions for the class name?



KeyStrafeUpAction.java:

/*
 * Copyright (c) 2003-2004, jMonkeyEngine - Mojo Monkey Coding
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *


 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
 * names of its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
package com.jme.input.action;

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

/**
 * <code>KeyStrafeUpAction</code> defines an action that causes the camera
 * to move along the positive up vector. The speed at which it moves is set
 * and of the form units per second.
 *
 * @author Mark Powell
 * @version $Id: KeyStrafeUpAction.java,v 1.10 2004/10/14 01:22:57 mojomonkey Exp $
 */
public class KeyStrafeUpAction extends KeyInputAction {
    //the camera to manipulate
    private Camera camera;
    //temporary vector to store translation
    private static final Vector3f tempVa = new Vector3f();

    /**
     * Constructor instantiates a new <code>KeyStrafeUpAction</code> object.
     *
     * @param camera
     *            the camera to move along the up vector.
     * @param speed
     *            the speed at which to move the camera.
     */
    public KeyStrafeUpAction(Camera camera, float speed) {
        this.camera = camera;
        this.speed = speed;
    }

    /**
     * <code>performAction</code> moves the camera along the up vector for a
     * given distance of speed * time.
     *
     * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
     */
    public void performAction(InputActionEvent evt) {
        Vector3f loc = camera.getLocation();
        loc.addLocal(camera.getUp().mult(speed * evt.getTime(), tempVa));
        camera.setLocation(loc);
        camera.update();
    }
}



KeyStrafeDownAction.java:

/*
 * Copydown (c) 2003-2004, jMonkeyEngine - Mojo Monkey Coding
 * All downs reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copydown notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copydown notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the
 * names of its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
package com.jme.input.action;

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

/**
 * <code>KeyStrafeUpAction</code> defines an action that causes the camera
 * to move along the negative up vector. The speed at which it moves is set
 * and of the form units per second.
 *
 * @author Mark Powell
 * @version $Id: KeyStrafeDownAction.java,v 1.10 2004/10/14 01:22:58 mojomonkey Exp $
 */
public class KeyStrafeDownAction extends KeyInputAction {
    //the camera to manipulate
    private Camera camera;
    //temporary vector to hold the translation
    private static final Vector3f tempVa = new Vector3f();

    /**
     * Constructor instantiates a new <code>KeyStrafeUpAction</code> object.
     *
     * @param camera
     *            the camera to move along the negative up vector.
     * @param speed
     *            the speed at which to move the camera.
     */
    public KeyStrafeDownAction(Camera camera, float speed) {
        this.camera = camera;
        this.speed = speed;
    }

    /**
     * <code>performAction</code> moves the camera along the negative up
     * vector for a given distance of speed * time.
     *
     * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
     */
    public void performAction(InputActionEvent evt) {
        Vector3f loc = camera.getLocation();
        loc.subtractLocal(camera.getUp().mult(speed * evt.getTime(), tempVa));
        camera.setLocation(loc);
        camera.update();
    }
}



Cheers

Personally I feel the actions are good enough.  People can use those to make their own handlers.

I basically made my own after browsing yours (copy paste edit locally was simpler than copying from the forum, heheā€¦)  Should be in CVS shortly.  Could you have a look over it to verify correctness?

Nodwick said:

If there's a way to access the CVS through HTTP or FTP...

For viewing you can use https://jme.dev.java.net/source/browse/jme/ .

Thanks for the link :slight_smile:



I've just done a test run with the code, and it works fine.

renanse said:

I basically made my own after browsing yours (copy paste edit locally was simpler than copying from the forum, hehe...)  Should be in CVS shortly.  Could you have a look over it to verify correctness?

I haven't yet bothered to access the CVS... but I'll look into that :)

EDIT:
I just tried, and it seems that the local firewall doesn't let me through and the proxy doesn't support (or just blocks) the CVS access.
If there's a way to access the CVS through HTTP or FTP, I'll look at it, otherwise I'll just have to wait for it to be put into the next release.
Nodwick said:

If there's a way to access the CVS through HTTP or FTP, I'll look at it, otherwise I'll just have to wait for it to be put into the next release.


http://cvsgrab.sourceforge.net/