View Javadoc
1 /***************************************************************************** 2 * Virtual Mockup for Machine Vision 3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr., 4 * Carlos S. Santos. 5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP 6 * 7 * Permission is granted to redistribute and/or modify this 8 * software under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This software is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html) 16 * for more details. 17 * 18 *****************************************************************************/ 19 20 package camera3d.manipulation; 21 22 import javax.media.j3d.Transform3D; 23 import javax.media.j3d.TransformGroup; 24 import javax.vecmath.*; 25 import camera3d.MathUtility; 26 import camera3d.TransformScope; 27 28 /*** 29 * 30 * @author Carlos da Silva dos Santos, Fábio Roberto de Miranda 31 * @version 23/05/2003 32 */ 33 class RotTGAdapter implements RotatableObject{ 34 35 private TransformGroup rotTG; 36 37 private Transform3D transform3D = new Transform3D(); 38 private Transform3D tempT3D = new Transform3D(); 39 40 /*** Holds the total transformation, given by: 41 * (TransformGroup localToVworld transform)*(TransformGroup internal transform) */ 42 private Transform3D totalT3D = new Transform3D(); 43 44 /*** Holds the TransformGroup localToVworld transform. */ 45 private Transform3D tgLocalToVworld = new Transform3D(); 46 47 /*** Quaternion which will hold incremental rotation. */ 48 private Quat4d rotQuat = new Quat4d(); 49 50 /*** Quaternion which will hold rotation already present in the TransformGroup. */ 51 private Quat4d baseQuat = new Quat4d(); 52 53 54 RotTGAdapter(){ 55 } 56 57 58 RotTGAdapter(TransformGroup rotTG){ 59 this(); 60 this.rotTG = rotTG; 61 } 62 63 void setTransformGroup(TransformGroup tg){ 64 this.rotTG = tg; 65 } 66 67 public boolean isLive(){ 68 if(this.rotTG==null) return false; 69 else return rotTG.isLive(); 70 } 71 72 /*** 73 * @param axis axis affected by rotation. 74 * @param deltaAngle 75 */ 76 public void rotateLocal(TransformScope axis, double deltaAngle){ 77 MathUtility.generateRotQuat(axis,deltaAngle,rotQuat); 78 rotTG.getTransform(tempT3D); 79 tempT3D.get(baseQuat); 80 // baseQuat = rotQuat*baseQuat 81 //baseQuat.mul(rotQuat, baseQuat); 82 83 //baseQuat = baseQuat*rotQuat; 84 baseQuat.mul(rotQuat); 85 baseQuat.normalize(); 86 87 tempT3D.setRotation(baseQuat); 88 rotTG.setTransform(tempT3D); 89 } 90 91 /*** 92 * Performs incremental rotation around one of the absolute axis. It is suitable 93 * to be called by manipulators, in order to perform absolute rotation.<br> 94 * Method from RotatableObject interface. 95 * @param axis the axis around which the rotation will be performed. 96 * @param deltaAngle of the increment (in degrees). 97 */ 98 public void rotateAbsolute(TransformScope axis, double deltaAngle){ 99 //System.out.println("rot abs"); 100 MathUtility.generateRotQuat(axis,deltaAngle,rotQuat); 101 102 getLocalToVworld(totalT3D); 103 totalT3D.get(baseQuat); 104 // baseQuat = baseQuat*rotQuat 105 // baseQuat.mul(rotQuat); 106 107 // baseQuat = rotQuat*baseQuat 108 baseQuat.mul(rotQuat, baseQuat); 109 110 baseQuat.normalize(); 111 112 totalT3D.setRotation(baseQuat); 113 114 // puts inverse of tgLocalToVworld in tempT3D 115 tempT3D.invert(tgLocalToVworld); 116 // transform3D receives (tgLocalToVworld^-1)*totalT3D 117 transform3D.mul(tempT3D,totalT3D); 118 rotTG.setTransform(transform3D); 119 } 120 121 public void getLocalToVworld(Transform3D localToVworld){ 122 rotTG.getLocalToVworld(tgLocalToVworld); 123 rotTG.getTransform(tempT3D); 124 tempT3D.mul(tgLocalToVworld,tempT3D); 125 localToVworld.set(tempT3D); 126 } 127 128 }

This page was automatically generated by Maven