Inside3D!
     

Easy Bounding Box Fix

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
Stroggos



Joined: 14 Apr 2009
Posts: 43

PostPosted: Sat Oct 03, 2009 11:50 am    Post subject: Easy Bounding Box Fix Reply with quote

Easy Bounding Box Fix:
I found this by accident and it seemed to work. I'm really not sure how it works
so maybe someone could tell me.

There is only one change in one file throughout the whole tutorial. First find
R_CullBox(). It should look like this:
Code:

qboolean R_CullBox (vec3_t mins, vec3_t maxs)
{
   int      i;

   for (i=0 ; i<4 ; i++)
      if (BoxOnPlaneSide (mins, maxs, &frustum[i]) == 2)
         return true;
   return false;
}


Then change the line:
Code:

if (BoxOnPlaneSide (mins, maxs, &frustum[i]) == 2)

to
Code:

if (BoxOnPlaneSide (mins, maxs, &frustum[i]) == 5)


Compile and run. Goto the final map (end.bsp) and look up at the Shub-Niggurath.
_________________
Dont even try to port Quake 4 to the ipod
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Sat Oct 03, 2009 5:15 pm    Post subject: Reply with quote

And what is exactly fixed with this code snippet ? The fact that Shub's bound box does not fit to its model ?
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Sat Oct 03, 2009 5:45 pm    Post subject: Reply with quote

He is makeing it so it returns 5 and makes it always visible.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!


Last edited by Team Xlink on Sat Oct 03, 2009 8:47 pm; edited 1 time in total
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sat Oct 03, 2009 6:17 pm    Post subject: Reply with quote

It 'fixes' it by disabling culling entirely.

BoxOnPlaneSide returns 1 if part of the box is fully in view, 2 if none of it is (thus cull), and 3 if part of it is. 0 is possible if the box is inside out...

5 will never happen. Thus the box (read: model) will never be culled, and will always be visible.
Note that the BSP culling code also uses this function to cull things. So if you do apply that change, you'll more than double the amount of data sent to the graphics card every frame.



The bug is that the model loader loads every single mdl file with mins & max as '-16 -16 -16' & '16 16 16'. Thus the box sizes used in the call to R_CullBox are wrong.

A better, but still lazy, 'fix' is to remove the condition+call+return in R_DrawAliasModel instead. Just comment out the two lines.

The proper fix is to fix the mdl loader to set the size to model_header->origin & (model_header->origin_scale*255).

And to then maybe hack PF_setmodel so QC still sees models as the old -16 & 16 size (quakerally for one breaks).
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Sat Oct 03, 2009 8:46 pm    Post subject: Reply with quote

Spike, the quakerc.org tutorial at:

http://www.quake-1.com/docs/quakesrc.org/71.html

Says to add:
Code:

   aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] =  99999;

   aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = -99999;



After this:

Code:

   //

   // load the frames

   //



   posenum = 0;

   pframetype = (daliasframetype_t *)&pintriangles[pheader->numtris];


In this:

Code:
   Mod_LoadAliasModel



So instead of doing this:
Code:

   aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] =  99999;

   aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = -99999;


I should do this:
Code:

   aliasbboxmins[0] = aliasbboxmins[1] = aliasbboxmins[2] = 255;
   aliasbboxmaxs[0] = aliasbboxmaxs[1] = aliasbboxmaxs[2] = 0;


That is correct, right?
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sat Oct 03, 2009 9:01 pm    Post subject: Reply with quote

The important bit is this code:
Quote:

// FIXME: do this right
mod->mins[0] = mod->mins[1] = mod->mins[2] = -16;
mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16;


The whole aliasbboxmins / aliasbboxmaxs part of that tutorial you linked is to try to get as small a bounds as possible.
Although that's probably overkill, as the model will generally be expanded to consume the full 0-255 range anyway, in which case mins is 0 and maxs is 255.

But yeah, that tutorial should fix it properly and efficiently.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Mon Oct 05, 2009 9:02 pm    Post subject: Reply with quote

Rich Whitehouse fixed it in his model loader
Code:

   //rww - doing this right (get the max extents of the verts for all poses).
   //could also use a mins/maxs for culling for each pose uniquely, but who cares.
   //continue using 32 as the minimum extent size
   mod->mins[0] = mod->mins[1] = mod->mins[2] = -16.0f;
   mod->maxs[0] = mod->maxs[1] = mod->maxs[2] = 16.0f;
   for (i = 0; i < pheader->numposes; i++)
   {
      int j;
      for (j = 0; j < pheader->numverts; j++) {
         byte *vert = poseverts[i][j].v;
         float v;
         for (k = 0; k < 3; k++)
         {
            v = (float)vert[k];
            v *= pheader->scale[k];
            v += pheader->scale_origin[k];

            if (v < mod->mins[k])
            {
               mod->mins[k] = v;
            }
            if (v > mod->maxs[k])
            {
               mod->maxs[k] = v;
            }
         }
      }
   }
   for (k = 0; k < 3; k++)
   {
      mod->mins[k] -= 32.0f;
      mod->maxs[k] += 32.0f;
   }

   if (mod->maxs[1] > mod->maxs[0])
   {
      mod->maxs[0] = mod->maxs[1];
   }
   else
   {
      mod->maxs[1] = mod->maxs[0];
   }
   if (mod->maxs[2] > mod->maxs[0])
   {
      mod->maxs[0] = mod->maxs[2];
      mod->maxs[1] = mod->maxs[2];
   }
   else
   {
      mod->maxs[2] = mod->maxs[0];
   }
   if (mod->mins[1] < mod->mins[0])
   {
      mod->mins[0] = mod->mins[1];
   }
   else
   {
      mod->mins[1] = mod->mins[0];
   }
   if (mod->mins[2] < mod->mins[0])
   {
      mod->mins[0] = mod->mins[2];
      mod->mins[1] = mod->mins[2];
   }
   else
   {
      mod->mins[2] = mod->mins[0];
   }

   mod->radius = RadiusFromBounds (mod->mins, mod->maxs);
Back to top
View user's profile Send private message
FrikaC
Site Admin


Joined: 08 Oct 2004
Posts: 947

PostPosted: Thu Oct 08, 2009 10:00 pm    Post subject: Reply with quote

Weird bit of code. He's got it starting at 32x32x32, finds the maximum extents of the model, extends a further 64x64x64 (to cover up rotations exiting the bounds no doubt (better would be to multiply by the square root of 2), then takes the greatest extent encountered and copies it everywhere (again, rotation).
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group