[Bf-committers] Help with Matrix problem

Alexander Ewering blender at instinctive.de
Fri Dec 10 12:34:41 CET 2004


Hello,

could someone (Martin?) possibly take a look at this matrix problem?

I'm working on my object grouping feature, and I have a problem drawing the
group's boundbox.

I managed to make a generic function that can deliver an overall boundbox
for any amount of arbitrary object types. This boundbox is drawn correctly
also if I translate or scale the Group object (to whose coordinate space
the boundbox belongs).

However, if i *rotate* it, the boundbox slowly collapses in one axis until
reaching 45 degrees, then expands again until it is right again at 90 degrees, etc.

Screenies:

http://pub.intrr.org/matrix.png

I'm transforming the boundbox into the object's space (I imagine) before drawing
it, by multiplying the coordinates by its inverse matrix.

However, it's all a bit of guesswork, as I don't know in what coordinate space
any of the stuff is :)

Can anyone imagine what the problem is?

Relevant code:

void drawgroup(Object *ob)
{
     Base *base;
     float min[3], max[3];
     BoundBox _bb;
     BoundBox *bb= &_bb;
     float imat[4][4], cmat[4][4];

     INIT_MINMAX(min, max);

     for (base= G.scene->base.first; base; base= base->next) {
         if (base->object->parent == ob) {
             minmax_object(base->object, min, max);
         }
     }
     Mat4Invert(imat, ob->obmat);
     Mat4MulVecfl(imat, min);
     Mat4MulVecfl(imat, max);
     VecMulf(min, 1.02);
     VecMulf(max, 1.02);

     bb->vec[0][0]=bb->vec[1][0]=bb->vec[2][0]=bb->vec[3][0]= min[0];
     bb->vec[4][0]=bb->vec[5][0]=bb->vec[6][0]=bb->vec[7][0]= max[0];

     bb->vec[0][1]=bb->vec[1][1]=bb->vec[4][1]=bb->vec[5][1]= min[1];
     bb->vec[2][1]=bb->vec[3][1]=bb->vec[6][1]=bb->vec[7][1]= max[1];

     bb->vec[0][2]=bb->vec[3][2]=bb->vec[4][2]=bb->vec[7][2]= min[2];
     bb->vec[1][2]=bb->vec[2][2]=bb->vec[5][2]=bb->vec[6][2]= max[2];

     draw_bb_box(bb);
}

Thanks!

| alexander ewering              instinctive mediaworks
| ae[@]instinctive[.]de   http://www[.]instinctive[.]de


More information about the Bf-committers mailing list