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 ScaleTGAdapter implements ScalableObject{
34  
35      private TransformGroup scaleTG;
36  
37      private Transform3D auxT3D = new Transform3D();
38      private Transform3D tempT3D = new Transform3D();
39      private Vector3d tempVec3d = new Vector3d();
40  
41      ScaleTGAdapter(){
42  
43      }
44  
45  
46      ScaleTGAdapter(TransformGroup scaleTG){
47         this();
48         this.scaleTG = scaleTG;
49      }
50  
51      void setTransformGroup(TransformGroup tg){
52         this.scaleTG = tg;
53      }
54  
55      public boolean isLive(){
56         if(this.scaleTG==null) return false;
57         else return scaleTG.isLive();
58      }
59  
60     /***
61      *
62      */
63     public void scaleRelative(TransformScope scope, double scale){
64        if(scope==TransformScope.X) setRelativeScale(scale,1,1);
65        if(scope==TransformScope.Y) setRelativeScale(1,scale,1);
66        if(scope==TransformScope.Z) setRelativeScale(1,1,scale);
67        if(scope==TransformScope.XYZ) setRelativeScale(scale,scale,scale);
68     }
69  
70     private void setRelativeScale(double x, double y, double z){
71        scaleTG.getTransform(auxT3D);
72  
73        /* Places relative scale in tempT3D */
74        tempT3D.setIdentity();
75        tempVec3d.x = x;
76        tempVec3d.y = y;
77        tempVec3d.z = z;
78        tempT3D.setScale(tempVec3d);
79        /* Multiplies former and temporary transformations */
80        auxT3D.mul(tempT3D);
81  
82        scaleTG.setTransform(auxT3D);
83     }
84  
85  }
This page was automatically generated by Maven