Exemplo n.º 1
0
float
Projector::ApparentRadius(const Vec3& v, float radius) const
{
    Vec3 vloc = v;

    Transform(vloc);                  // transform in place
    return ProjectRadius(vloc, radius);
}
Exemplo n.º 2
0
/*
=================
R_ComputeLOD

=================
*/
int R_ComputeLOD( trRefEntity_t *ent ) {
	float radius;
	float flod, lodscale;
	float projectedRadius;
	md3Frame_t *frame;
	int lod;

	if ( tr.currentModel->numLods < 2 )
	{
		// model has only 1 LOD level, skip computations and bias
		lod = 0;
	}
	else
	{
		// multiple LODs exist, so compute projected bounding sphere
		// and use that as a criteria for selecting LOD

		frame = ( md3Frame_t * ) ( ( ( unsigned char * ) tr.currentModel->md3[0] ) + tr.currentModel->md3[0]->ofsFrames );

		frame += ent->e.frame;

		radius = RadiusFromBounds( frame->bounds[0], frame->bounds[1] );

		if ( ( projectedRadius = ProjectRadius( radius, ent->e.origin ) ) != 0 )
		{
			lodscale = r_lodscale->value;
			if (lodscale > 20) lodscale = 20;
			flod = 1.0f - projectedRadius * lodscale;
		}
		else
		{
			// object intersects near view plane, e.g. view weapon
			flod = 0;
		}

		flod *= tr.currentModel->numLods;
		lod = myftol( flod );

		if ( lod < 0 )
		{
			lod = 0;
		}
		else if ( lod >= tr.currentModel->numLods )
		{
			lod = tr.currentModel->numLods - 1;
		}
	}

	lod += r_lodbias->integer;
	
	if ( lod >= tr.currentModel->numLods )
		lod = tr.currentModel->numLods - 1;
	if ( lod < 0 )
		lod = 0;

	return lod;
}
Exemplo n.º 3
0
/*
=================
R_CalcMDSLod

=================
*/
float R_CalcMDSLod( refEntity_t *refent, vec3_t origin, float radius, float modelBias, float modelScale ) {
	float flod, lodScale;
	float projectedRadius;

	if ( refent->reFlags & REFLAG_FULL_LOD ) {
		return 1.0f;
	}

	// compute projected bounding sphere and use that as a criteria for selecting LOD

	projectedRadius = ProjectRadius( radius, origin );
	if ( projectedRadius != 0 ) {

//		ri.Printf (PRINT_ALL, "projected radius: %f\n", projectedRadius);

		lodScale = r_lodscale->value;   // fudge factor since MDS uses a much smoother method of LOD
		flod = projectedRadius * lodScale * modelScale;
	} else
	{
		// object intersects near view plane, e.g. view weapon
		flod = 1.0f;
	}

	if ( refent->reFlags & REFLAG_FORCE_LOD ) {
		flod *= 0.5;
	}
//----(SA)	like reflag_force_lod, but separate for the moment
	if ( refent->reFlags & REFLAG_DEAD_LOD ) {
		flod *= 0.8;
	}

	flod -= 0.25 * ( r_lodbias->value ) + modelBias;

	if ( flod < 0.0 ) {
		flod = 0.0;
	} else if ( flod > 1.0f ) {
		flod = 1.0f;
	}

	return flod;
}
Exemplo n.º 4
0
/*
=================
R_ComputeLOD

=================
*/
int R_ComputeLOD(trRefEntity_t * ent)
{
	float           radius;
	float           flod, lodscale;
	float           projectedRadius;
	md3Frame_t     *frame;
	int             lod;

	if(tr.currentModel->numLods < 2)
	{
		// model has only 1 LOD level, skip computations and bias
		lod = 0;
	}
	else
	{
		// multiple LODs exist, so compute projected bounding sphere
		// and use that as a criteria for selecting LOD

		// RF, checked for a forced lowest LOD
		if(ent->e.reFlags & REFLAG_FORCE_LOD)
		{
			return (tr.currentModel->numLods - 1);
		}

		frame = (md3Frame_t *) (((unsigned char *)tr.currentModel->model.md3[0]) + tr.currentModel->model.md3[0]->ofsFrames);

		frame += ent->e.frame;

		radius = RadiusFromBounds(frame->bounds[0], frame->bounds[1]);

		//----(SA)  testing
		if(ent->e.reFlags & REFLAG_ORIENT_LOD)
		{
			// right now this is for trees, and pushes the lod distance way in.
			// this is not the intended purpose, but is helpful for the new
			// terrain level that has loads of trees
//          radius = radius/2.0f;
		}
		//----(SA)  end

		if((projectedRadius = ProjectRadius(radius, ent->e.origin)) != 0)
		{
			lodscale = r_lodscale->value;
			if(lodscale > 20)
			{
				lodscale = 20;
			}
			flod = 1.0f - projectedRadius * lodscale;
		}
		else
		{
			// object intersects near view plane, e.g. view weapon
			flod = 0;
		}

		flod *= tr.currentModel->numLods;
		lod = ri.ftol(flod);

		if(lod < 0)
		{
			lod = 0;
		}
		else if(lod >= tr.currentModel->numLods)
		{
			lod = tr.currentModel->numLods - 1;
		}
	}

	lod += r_lodbias->integer;

	if(lod >= tr.currentModel->numLods)
	{
		lod = tr.currentModel->numLods - 1;
	}
	if(lod < 0)
	{
		lod = 0;
	}

	return lod;
}
Exemplo n.º 5
0
Arquivo: tr_mesh.c Projeto: Razish/QtZ
int R_ComputeLOD( trRefEntity_t *ent ) {
    float radius;
    float flod, lodscale;
    float projectedRadius;
    md3Frame_t *frame;
#ifdef RAVENMD4
    mdrHeader_t *mdr;
    mdrFrame_t *mdrframe;
#endif
    int lod;

    if ( tr.currentModel->numLods < 2 )
    {
        // model has only 1 LOD level, skip computations and bias
        lod = 0;
    }
    else
    {
        // multiple LODs exist, so compute projected bounding sphere
        // and use that as a criteria for selecting LOD

#ifdef RAVENMD4
        if(tr.currentModel->type == MOD_MDR)
        {
            int frameSize;
            mdr = (mdrHeader_t *) tr.currentModel->modelData;
            frameSize = (size_t) (&((mdrFrame_t *)0)->bones[mdr->numBones]);

            mdrframe = (mdrFrame_t *) ((byte *) mdr + mdr->ofsFrames + frameSize * ent->e.frame);

            radius = RadiusFromBounds(mdrframe->bounds[0], mdrframe->bounds[1]);
        }
        else
#endif
        {
            frame = ( md3Frame_t * ) ( ( ( unsigned char * ) tr.currentModel->md3[0] ) + tr.currentModel->md3[0]->ofsFrames );

            frame += ent->e.frame;

            radius = RadiusFromBounds( &frame->bounds[0], &frame->bounds[1] );
        }

        if ( ( projectedRadius = ProjectRadius( radius, &ent->e.origin ) ) != 0 )
        {
            lodscale = r_lodscale->value;
            if (lodscale > 20) lodscale = 20;
            flod = 1.0f - projectedRadius * lodscale;
        }
        else
        {
            // object intersects near view plane, e.g. view weapon
            flod = 0;
        }

        flod *= tr.currentModel->numLods;
        lod = ri->ftol(flod);

        if ( lod < 0 )
        {
            lod = 0;
        }
        else if ( lod >= tr.currentModel->numLods )
        {
            lod = tr.currentModel->numLods - 1;
        }
    }

    lod += r_lodbias->integer;

    if ( lod >= tr.currentModel->numLods )
        lod = tr.currentModel->numLods - 1;
    if ( lod < 0 )
        lod = 0;

    return lod;
}