gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Boxtest x,y,z ?? (Solved, a bug in libnds?!!!)

#131121 - a128 - Mon Jun 11, 2007 10:22 am

I have a question about the parameters for BoxTest (x,y,z,.....)

could it be that x,y,z is just the center of the box?

and that width and height and depth

is somethink like width= (abs(xmin)+abs(xmax) ) / 2?

The boxtest example in libnds just calculates boxtest using boxtest(xmin,ymin,zmin.....) but do not use it for culling tests.

I just ask because it's common for culling boxtests that you define the Center and the Size from that center point.


Last edited by a128 on Mon Jun 18, 2007 8:05 am; edited 1 time in total

#131206 - a128 - Tue Jun 12, 2007 7:47 am

a128 wrote:


could it be that x,y,z is just the center of the box?


of course it must be positionX,positionY,positionZ

so Width = Size/2

I will test that

#131216 - a128 - Tue Jun 12, 2007 1:48 pm

I calculate the Boxtest parameters
Code:



x=MinX+PositionX
y=....
z=....
 
width=ABS(minX)+ABS(maxX)
height=ABS(minY)+ABS(maxY)
depth= same for Z
   


it seems to work fine (NOTE: days later it turns out that this does not wokr at all)

x,y,z are the position of the cube in view coords...but relative to the minima of the bounding box


Last edited by a128 on Fri Jun 15, 2007 1:18 pm; edited 1 time in total

#131231 - memoni - Tue Jun 12, 2007 7:43 pm

I think your width calculation is not right. Try this instead:

Code:
width = maxX - minX;


I wonder how you got that abs there. If you want half width, then divide by 2 :)

#131267 - a128 - Wed Jun 13, 2007 10:56 am

memoni wrote:
I think your width calculation is not right. Try this instead:

Code:
width = maxX - minX;


I wonder how you got that abs there. If you want half width, then divide by 2 :)


oh yes sure thats correct

my brain is dead :-)

#131425 - a128 - Fri Jun 15, 2007 1:18 pm

this Boxtest(x,y,z,width,height,depth) method drives me insane

does anyone used this for culling?

#131633 - a128 - Mon Jun 18, 2007 8:05 am

I guess now I have a working BoxTest

1) There is a bug in libnds

Code:

//---------------------------------------------------------------------------------
int BoxTest(v16 x, v16 y, v16 z, v16 height, v16 width, v16 depth)
//---------------------------------------------------------------------------------
{
  glPolyFmt(BIT(12) | BIT(13));
  glBegin(GL_TRIANGLES);
  glEnd();

  GFX_BOX_TEST = VERTEX_PACK(x, y);
  GFX_BOX_TEST = VERTEX_PACK(z, height);
  GFX_BOX_TEST = VERTEX_PACK(width, depth);

  while(GFX_STATUS & BIT(0));

  return (GFX_STATUS & BIT(1));
}



should be regarding

http://nocash.emubase.de/gbatek.htm#ds3dtests

Code:

//---------------------------------------------------------------------------------
int BoxTest(v16 x, v16 y, v16 z, v16 width, v16 height, v16 depth) //CHANGED
//---------------------------------------------------------------------------------
{
  glPolyFmt(BIT(12) | BIT(13));
  glBegin(GL_TRIANGLES);
  glEnd();

  GFX_BOX_TEST = VERTEX_PACK(x, y);
  GFX_BOX_TEST = VERTEX_PACK(z, width); //CHANGED
  GFX_BOX_TEST = VERTEX_PACK(height, depth); //CHANGED

  while(GFX_STATUS & BIT(0));

  return (GFX_STATUS & BIT(1));
}


This seems to work fine.

---------
2) My models was scaled so they fit -7.99f.....7.99ff which is fine for that v16 fixpoint type

Since width,height,depht is also a v16 type this parameters must not exceed 7.99 either.....so I scaled my model to 7.99f*0.5 so width,height,deepth is max. 7.99ff

now the boxtest works fine

#131641 - a128 - Mon Jun 18, 2007 3:56 pm

This is how I do the BoxTest ..even with modles bigger then +-7.99f


1) Calc the min,max from the verticies
2) Calc the scale and scale the model so the max vert is 7.99f/2
and the max. size is 7.99f (important for BoxTest)

Code:
 static const float BASE = 7.99f/2.0f;
        // Set vertices to [(-BASE,-BASE,-BASE);(BASE,BASE,BASE)]
       

       float scalex = (ABS(maxX) > ABS(minX)) ? ABS(maxX) : ABS(minX) ;

    float scaley = (ABS(maxY) > ABS(minY)) ? ABS(maxY) : ABS(minY) ;

    float scalez = (ABS(maxZ) > ABS(minZ)) ? ABS(maxZ) : ABS(minZ) ;


        float sc = MAX(MAX(scalex, scaley), scalez) / BASE;

        scale[nr]=sc;

   v = ob->vertices;

        for ( i = 0; i < ob->num_vert; i++, v++) {

            float x = v->x;
            float y = v->y;
            float z = v->z;

            v->x = (x) / sc;
            v->y = (y) / sc;
            v->z = (z) / sc;

        }
       



while Rendering I do

glTranslate(position of the model in world coords)
glScale(scale)

x=minX/scale
y=minY/scale
z=minZ/scale

width=(maxX-minX)/scale
height=(maxY-minY)/scale
depth=(maxZ-minZ)/scale

//These paramters does not exceed 7.99f!!!!!!!
if(BoxTest(x,y,z,width,height,depth)){

draw the model

}


Last edited by a128 on Tue Jul 03, 2007 8:25 am; edited 2 times in total

#131656 - gabebear - Mon Jun 18, 2007 9:42 pm

Cool, I'll add this to the list of stuff to fix. It's nice when it's an easy fix like this.

I started a new job and haven't had time for much else... sorry for the lack of progress on bugs lately.

#131953 - wintermute - Thu Jun 21, 2007 4:03 pm

I can throw this one into CVS if you don't have the time to deal with it atm.

I'm hoping to roll another stable libnds fairly soon when I finalise devkitARM r21 so I'd like to make sure everything works as it should.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#134282 - a128 - Thu Jul 12, 2007 8:12 am

this is still broken in libnds?!