KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > buchuki > ensmer > input > command > navigation > TransformCommand


1 /*
2  * Copyright 2004 Dusty Phillips
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package com.buchuki.ensmer.input.command.navigation;
18
19 import com.buchuki.ensmer.input.Accelerator;
20 import com.buchuki.ensmer.input.command.Command;
21 import com.buchuki.ensmer.input.event.Measurable;
22 import javax.vecmath.Matrix4f;
23
24 /**
25  * Abstract class encapsulating the few commonalities of the rotation and
26  * movement commands.
27  *
28  * @author Dusty Phillips [dusty@buchuki.com]
29  */

30 public abstract class TransformCommand implements Command {
31     
32     /**
33      * Creates a new instance of TransformCommand. Maintains a reference to the
34      * Transformable3D and the accelerator to manipulate the object
35      *
36      * @param transformable The transformable to forward the relative matrix movement to
37      * @param accel the Accelerator to dynamically modify the acceleration value
38      * @param accelmod An additional modifier to be applied to the accelerator. These are compiled in in current versions of Ensmer, but will eventually have to be configurable; this supports making it configurable in the future
39      */

40     public TransformCommand(Transformable3D transformable, Accelerator accel, float accelmod) {
41         this.transformable = transformable;
42         this.accelerator = accel;
43         this.accelmod = accelmod;
44     }
45     
46     /**
47      * Get the accelerated magnitude for the give input event
48      *
49      * @param event a MeasurableEvent containing a magnitude value that
50      * needs to be modified
51      */

52     public float getAcceleratedMagnitude(Measurable event) {
53         return event.getMagnitude() * accelerator.getAcceleration() * accelmod;
54     }
55     
56     /**
57      * Notify the Transformable that the position needs to be updated
58      *
59      * @param matrix a Matrix4f representing a relative change in position
60      */

61     protected void updatePosition(Matrix4f matrix) {
62         transformable.moveTransform(matrix);
63     }
64     
65     /**
66      * The accelerator to modify magnitude values by
67      */

68     private Accelerator accelerator;
69     
70     /**
71      * An additional acceleration modifier value to fine tune the default
72      * acceleration value on varying hardware
73      */

74     private float accelmod;
75     
76     /**
77      * The transformable to forward commands to
78      */

79     private Transformable3D transformable;
80     
81 }
82
Popular Tags