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  
26  /***
27   *
28   * @author  Carlos da Silva dos Santos, Fábio Roberto de Miranda
29   * @version 23/05/2003
30   */
31  class TransTGAdapter implements TranslatableObject{
32  
33      private TransformGroup transTG;
34      private Transform3D transform3D = new Transform3D();
35      private Transform3D tempT3D = new Transform3D();
36  
37      /*** Holds the TransformGroup localToVworld transform. */
38      private Transform3D tgLocalToVworld = 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      TransTGAdapter(){
45  
46      }
47  
48      TransTGAdapter(TransformGroup transTG){
49         this();
50         this.transTG = transTG;
51      }
52  
53      void setTransformGroup(TransformGroup tg){
54         this.transTG = tg;
55      }
56  
57      public boolean isLive(){
58         if(this.transTG==null) return false;
59         else return transTG.isLive();
60      }
61  
62      public void translate(Vector3d translation){
63          /* this method works as follows:
64             The new value of the total transformation is calculated.
65             The total transformation is given by:
66               totalT3D = tgLocalToVworld*transform3D
67             Therefore:
68               transform3D = (tgLocalToVworld^-1)*totalT3D
69           */
70          // puts total transformation in totalT3D
71          getLocalToVworld(totalT3D);
72          // sets new translation, leaving rotation and scale
73          // intact
74          totalT3D.setTranslation(translation);
75          // puts inverse of tgLocalToVworld in tempT3D
76          tempT3D.invert(tgLocalToVworld);
77          // transform3D receives (tgLocalToVworld^-1)*totalT3D
78          transform3D.mul(tempT3D,totalT3D);
79          transTG.setTransform(transform3D);
80      }
81  
82      public void getLocalToVworld(Transform3D localToVworld){
83          transTG.getLocalToVworld(tgLocalToVworld);
84          transTG.getTransform(tempT3D);
85          tempT3D.mul(tgLocalToVworld,tempT3D);
86          localToVworld.set(tempT3D);
87      }
88  
89  }
This page was automatically generated by Maven