NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: OOps, Re: Fixed text size query...

Hi Jim,

I've solved a similiar problem to yours, except for contour value
labels.  Here's my controlChanged() method with a few comments:

            .
            .
            .

   public void controlChanged(ControlEvent e)
   {
     matrix = proj.getMatrix();

     MouseBehaviorJ3D.unmake_matrix(rot_a, scale_a, trans_a, matrix);

     double factor = first_scale/scale_a[0];
     float f_scale = (float) ((scale_a[0] - first_scale)/scale_a[0]);
     trans.getTransform(t3d);

     Vector3f trans_vec
       new Vector3f(f_scale*vertex[3*closest_vert+0],
                    f_scale*vertex[3*closest_vert+1],
                    f_scale*vertex[3*closest_vert+2]);


     t3d.set((float)factor, trans_vec);
     trans.setTransform(t3d);
   }

 -----

I use a little matrix algebra, and a little experimentation, to 
compute the f_scale value, essentially I solve for translation
components required to place the label where I want it, at the 
desired scale.  It works very well, and under all combinations
of transformation although I can only prove it works for pure
scaling, and scaling with translation.  The closest_vert is sort
of the anchor point for the label.

Hope this helps,

TomR
        

Bill Hibbard wrote:
> 
> I wrote:
> 
> > 2. Since you know that:
> >
> >   Transform3D theTransform = new Transform3D();
> >   theTransform.set( 1 / aScale[ 0 ], theTranslationVector );
> >   theTransformGroup_.setTransform( theTransform );
> >
> > works for fixing the location and size, you might try:
> >
> >   Transform3D theTransform = new Transform3D();
> >   theTransform.set( 1 / aScale[ 0 ], theTranslationVector );
> >   Transform3D scale = new Transform3D();
> >   scale.set( 1 / aScale[ 0 ] );
> >   theTransform.mul(scale);
> >   theTransformGroup_.setTransform( theTransform );
> 
> Clearly this should not re-apply the scale, but apply the
> inverse of the translation in 'scale'. That is:
> 
>   Transform3D theTransform = new Transform3D();
>   theTransform.set( 1 / aScale[ 0 ], theTranslationVector );
>   Transform3D translate = new Transform3D();
>   Vector3d inverse = new Vector3d();
>   inverse.x = -theTranslationVector.x;
>   inverse.y = -theTranslationVector.y;
>   inverse.z = -theTranslationVector.z;
>   translate.set( inverse );
>   theTransform.mul(translate);
>   theTransformGroup_.setTransform( theTransform );
> 
> > I may have some detail wrong, like the order of multiplying
> > matrices, but with a few experiments you may get it. When I
> > write such transform matrix code, I always have to experiment
> > to get it right.
> 
> And of course, you can probably accomplish the same thing
> with your original code and experimenting with arithmetic
> operations on the x, y and z values in theTranslationVector.
> 
> Good luck,
> Bill
> ----------------------------------------------------------
> Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
> hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
> http://www.ssec.wisc.edu/~billh/vis.html


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: