Page 1 of 1

Bounding Boxes and Powerups

Posted: Fri Jul 02, 2010 2:53 pm
by smalec
Hello,
I would like to how to draw bounding boxes around other players, is it possible to use drawtools like CG_FillRect for this?
and my second question is: how to display the powerups respawn time like how many seconds are left to the quad damage respawn?
Thank you,
s.

Re: Bounding Boxes and Powerups

Posted: Sat Jul 03, 2010 8:33 am
by ^misantropia^
I would like to how to draw bounding boxes around other players, is it possible to use drawtools like CG_FillRect for this
Not CG_FillRect(), it's only for 2D drawing. You probably want trap_R_AddPolysToScene().
how to display the powerups respawn time like how many seconds are left to the quad damage respawn
Do you want to know how to calculate the time remaining to respawn or how to make it visible on-screen?

Re: Bounding Boxes and Powerups

Posted: Sat Jul 03, 2010 4:04 pm
by smalec
Do you want to know how to calculate the time remaining to respawn or how to make it visible on-screen?
How to calculate the time remaining to respawn

Re: Bounding Boxes and Powerups

Posted: Sat Jul 03, 2010 5:02 pm
by ^misantropia^
You'll have to listen for the pickup event from the server. item->quantity (I kid you not) is the respawn time, in the below snippet from cgame/cg_event.c:

Code: Select all

        case EV_GLOBAL_ITEM_PICKUP:
                DEBUGNAME("EV_GLOBAL_ITEM_PICKUP");
                { 
                        gitem_t *item;
                        int             index;

                        index = es->eventParm;          // player predicted

                        if ( index < 1 || index >= bg_numItems ) {
                                break;
                        }
                        item = &bg_itemlist[ index ];
                        // powerup pickups are global
                        if( item->pickup_sound ) {
                                trap_S_StartSound (NULL, cg.snap->ps.clientNum, CHAN_AUTO, trap_S_RegisterSound( item->pickup_sound, qfalse ) );
                        }

                        // show icon and name on status bar
                        if ( es->number == cg.snap->ps.clientNum ) {
                                CG_ItemPickup( index );  
                        }
                }
                break;

Re: Bounding Boxes and Powerups

Posted: Sun Aug 08, 2010 11:27 pm
by Hxrmn
You mean like this:
Image

BTW, this is real code, took me 3 hours to write it :P
Bounding boxes are a bit big on some players so it needs a bit of work.
The problem is, trap_R_ModelBounds only gets the bounding box of the model for it's first frame. So I'll probably have to implement my own bounding boxes for the player's body / legs. :(

Re: Bounding Boxes and Powerups

Posted: Mon Aug 09, 2010 10:15 am
by ^misantropia^
Hxrmn, I'm afraid I don't understand. The bounding box is static, right? What is it you would want to do with it?

Re: Bounding Boxes and Powerups

Posted: Mon Aug 09, 2010 5:57 pm
by Hxrmn
I would like to how to draw bounding boxes around other players, is it possible to use drawtools like CG_FillRect
I assumed he meant some sort of hud element like the kind they made for dystopia:
Image

Based on the fact that he was asking about a 2D drawing function ("CG_FillRect").

But yeah if you wanted to do a 3D bounding box, you'll still have the same issue with not being able to get the animated bounding box.

Re: Bounding Boxes and Powerups

Posted: Tue Aug 10, 2010 4:41 pm
by smalec
I'm talking about 3d box not simple frame...
btw. maybe u guys know how to link two vec3_t and make a line ?

Re: Bounding Boxes and Powerups

Posted: Tue Aug 10, 2010 6:42 pm
by Hxrmn
Like I said, you can do a bounding box based on the player model but it only uses the bounding box for the first frame of animation. So on some of the player models where the death animation is on the first frame, the bounding box is huge. You could just fake it by defining your own bounding box mins/maxs.

Your mins/maxs could just be:
[-20,-20,0]
[20,20,100]

I dunno, mess with it.

Then you can get the the 8 points that make up the box using this code:

Code: Select all

void BoundingBoxPoints(vec3_t origin, vec3_t mins, vec3_t maxs, vec3_t nodes[8]) {
	vec3_t tmaxs, tmins;
	float old;

	VectorAdd(mins, origin, tmins);
	VectorAdd(maxs, origin, tmaxs);
	VectorCopy(tmins,nodes[0]);
	old = tmins[0];
	tmins[0] = tmaxs[0];
	VectorCopy(tmins,nodes[1]);
	tmins[0] = old;
	tmins[1] = tmaxs[1];
	VectorCopy(tmins,nodes[2]);
	tmins[0] = tmaxs[0];
	VectorCopy(tmins,nodes[3]);

	VectorAdd(mins, origin, tmins);
	VectorCopy(tmaxs,nodes[4]);
	old = tmaxs[0];
	tmaxs[0] = tmins[0];
	VectorCopy(tmaxs,nodes[5]);
	tmaxs[0] = old;
	tmaxs[1] = tmins[1];
	VectorCopy(tmaxs,nodes[6]);
	tmaxs[0] = tmins[0];
	VectorCopy(tmaxs,nodes[7]);
}
Then it's just a matter of drawing lines between the right points, and you can just use a refentity_t with RT_BEAM.

Code: Select all

	refEntity_t   re;
 
	re.shaderTime = cg.time;
	re.reType = RT_RAIL_CORE;
	re.customShader = cgs.media.railCoreShader;
  
	re.shaderRGBA[0] = 255;
        re.shaderRGBA[1] = 255;
        re.shaderRGBA[2] = 255;
        re.shaderRGBA[3] = 255;

	VectorCopy(start, re.origin);
	VectorCopy(end, re.oldorigin);

        trap_R_AddRefEntityToScene( &re);
Might want to make it a function. :P
-Cheers

Re: Bounding Boxes and Powerups

Posted: Wed Aug 11, 2010 10:31 am
by smalec
works perfect :)

Re: Bounding Boxes and Powerups

Posted: Thu Aug 12, 2010 11:17 am
by smalec
Oh maybe u know how to make this line rotate with me?

Re: Bounding Boxes and Powerups

Posted: Fri Aug 13, 2010 6:21 pm
by Hxrmn
Ok when you make your bounding box points, pass vec3_origin as the origin (0,0,0), this allows us to rotate the points properly
You'll need the following code for rotations.

Code: Select all

void RotateForAxis(vec3_t v, vec3_t axis[3]) {
        int i;
        vec3_t temp,temp2;
        VectorClear(temp);
        VectorClear(temp2);
        for(i=0; i<3; i++) {
                VectorScale(axis[i], v[i], temp);
                VectorAdd(temp,temp2,temp2);
        }
        VectorCopy(temp2,v);
}
create your rotation axis:

Code: Select all

vec3_t rotation[3];
...
AnglesToAxis(yourPlayerAngle, rotation);
rotate + translate the points:

Code: Select all

for(i=0, i<8, i++) {
       RotateForAxis(nodes[i], rotation);
       VectorAdd(nodes[i],yourPlayerOrigin,nodes[i]);
}
You will need to supply values for "yourPlayerAngle" and "yourPlayerOrigin" which are both vec3_t.
Good luck to you.