OSDN Git Service

Set optimal mime types and executable settings.
[mikumikustudio/MikuMikuStudio.git] / src / com / jme / input / action / KeyForwardAction.java
1 /*
2  * Copyright (c) 2003-2009 jMonkeyEngine
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 
17  *   may be used to endorse or promote products derived from this software 
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 package com.jme.input.action;
34
35 import com.jme.math.Vector3f;
36 import com.jme.renderer.Camera;
37
38 /**
39  * <code>KeyForwardAction</code> provides the action of moving a camera along
40  * it's direction vector. How fast the camera moves in a single frame is defined
41  * by the speed of the camera times the time between frames. The speed of the
42  * camera can be thought of as how many units per second the camera can travel.
43  * 
44  * @author Mark Powell
45  * @version $Id: KeyForwardAction.java,v 1.14 2006/11/03 09:18:54 irrisor Exp $
46  */
47 public class KeyForwardAction extends KeyInputAction {
48
49     //temp holder for the multiplication of the direction and time
50     private static final Vector3f tempVa = new Vector3f();
51     //the camera to manipulate
52     private Camera camera;
53
54     /**
55      * Constructor instantiates a new <code>KeyForwardAction</code> object.
56      * 
57      * @param camera
58      *            the camera that will be affected by this action.
59      * @param speed
60      *            the speed at which the camera can move.
61      */
62     public KeyForwardAction(Camera camera, float speed) {
63         this.camera = camera;
64         this.speed = speed;
65     }
66
67     /**
68      * <code>performAction</code> moves the camera along it's positive
69      * direction vector at a speed of movement speed * time. Where time is the
70      * time between frames and 1 corresponds to 1 second.
71      * 
72      * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
73      */
74     public void performAction(InputActionEvent evt) {
75         Vector3f loc = camera.getLocation();
76         if ( !camera.isParallelProjection() ) {
77             loc.addLocal(camera.getDirection().mult(speed * evt.getTime(), tempVa));
78         } else {
79             // move up instead of forward if in parallel mode
80             loc.addLocal(camera.getUp().mult(speed * evt.getTime(), tempVa));
81         }
82         camera.update();
83     }
84 }