1 16 17 package com.buchuki.ensmer.input.command.navigation; 18 19 import com.buchuki.ensmer.input.Accelerator; 20 import com.buchuki.ensmer.input.event.EnsmerInputEvent; 21 import com.buchuki.ensmer.input.event.Measurable; 22 import javax.media.j3d.Transform3D; 23 import javax.vecmath.*; 24 25 29 public class RotateCommand extends TransformCommand { 30 31 43 public RotateCommand(Transformable3D transformable, Accelerator accel, 44 float accelMod, Axis axis) { 45 super(transformable, accel, accelMod); 46 this.axis = axis; 47 } 48 49 53 public boolean execute(EnsmerInputEvent event) { 54 float rotateAmount = getAcceleratedMagnitude((Measurable) event); 55 performRotation(rotateAmount); 56 return true; 57 } 58 59 63 public void undoRotation() { 64 performRotation(-1.0f * totalRotation); 65 } 66 67 75 protected void transformRotation(Matrix4f matrix) { 76 } 77 78 83 private void performRotation(float magnitude) { 84 totalRotation += magnitude; 85 Transform3D transform = new Transform3D(); 86 axis.rotate(transform, magnitude); 87 Matrix4f matrix = new Matrix4f(); 88 transform.get(matrix); 89 transformRotation(matrix); 90 updatePosition(matrix); 91 } 92 93 96 private Axis axis; 97 98 102 private float totalRotation; 103 104 108 public enum Axis { 109 X, 110 Y, 111 Z; 112 113 119 void rotate(Transform3D transform, float magnitude) { 120 switch(this) { 121 case X: 122 transform.rotX(magnitude); 123 break; 124 case Y: 125 transform.rotY(magnitude); 126 break; 127 case Z: 128 transform.rotZ(magnitude); 129 } 130 } 131 } 132 } 133 | Popular Tags |