I have an application that draws a group of bars in one of three
orientations; along the x-axis(horizontally), along the
y-axis(vertically) and both the x and y axis(diagonally).
Interactively, I allow the user to switch the bar group between these
orientations while keeping all bars within a unit cube volume.  While
switching between these orientations, I need to retain the height(z) of
the bars.  To do so, I retrieve the scale component of the bargroup's
transform and only reset the x and y.  The problem is that after a few
of these operations, the getScale(Vector3d) does not return the correct
scale values.  In fact, looking closely at the transform's matrix and
the resulting scale vector, it appears that an index problem is occuring
inside the getScale(Vector3d) operation.

Below is a snippet of code and data output that shows the problem.


  private Transform3D t3d_ = new Transform3D();
  private int numBars_ = 3;

  public void setBarAlignment (int alignment)
  {
    alignment_ = alignment;
    double mat[] = new double[16];
    Vector3d scale = new Vector3d();

    for (int i=0; i<numBars_; i++)
    {
      Bar bar = (Bar)bars_.elementAt(i);
      bar.getTransform(t3d_);
      t3d_.get(mat);
//      double height = mat[(2*4)+2];
      t3d_.getScale(scale);
 if (i==0)
 {
 System.out.println("BarGroup -> "+getUserData());
 System.out.println("Before");
 System.out.println(t3d_);

 System.out.println("Scale gotten = "+scale);
 }
      if (alignment_ == HORIZONTAL)
      {
        t3d_.setTranslation(new Vector3d((double)i/(double)numBars_,
0.0, 0.0));
        scale.x = 1.0/(double)numBars_;
        scale.y = 1.0;
//        scale.z = height;

        t3d_.setScale(scale);

 // !HACK - Translate correctly
 //       mat[3] = (double)i/numBars_;
 //       mat[(1*4)+3] = 0.0;
 //       mat[(2*4)+3] = 0.0;

 // !HACK - Scale correctly
 //       mat[0] = 1.0/numBars_;
 //       mat[(1*4)+1] = 1.0;
      }
      else if (alignment_ == DIAGONAL)
      {
        t3d_.setTranslation(new Vector3d((double)i/(double)numBars_,
((double)(numBars_-i-1.0))/(double)numBars_, 0.0));
        scale.x = 1.0/(double)numBars_;
        scale.y = 1.0/(double)numBars_;
 //       scale.z = height;

        t3d_.setScale(scale);

 // !HACK - Translate correctly
 //       mat[3] = (double)i/numBars_;
 //       mat[(1*4)+3] = ((double)(numBars_-i-1.0))/(double)numBars_;
 //      mat[(2*4)+3] = 0.0;

 // !HACK - Scale correctly
 //       mat[0] = 1.0/numBars_;
 //       mat[(1*4)+1] = 1.0/numBars_;
      }
      else // (alignment_ == VERTICAL)
      {
        t3d_.setTranslation(new Vector3d(0.0,
(double)i/(double)numBars_, 0.0));
        scale.x = 1.0;
        scale.y = 1.0/(double)numBars_;
 //       scale.z = height;

        t3d_.setScale(scale);

 // !HACK - Translate correctly
 //       mat[3] = 0.0;
 //       mat[(1*4)+3] = (double)i/numBars_;
 //       mat[(2*4)+3] = 0.0;

 // !HACK - Scale correctly
 //       mat[0] = 1.0;
 //       mat[(1*4)+1] = 1.0/numBars_;
      }

 //     t3d_.set(mat);
 if (i==0)
 {
        System.out.println("Scale applied : "+scale);
        System.out.println("After");
        System.out.println(t3d_);
 }


      bar.setTransform(t3d_);
  }


Data output:

// ***** Switching to HORIZONTAL *****
BarGroup -> com.i2.ui.j3d.Vector3i->[0,0,0]
Before
1.0, 0.0, 0.0, 0.0
0.0, 0.3333333333333333, 0.0, 0.0
0.0, 0.0, 0.34166126614974257, 0.0
0.0, 0.0, 0.0, 1.0

Scale gotten = (1.0, 0.3333333333333333, 0.34166126614974257)
Scale applied : (0.3333333333333333, 1.0, 0.34166126614974257)
After
0.3333333333333333, 0.0, 0.0, 0.0
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 0.34166126614974257, 0.0
0.0, 0.0, 0.0, 1.0


// ***** Switching to VERTICAL *****
BarGroup -> com.i2.ui.j3d.Vector3i->[0,0,0]
Before
0.3333333333333333, 0.0, 0.0, 0.0
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 0.34166126614974257, 0.0
0.0, 0.0, 0.0, 1.0

Scale gotten = (0.34166126614974257, 0.3333333333333333, 1.0)
Scale applied : (1.0, 0.3333333333333333, 1.0)
After
0.0, 0.3333333333333333, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
1.0, 0.0, 0.0, 0.0
0.0, 0.0, 0.0, 1.0


When switching to horizontal, the scaling is done properly.  But when I
switch back to vertical, the getScale(Vector3d) returns the wrong set of
values which screws up all of the transform operations done after that.
Is this a bug that anyone else has run across?  Is this currently being
addressed?  It would be great if there was some way to look at the
Transform3D source code to try and figure out what is going on.  As a
hack, I would also like the ability to override the getScale(Vector3d)
method but can't since it is declared final.

Weylin

BTW, this problem is in both Java3d 1.1 and the newest release, Java3d
1.1.1.
begin:vcard 
adr;dom:;;;Dallas;TX;75234;
n:Debetaz;Weylin
x-mozilla-html:FALSE
org:i2 Technologies
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
tel;fax:(214) 860-6067
tel;work:(214) 515-3789
x-mozilla-cpt:;0
fn:Weylin Debetaz
end:vcard

Reply via email to