Results 1 to 1 of 1

Thread: [idTech3]3D Bounding Box

  1. #1
    Join Date
    May 2009
    Posts
    5
    Thanks
    4
    Thanked 13 Times in 4 Posts

    Default [idTech3]3D Bounding Box

    should be useful

    Code:
    static void CG_DrawBoxSide(vec3_t a, vec3_t b, vec3_t c, vec3_t d)
    {
    	polyVert_t      verts[4];
    	vec4_t          color = { 0.0f, 255.0f, 0.0f, 20.0f };
    
    	VectorCopy(d, verts[0].xyz);
    	verts[0].st[0] = 1;
    	verts[0].st[1] = 1;
    	VectorCopy4(color, verts[0].modulate);
    
    	VectorCopy(c, verts[1].xyz);
    	verts[1].st[0] = 1;
    	verts[1].st[1] = 0;
    	VectorCopy4(color, verts[1].modulate);
    
    	VectorCopy(b, verts[2].xyz);
    	verts[2].st[0] = 0;
    	verts[2].st[1] = 0;
    	VectorCopy4(color, verts[2].modulate);
    
    	VectorCopy(a, verts[3].xyz);
    	verts[3].st[0] = 0;
    	verts[3].st[1] = 1;
    	VectorCopy4(color, verts[3].modulate);
    
    	orig_RE_AddPolyToScene(orig_RE_RegisterShader("white"), 4, verts);
    }
    
    void CG_DrawBoundingBox(vec3_t origin, vec3_t mins, vec3_t maxs)
    {
    	vec3_t          ppp, mpp, mmp, pmp;
    	vec3_t          mmm, pmm, ppm, mpm;
    
    	ppp[0] = origin[0] + maxs[0];
    	ppp[1] = origin[1] + maxs[1];
    	ppp[2] = origin[2] + maxs[2];
    
    	mpp[0] = origin[0] + mins[0];
    	mpp[1] = origin[1] + maxs[1];
    	mpp[2] = origin[2] + maxs[2];
    
    	mmp[0] = origin[0] + mins[0];
    	mmp[1] = origin[1] + mins[1];
    	mmp[2] = origin[2] + maxs[2];
    
    	pmp[0] = origin[0] + maxs[0];
    	pmp[1] = origin[1] + mins[1];
    	pmp[2] = origin[2] + maxs[2];
    
    	ppm[0] = origin[0] + maxs[0];
    	ppm[1] = origin[1] + maxs[1];
    	ppm[2] = origin[2] + mins[2];
    
    	mpm[0] = origin[0] + mins[0];
    	mpm[1] = origin[1] + maxs[1];
    	mpm[2] = origin[2] + mins[2];
    
    	mmm[0] = origin[0] + mins[0];
    	mmm[1] = origin[1] + mins[1];
    	mmm[2] = origin[2] + mins[2];
    
    	pmm[0] = origin[0] + maxs[0];
    	pmm[1] = origin[1] + mins[1];
    	pmm[2] = origin[2] + mins[2];
    
    	//phew!
    
    	CG_DrawBoxSide(ppp, mpp, mmp, pmp);
    	CG_DrawBoxSide(ppp, pmp, pmm, ppm);
    	CG_DrawBoxSide(mpp, ppp, ppm, mpm);
    	CG_DrawBoxSide(mmp, mpp, mpm, mmm);
    	CG_DrawBoxSide(pmp, mmp, mmm, pmm);
    	CG_DrawBoxSide(mmm, mpm, ppm, pmm);
    }
    
    How to use:
    
    	for(int num = 0; num < cg->snap->numEntities; num++)
    	{
    			float           x, zd, zu;
    			vec3_t          mins, maxs;
    			entityState_t  *es;
    
    			cent = &cg_entities[cg->snap->entities[num].number];
    			es = &cent->currentState;
    
    			x = (es->solid & 255);
    			zd = ((es->solid >> 8) & 255);
    			zu = ((es->solid >> 16) & 255) - 32;
    
    			mins[0] = mins[1] = -x;
    			maxs[0] = maxs[1] = x;
    			mins[2] = -zd;
    			maxs[2] = zu;
    
    			if(cent->currentState.eType == ET_PLAYER)
    			{
    				CG_DrawBoundingBox(cent->lerpOrigin, mins, maxs);
    			}
    	}
    and the final result:
    Attached Images Attached Images

  2. The Following 7 Users Say Thank You to bubble For This Useful Post:

    Asylum (3rd May 2011), cobra (4th May 2011), Deagle (3rd May 2011), hax92 (7th March 2013), lolzoruslockus (3rd May 2011), Murder4higher (6th May 2011), wessie (13th April 2013)

Visitors found this page by searching for:

bounding box snapping in 3d

paysafecard

compute bounding verts on box

3d bounding box

SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •