当前位置: 首页>>代码示例>>C++>>正文


C++ VectorAdd函数代码示例

本文整理汇总了C++中VectorAdd函数的典型用法代码示例。如果您正苦于以下问题:C++ VectorAdd函数的具体用法?C++ VectorAdd怎么用?C++ VectorAdd使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了VectorAdd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RB_DrawSun

/*
==============
RB_DrawSun
	(SA) FIXME: sun should render behind clouds, so passing dark areas cover it up
==============
*/
void RB_DrawSun( void ) {
	float size;
	float dist;
	vec3_t origin, vec1, vec2;
	vec3_t temp;
	byte color[4];

	if ( !tr.sunShader ) {
		return;
	}

	if ( !backEnd.skyRenderedThisView ) {
		return;
	}
	if ( !r_drawSun->integer ) {
		return;
	}
	qglPushMatrix();
	qglLoadMatrixf( backEnd.viewParms.world.modelMatrix );
	qglTranslatef( backEnd.viewParms.orientation.origin[0], backEnd.viewParms.orientation.origin[1], backEnd.viewParms.orientation.origin[2] );

	dist =  backEnd.viewParms.zFar / 1.75;      // div sqrt(3)

	// (SA) shrunk the size of the sun
	size = dist * 0.2;

	VectorScale( tr.sunDirection, dist, origin );
	PerpendicularVector( vec1, tr.sunDirection );
	CrossProduct( tr.sunDirection, vec1, vec2 );

	VectorScale( vec1, size, vec1 );
	VectorScale( vec2, size, vec2 );

	// farthest depth range
	qglDepthRange( 1.0, 1.0 );

	color[0] = color[1] = color[2] = color[3] = 255;

	// (SA) simpler sun drawing
	RB_BeginSurface( tr.sunShader, tess.fogNum );

	RB_AddQuadStamp( origin, vec1, vec2, color );
/*
		VectorCopy( origin, temp );
		VectorSubtract( temp, vec1, temp );
		VectorSubtract( temp, vec2, temp );
		VectorCopy( temp, tess.xyz[tess.numVertexes].v );
		tess.texCoords0[tess.numVertexes].v[0] = 0;
		tess.texCoords0[tess.numVertexes].v[1] = 0;
		tess.vertexColors[tess.numVertexes].v[0] = 255;
		tess.vertexColors[tess.numVertexes].v[1] = 255;
		tess.vertexColors[tess.numVertexes].v[2] = 255;
		tess.numVertexes++;

		VectorCopy( origin, temp );
		VectorAdd( temp, vec1, temp );
		VectorSubtract( temp, vec2, temp );
		VectorCopy( temp, tess.xyz[tess.numVertexes].v );
		tess.texCoords0[tess.numVertexes].v[0] = 0;
		tess.texCoords0[tess.numVertexes].v[1] = 1;
		tess.vertexColors[tess.numVertexes].v[0] = 255;
		tess.vertexColors[tess.numVertexes].v[1] = 255;
		tess.vertexColors[tess.numVertexes].v[2] = 255;
		tess.numVertexes++;

		VectorCopy( origin, temp );
		VectorAdd( temp, vec1, temp );
		VectorAdd( temp, vec2, temp );
		VectorCopy( temp, tess.xyz[tess.numVertexes].v );
		tess.texCoords0[tess.numVertexes].v[0] = 1;
		tess.texCoords0[tess.numVertexes].v[1] = 1;
		tess.vertexColors[tess.numVertexes].v[0] = 255;
		tess.vertexColors[tess.numVertexes].v[1] = 255;
		tess.vertexColors[tess.numVertexes].v[2] = 255;
		tess.numVertexes++;

		VectorCopy( origin, temp );
		VectorSubtract( temp, vec1, temp );
		VectorAdd( temp, vec2, temp );
		VectorCopy( temp, tess.xyz[tess.numVertexes].v );
		tess.texCoords0[tess.numVertexes].v[0] = 1;
		tess.texCoords0[tess.numVertexes].v[1] = 0;
		tess.vertexColors[tess.numVertexes].v[0] = 255;
		tess.vertexColors[tess.numVertexes].v[1] = 255;
		tess.vertexColors[tess.numVertexes].v[2] = 255;
		tess.numVertexes++;

		tess.indexes[tess.numIndexes++] = 0;
		tess.indexes[tess.numIndexes++] = 1;
		tess.indexes[tess.numIndexes++] = 2;
		tess.indexes[tess.numIndexes++] = 0;
		tess.indexes[tess.numIndexes++] = 2;
		tess.indexes[tess.numIndexes++] = 3;
*/
//.........这里部分代码省略.........
开发者ID:AdrienJaguenet,项目名称:Enemy-Territory,代码行数:101,代码来源:tr_sky.c

示例2: DeformText

// Change a polygon into a bunch of text polygons
void DeformText( const char *text ) {
	int		i;
	vector3	origin, width, height;
	int		len;
	int		ch;
	byte	color[4];
	float	bottom, top;
	vector3	mid;

	height.x = 0;
	height.y = 0;
	height.z = -1;
	CrossProduct( &tess.normal[0], &height, &width );

	// find the midpoint of the box
	VectorClear( &mid );
	bottom = 999999;
	top = -999999;
	for ( i = 0 ; i < 4 ; i++ ) {
		VectorAdd( &tess.xyz[i], &mid, &mid );
		if ( tess.xyz[i].z < bottom ) {
			bottom = tess.xyz[i].z;
		}
		if ( tess.xyz[i].z > top ) {
			top = tess.xyz[i].z;
		}
	}
	VectorScale( &mid, 0.25f, &origin );

	// determine the individual character size
	height.x = 0;
	height.y = 0;
	height.z = ( top - bottom ) * 0.5f;

	VectorScale( &width, height.z * -0.75f, &width );

	// determine the starting position
	len = strlen( text );
	VectorMA( &origin, (float)(len-1), &width, &origin );

	// clear the shader indexes
	tess.numIndexes = 0;
	tess.numVertexes = 0;

	color[0] = color[1] = color[2] = color[3] = 255;

	// draw each character
	for ( i = 0 ; i < len ; i++ ) {
		ch = text[i];
		ch &= 255;

		if ( ch != ' ' ) {
			int		row, col;
			float	frow, fcol, size;

			row = ch>>4;
			col = ch&15;

			frow = row*0.0625f;
			fcol = col*0.0625f;
			size = 0.0625f;

			RB_AddQuadStampExt( &origin, &width, &height, color, fcol, frow, fcol + size, frow + size );
		}
		VectorMA( &origin, -2, &width, &origin );
	}
开发者ID:AstralSerpent,项目名称:QtZ,代码行数:67,代码来源:tr_shade_calc.c

示例3: AddReflection


//.........这里部分代码省略.........
			if(org[2] > mirror->absmax[2]) continue;
			is_reflected = true;
		}
		if(is_reflected)
		{
			if (!ent->reflection[i])
			{			
				ent->reflection[i] = G_Spawn();
			
				if(ent->s.effects & EF_ROTATE)
				{
					ent->s.effects &= ~EF_ROTATE;
					gi.linkentity(ent);
				}
				ent->reflection[i]->movetype = MOVETYPE_NONE;
				ent->reflection[i]->solid = SOLID_NOT;
				ent->reflection[i]->classname = "reflection";
				ent->reflection[i]->flags = FL_REFLECT;
				ent->reflection[i]->takedamage = DAMAGE_NO;
			}
			if (ent->client && !ent->reflection[i]->client)
			{
				cl = (gclient_t *)malloc(sizeof(gclient_t)); 
				ent->reflection[i]->client = cl; 
			}
			if (ent->client && ent->reflection[i]->client)
			{
//				Lazarus: Hmm.. this crashes when loading saved game.
//				         Not sure what use pers is anyhow?
//				ent->reflection[i]->client->pers = ent->client->pers;
				ent->reflection[i]->s = ent->s;
			}
			ent->reflection[i]->s.number     = ent->reflection[i] - g_edicts;
			ent->reflection[i]->s.modelindex = ent->s.modelindex;
			ent->reflection[i]->s.modelindex2 = ent->s.modelindex2;
			ent->reflection[i]->s.modelindex3 = ent->s.modelindex3;
			ent->reflection[i]->s.modelindex4 = ent->s.modelindex4;
		#ifdef KMQUAKE2_ENGINE_MOD
			ent->reflection[i]->s.modelindex5 = ent->s.modelindex5;
			ent->reflection[i]->s.modelindex6 = ent->s.modelindex6;
		#ifndef LOOP_SOUND_ATTENUATION
			ent->reflection[i]->s.modelindex7 = ent->s.modelindex7;
			ent->reflection[i]->s.modelindex8 = ent->s.modelindex8;
		#endif
			ent->reflection[i]->s.alpha = ent->s.alpha;
		#endif
			ent->reflection[i]->s.skinnum = ent->s.skinnum;
			ent->reflection[i]->s.frame = ent->s.frame;
			ent->reflection[i]->s.effects = ent->s.effects;
			ent->reflection[i]->s.renderfx = ent->s.renderfx;
			ent->reflection[i]->s.renderfx &= ~RF_IR_VISIBLE;
		#ifdef KMQUAKE2_ENGINE_MOD
			// Don't flip if left handed player model
			if ( !(ent->s.modelindex == (MAX_MODELS-1) && hand->value == 1) )
				ent->reflection[i]->s.renderfx |= RF_MIRRORMODEL; // Knightmare added- flip reflected models
		#endif
			VectorCopy (ent->s.angles, ent->reflection[i]->s.angles);
			switch(i)
			{
			case 0:
			case 1:
				ent->reflection[i]->s.angles[0]+=180;
				ent->reflection[i]->s.angles[1]+=180;
				ent->reflection[i]->s.angles[2]=360-ent->reflection[i]->s.angles[2];
				break;
			case 2:
			case 3:
				AngleVectors(ent->reflection[i]->s.angles,forward,NULL,NULL);
				roll = ent->reflection[i]->s.angles[2];
				forward[0] = -forward[0];
				vectoangles(forward,ent->reflection[i]->s.angles);
				ent->reflection[i]->s.angles[2] = 360-roll;
				break;
			case 4:
			case 5:
				AngleVectors(ent->reflection[i]->s.angles,forward,NULL,NULL);
				roll = ent->reflection[i]->s.angles[2];
				forward[1] = -forward[1];
				vectoangles(forward,ent->reflection[i]->s.angles);
				ent->reflection[i]->s.angles[2] = 360-roll;
			}

			VectorCopy (org, ent->reflection[i]->s.origin);
			if(ent->s.renderfx & RF_BEAM)
			{
				vec3_t	delta;

				VectorSubtract(ent->reflection[i]->s.origin,ent->s.origin,delta);
				VectorAdd(ent->s.old_origin,delta,ent->reflection[i]->s.old_origin);
			}
			else
				VectorCopy(ent->reflection[i]->s.origin, ent->reflection[i]->s.old_origin);
			gi.linkentity (ent->reflection[i]);
		}
		else if (ent->reflection[i])
		{
			DeleteReflection(ent,i);
		}
	}
}
开发者ID:qbism,项目名称:qbq2,代码行数:101,代码来源:g_reflect.c

示例4: G_BounceItem

/*
================
G_BounceItem

================
*/
void G_BounceItem( gentity_t *ent, trace_t *trace ) {
	vec3_t	velocity;
	float	dot;
	int		hitTime;
	qboolean droppedSaber = qtrue;

	if ( ent->item
		&& ent->item->giType == IT_WEAPON
		&& ent->item->giTag == WP_SABER 
		&& (ent->flags&FL_DROPPED_ITEM) )
	{
		droppedSaber = qtrue;
	}

	// reflect the velocity on the trace plane
	hitTime = level.previousTime + ( level.time - level.previousTime ) * trace->fraction;
	EvaluateTrajectoryDelta( &ent->s.pos, hitTime, velocity );
	dot = DotProduct( velocity, trace->plane.normal );
	VectorMA( velocity, -2*dot, trace->plane.normal, ent->s.pos.trDelta );

	// cut the velocity to keep from bouncing forever
	VectorScale( ent->s.pos.trDelta, ent->physicsBounce, ent->s.pos.trDelta );

	if ( droppedSaber )
	{//a dropped saber item
		//FIXME: use NPC_type (as saberType) to get proper bounce sound?
		WP_SaberFallSound( NULL, ent );
	}

	// check for stop
	if ( trace->plane.normal[2] > 0 && ent->s.pos.trDelta[2] < 40 ) 
	{//stop
		G_SetOrigin( ent, trace->endpos );
		ent->s.groundEntityNum = trace->entityNum;
		if ( droppedSaber )
		{//a dropped saber item
			//stop rotation
			VectorClear( ent->s.apos.trDelta );
			ent->currentAngles[PITCH] = SABER_PITCH_HACK;
			ent->currentAngles[ROLL] = 0;
			if ( ent->NPC_type 
				&& ent->NPC_type[0] )
			{//we have a valid saber for this
				saberInfo_t saber;
				if ( WP_SaberParseParms( ent->NPC_type, &saber ) )
				{
					if ( (saber.saberFlags&SFL_BOLT_TO_WRIST) )
					{
						ent->currentAngles[PITCH] = 0;
					}
				}
			}
			pitch_roll_for_slope( ent, trace->plane.normal, ent->currentAngles, qtrue );
			G_SetAngles( ent, ent->currentAngles );
		}
		return;
	}
	//bounce
	if ( droppedSaber )
	{//a dropped saber item
		//change rotation
		VectorCopy( ent->currentAngles, ent->s.apos.trBase );
		ent->s.apos.trType = TR_LINEAR;
		ent->s.apos.trTime = level.time;
		VectorSet( ent->s.apos.trDelta, Q_irand( -300, 300 ), Q_irand( -300, 300 ), Q_irand( -300, 300 ) );
	}

	VectorAdd( ent->currentOrigin, trace->plane.normal, ent->currentOrigin);
	VectorCopy( ent->currentOrigin, ent->s.pos.trBase );
	ent->s.pos.trTime = level.time;
}
开发者ID:Joanxt,项目名称:OpenJK,代码行数:77,代码来源:g_items.cpp

示例5: SV_movestep

//FIXME since we need to test end position contents here, can we avoid doing
//it again later in catagorize position?
qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
{
    float		dz;
    vec3_t		oldorg, neworg, end;
    trace_t		trace;
    int			i;
    float		stepsize;
    vec3_t		test;
    int			contents;

// try the move
    VectorCopy (ent->s.origin, oldorg);
    VectorAdd (ent->s.origin, move, neworg);

// flying monsters don't step up
    if ( ent->flags & (FL_SWIM | FL_FLY) )
    {
        // try one move with vertical motion, then one without
        for (i=0 ; i<2 ; i++)
        {
            VectorAdd (ent->s.origin, move, neworg);
            if (i == 0 && ent->enemy)
            {
                if (!ent->goalentity)
                    ent->goalentity = ent->enemy;
                dz = ent->s.origin[2] - ent->goalentity->s.origin[2];
                if (ent->goalentity->client)
                {
                    if (dz > 40)
                        neworg[2] -= 8;
                    if (!((ent->flags & FL_SWIM) && (ent->waterlevel < 2)))
                        if (dz < 30)
                            neworg[2] += 8;
                }
                else
                {
                    if (dz > 8)
                        neworg[2] -= 8;
                    else if (dz > 0)
                        neworg[2] -= dz;
                    else if (dz < -8)
                        neworg[2] += 8;
                    else
                        neworg[2] += dz;
                }
            }
            trace = gi.trace (ent->s.origin, ent->mins, ent->maxs, neworg, ent, MASK_MONSTERSOLID);

            // fly monsters don't enter water voluntarily
            if (ent->flags & FL_FLY)
            {
                if (!ent->waterlevel)
                {
                    test[0] = trace.endpos[0];
                    test[1] = trace.endpos[1];
                    test[2] = trace.endpos[2] + ent->mins[2] + 1;
                    contents = gi.pointcontents(test);
                    if (contents & MASK_WATER)
                        return false;
                }
            }

            // swim monsters don't exit water voluntarily
            if (ent->flags & FL_SWIM)
            {
                if (ent->waterlevel < 2)
                {
                    test[0] = trace.endpos[0];
                    test[1] = trace.endpos[1];
                    test[2] = trace.endpos[2] + ent->mins[2] + 1;
                    contents = gi.pointcontents(test);
                    if (!(contents & MASK_WATER))
                        return false;
                }
            }

            if (trace.fraction == 1)
            {
                VectorCopy (trace.endpos, ent->s.origin);
                if (relink)
                {
                    gi.linkentity (ent);
                    G_TouchTriggers (ent);
                }
                return true;
            }

            if (!ent->enemy)
                break;
        }

        return false;
    }

// push down from a step height above the wished position
    if (!(ent->monsterinfo.aiflags & AI_NOSTEP))
        stepsize = STEPSIZE;
    else
//.........这里部分代码省略.........
开发者ID:petmac,项目名称:quake2-lite,代码行数:101,代码来源:m_move.c

示例6: SV_CalcBlend

/*
=============
SV_CalcBlend
=============
*/
void SV_CalcBlend (edict_t *ent)
{
	int		contents;
	vec3_t	vieworg;
	int		remaining;

	ent->client->ps.blend[0] = ent->client->ps.blend[1] = 
		ent->client->ps.blend[2] = ent->client->ps.blend[3] = 0;

	// add for contents
	VectorAdd (ent->s.origin, ent->client->ps.viewoffset, vieworg);
	contents = gi.pointcontents (vieworg);
	if (contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER) )
		ent->client->ps.rdflags |= RDF_UNDERWATER;
	else
		ent->client->ps.rdflags &= ~RDF_UNDERWATER;

	if (contents & (CONTENTS_SOLID|CONTENTS_LAVA))
		SV_AddBlend (1.0, 0.3, 0.0, 0.6, ent->client->ps.blend);
	else if (contents & CONTENTS_SLIME)
		SV_AddBlend (0.0, 0.1, 0.05, 0.6, ent->client->ps.blend);
	else if (contents & CONTENTS_WATER)
		SV_AddBlend (0.5, 0.3, 0.2, 0.4, ent->client->ps.blend);

	// add for powerups
	if (ent->client->quad_framenum > level.framenum)
	{
		remaining = ent->client->quad_framenum - level.framenum;
		if (remaining == 30)	// beginning to fade
			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/damage2.wav"), 1, ATTN_NORM, 0);
		if (remaining > 30 || (remaining & 4) )
			SV_AddBlend (0, 0, 1, 0.08, ent->client->ps.blend);
	}
	// PMM - double damage
	else if (ent->client->double_framenum > level.framenum)
	{
		remaining = ent->client->double_framenum - level.framenum;
		if (remaining == 30)	// beginning to fade
			gi.sound(ent, CHAN_ITEM, gi.soundindex("misc/ddamage2.wav"), 1, ATTN_NORM, 0);
		if (remaining > 30 || (remaining & 4) )
			SV_AddBlend (0.9, 0.7, 0, 0.08, ent->client->ps.blend);
	}
	// PMM
	else if (ent->client->invincible_framenum > level.framenum)
	{
		remaining = ent->client->invincible_framenum - level.framenum;
		if (remaining == 30)	// beginning to fade
			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/protect2.wav"), 1, ATTN_NORM, 0);
		if (remaining > 30 || (remaining & 4) )
			SV_AddBlend (1, 1, 0, 0.08, ent->client->ps.blend);
	}
	else if (ent->client->enviro_framenum > level.framenum)
	{
		remaining = ent->client->enviro_framenum - level.framenum;
		if (remaining == 30)	// beginning to fade
			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
		if (remaining > 30 || (remaining & 4) )
			SV_AddBlend (0, 1, 0, 0.08, ent->client->ps.blend);
	}
	else if (ent->client->breather_framenum > level.framenum)
	{
		remaining = ent->client->breather_framenum - level.framenum;
		if (remaining == 30)	// beginning to fade
			gi.sound(ent, CHAN_ITEM, gi.soundindex("items/airout.wav"), 1, ATTN_NORM, 0);
		if (remaining > 30 || (remaining & 4) )
			SV_AddBlend (0.4, 1, 0.4, 0.04, ent->client->ps.blend);
	}

	//PGM
	if(ent->client->nuke_framenum > level.framenum)
	{
		float brightness;
		brightness = (ent->client->nuke_framenum - level.framenum) / 20.0;
		SV_AddBlend (1, 1, 1, brightness, ent->client->ps.blend);
	}
	if (ent->client->ir_framenum > level.framenum)
	{
		remaining = ent->client->ir_framenum - level.framenum;
		if(remaining > 30 || (remaining & 4))
		{
			ent->client->ps.rdflags |= RDF_IRGOGGLES;
			SV_AddBlend (1, 0, 0, 0.2, ent->client->ps.blend);
		}
		else
			ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
	}
	else
	{
		ent->client->ps.rdflags &= ~RDF_IRGOGGLES;
	}
	//PGM

	// add for damage
	if (ent->client->damage_alpha > 0)
		SV_AddBlend (ent->client->damage_blend[0],ent->client->damage_blend[1]
//.........这里部分代码省略.........
开发者ID:DrItanium,项目名称:rogue,代码行数:101,代码来源:view.c

示例7: PM_SlideMove

qboolean	PM_SlideMove( qboolean gravity ) {
	int			bumpcount, numbumps;
	vec3_t		dir;
	float		d;
	int			numplanes;
	vec3_t		planes[MAX_CLIP_PLANES];
	vec3_t		primal_velocity;
	vec3_t		clipVelocity;
	int			i, j, k;
	trace_t	trace;
	vec3_t		end;
	float		time_left;
	float		into;
	vec3_t		endVelocity;
	vec3_t		endClipVelocity;
	
	numbumps = 4;

	VectorCopy (pm->ps->velocity, primal_velocity);

	if ( gravity ) {
		VectorCopy( pm->ps->velocity, endVelocity );
		endVelocity[2] -= pm->ps->gravity * pml.frametime;
		pm->ps->velocity[2] = ( pm->ps->velocity[2] + endVelocity[2] ) * 0.5;
		primal_velocity[2] = endVelocity[2];
		if ( pml.groundPlane ) {
			// slide along the ground plane
			PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal, 
				pm->ps->velocity, OVERCLIP );
		}
	}

	time_left = pml.frametime;

	// never turn against the ground plane
	if ( pml.groundPlane ) {
		numplanes = 1;
		VectorCopy( pml.groundTrace.plane.normal, planes[0] );
	} else {
		numplanes = 0;
	}

	// never turn against original velocity
	VectorNormalize2( pm->ps->velocity, planes[numplanes] );
	numplanes++;

	for ( bumpcount=0 ; bumpcount < numbumps ; bumpcount++ ) {

		// calculate position we are trying to move to
		VectorMA( pm->ps->origin, time_left, pm->ps->velocity, end );

		// see if we can make it there
		pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemask);

		if (trace.allsolid) {
			// entity is completely trapped in another solid
			pm->ps->velocity[2] = 0;	// don't build up falling damage, but allow sideways acceleration
			return qtrue;
		}

		if (trace.fraction > 0) {
			// actually covered some distance
			VectorCopy (trace.endpos, pm->ps->origin);
		}

		if (trace.fraction == 1) {
			 break;		// moved the entire distance
		}

		// save entity for contact
		PM_AddTouchEnt( trace.entityNum );

		time_left -= time_left * trace.fraction;

		if (numplanes >= MAX_CLIP_PLANES) {
			// this shouldn't really happen
			VectorClear( pm->ps->velocity );
			return qtrue;
		}

		//
		// if this is the same plane we hit before, nudge velocity
		// out along it, which fixes some epsilon issues with
		// non-axial planes
		//
		for ( i = 0 ; i < numplanes ; i++ ) {
			if ( DotProduct( trace.plane.normal, planes[i] ) > 0.99 ) {
				VectorAdd( trace.plane.normal, pm->ps->velocity, pm->ps->velocity );
				break;
			}
		}
		if ( i < numplanes ) {
			continue;
		}
		VectorCopy (trace.plane.normal, planes[numplanes]);
		numplanes++;

		//
		// modify velocity so it parallels all of the clip planes
		//
//.........这里部分代码省略.........
开发者ID:ET-NiK,项目名称:amxxgroup,代码行数:101,代码来源:bg_slidemove.c

示例8: GrabFrame

/*
   ===============
   GrabFrame
   ===============
 */
static void GrabFrame( char *frame ){
	triangle_t      *ptri;
	int i, j;
	trivert_t       *ptrivert;
	int num_tris;
	char file1[1024];
	frame_t         *fr;
	vertexnormals_t vnorms[MAX_VERTS];
	int index_xyz;
	char            *framefile;

	// the frame 'run1' will be looked for as either
	// run.1 or run1.tri, so the new alias sequence save
	// feature an be used
	framefile = FindFrameFile( frame );

	sprintf( file1, "%s/%s", cdarchive, framefile );
	ExpandPathAndArchive( file1 );

	sprintf( file1, "%s/%s",cddir, framefile );

	printf( "grabbing %s  ", file1 );

	if ( model.num_frames >= MAX_FRAMES ) {
		Error( "model.num_frames >= MAX_FRAMES" );
	}
	fr = &g_frames[model.num_frames];
	model.num_frames++;

	strcpy( fr->name, frame );

//
// load the frame
//
	if ( do3ds ) {
		Load3DSTriangleList( file1, &ptri, &num_tris, NULL, NULL );
	}
	else{
		LoadTriangleList( file1, &ptri, &num_tris, NULL, NULL );
	}

	if ( num_tris != model.num_tris ) {
		Error( "%s: number of triangles doesn't match base frame\n", file1 );
	}

//
// allocate storage for the frame's vertices
//
	ptrivert = fr->v;

	for ( i = 0 ; i < model.num_xyz ; i++ )
	{
		vnorms[i].numnormals = 0;
		VectorClear( vnorms[i].normalsum );
	}
	ClearBounds( fr->mins, fr->maxs );

//
// store the frame's vertices in the same order as the base. This assumes the
// triangles and vertices in this frame are in exactly the same order as in the
// base
//
	for ( i = 0 ; i < num_tris ; i++ )
	{
		vec3_t vtemp1, vtemp2, normal;
		float ftemp;

		VectorSubtract( ptri[i].verts[0], ptri[i].verts[1], vtemp1 );
		VectorSubtract( ptri[i].verts[2], ptri[i].verts[1], vtemp2 );
		CrossProduct( vtemp1, vtemp2, normal );

		VectorNormalize( normal, normal );

		// rotate the normal so the model faces down the positive x axis
		ftemp = normal[0];
		normal[0] = -normal[1];
		normal[1] = ftemp;

		for ( j = 0 ; j < 3 ; j++ )
		{
			index_xyz = triangles[i].index_xyz[j];

			// rotate the vertices so the model faces down the positive x axis
			// also adjust the vertices to the desired origin
			ptrivert[index_xyz].v[0] = ( ( -ptri[i].verts[j][1] ) * scale_up ) +
									   adjust[0];
			ptrivert[index_xyz].v[1] = ( ptri[i].verts[j][0] * scale_up ) +
									   adjust[1];
			ptrivert[index_xyz].v[2] = ( ptri[i].verts[j][2] * scale_up ) +
									   adjust[2];

			AddPointToBounds( ptrivert[index_xyz].v, fr->mins, fr->maxs );

			VectorAdd( vnorms[index_xyz].normalsum, normal, vnorms[index_xyz].normalsum );
			vnorms[index_xyz].numnormals++;
//.........这里部分代码省略.........
开发者ID:Barbatos,项目名称:GtkRadiant,代码行数:101,代码来源:models.c

示例9: SV_LinkEntity

void SV_LinkEntity(sharedEntity_t *gEnt) {
	worldSector_t *node;
	int leafs[MAX_TOTAL_ENT_LEAFS];
	int cluster;
	int num_leafs;
	int i, j, k;
	int area;
	int lastLeaf;
	float *origin, *angles;
	svEntity_t *ent;

	ent = SV_SvEntityForGentity(gEnt);
	// sanity check for possible currentOrigin being reset bug
	if (!gEnt->r.bmodel && VectorCompare(gEnt->r.currentOrigin, vec3_origin)) {
		Com_DPrintf("WARNING: BBOX entity is being linked at world origin, this is probably a bug\n");
	}

	if (ent->worldSector) {
		SV_UnlinkEntity(gEnt);   // unlink from old position
	}
	// encode the size into the entityState_t for client prediction
	if (gEnt->r.bmodel) {
		gEnt->s.solid = SOLID_BMODEL;      // a solid_box will never create this value
	} else if (gEnt->r.contents & (CONTENTS_SOLID|CONTENTS_BODY)) {
		// assume that x/y are equal and symetric
		i = gEnt->r.maxs[0];

		if (i < 1) {
			i = 1;
		}

		if (i > 255) {
			i = 255;
		}
		// z is not symetric
		j = (-gEnt->r.mins[2]);

		if (j < 1) {
			j = 1;
		}

		if (j > 255) {
			j = 255;
		}
		// and z maxs can be negative...
		k = (gEnt->r.maxs[2] + 32);

		if (k < 1) {
			k = 1;
		}

		if (k > 255) {
			k = 255;
		}

		gEnt->s.solid = (k << 16)|(j << 8)|i;
	} else {
		gEnt->s.solid = 0;
	}
	// get the position
	origin = gEnt->r.currentOrigin;
	angles = gEnt->r.currentAngles;
	// set the abs box
	if (gEnt->r.bmodel && (angles[0] || angles[1] || angles[2])) {
		// expand for rotation
		float max;

		max = RadiusFromBounds(gEnt->r.mins, gEnt->r.maxs);

		for (i = 0; i < 3; i++) {
			gEnt->r.absmin[i] = origin[i] - max;
			gEnt->r.absmax[i] = origin[i] + max;
		}
	} else {
		// normal
		VectorAdd(origin, gEnt->r.mins, gEnt->r.absmin);
		VectorAdd(origin, gEnt->r.maxs, gEnt->r.absmax);
	}
	// because movement is clipped an epsilon away from an actual edge, we must fully check even when bounding boxes don't quite touch
	gEnt->r.absmin[0] -= 1;
	gEnt->r.absmin[1] -= 1;
	gEnt->r.absmin[2] -= 1;
	gEnt->r.absmax[0] += 1;
	gEnt->r.absmax[1] += 1;
	gEnt->r.absmax[2] += 1;
	// link to PVS leafs
	ent->numClusters = 0;
	ent->lastCluster = 0;
	ent->areanum = -1;
	ent->areanum2 = -1;
	// get all leafs, including solids
	num_leafs = CM_BoxLeafnums(gEnt->r.absmin, gEnt->r.absmax, leafs, MAX_TOTAL_ENT_LEAFS, &lastLeaf);
	// if none of the leafs were inside the map, the entity is outside the world and can be considered unlinked
	if (!num_leafs) {
		return;
	}
	// set areas, even from clusters that don't fit in the entity array
	for (i = 0; i < num_leafs; i++) {
		area = CM_LeafArea(leafs[i]);

//.........这里部分代码省略.........
开发者ID:ioid3-games,项目名称:ioid3-rtcw,代码行数:101,代码来源:sv_world.c

示例10: fire_lead


//.........这里部分代码省略.........
		// see if we hit water
		if (tr.contents & MASK_WATER)
		{
			int		color;

			water = true;
			VectorCopy (tr.endpos, water_start);

			if (!VectorCompare (start, tr.endpos))
			{
				if (tr.contents & CONTENTS_WATER)
				{
					if (strcmp(tr.surface->name, "*brwater") == 0)
						color = SPLASH_BROWN_WATER;
					else
						color = SPLASH_BLUE_WATER;
				}
				else if (tr.contents & CONTENTS_SLIME)
					color = SPLASH_SLIME;
				else if (tr.contents & CONTENTS_LAVA)
					color = SPLASH_LAVA;
				else
					color = SPLASH_UNKNOWN;

				if (color != SPLASH_UNKNOWN)
				{
					gi.WriteByte (svc_temp_entity);
					gi.WriteByte (TE_SPLASH);
					gi.WriteByte (8);
					gi.WritePosition (tr.endpos);
					gi.WriteDir (tr.plane.normal);
					gi.WriteByte (color);
					gi.multicast (tr.endpos, MULTICAST_PVS);
				}

				// change bullet's course when it enters water
				VectorSubtract (end, start, dir);
				vectoangles (dir, dir);
				AngleVectors (dir, forward, right, up);
				r = crandom()*hspread*2;
				u = crandom()*vspread*2;
				VectorMA (water_start, 8192, forward, end);
				VectorMA (end, r, right, end);
				VectorMA (end, u, up, end);
			}

			// re-trace ignoring water this time
			tr = gi.trace (water_start, NULL, NULL, end, self, MASK_SHOT);
		}
	}

	// send gun puff / flash
	if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
	{
		if (tr.fraction < 1.0)
		{
			if (tr.ent->takedamage)
			{
				T_Damage (tr.ent, self, self, aimdir, tr.endpos, tr.plane.normal, damage, kick, DAMAGE_BULLET, mod);
			}
			else
			{
				if (strncmp (tr.surface->name, "sky", 3) != 0)
				{
					gi.WriteByte (svc_temp_entity);
					gi.WriteByte (te_impact);
					gi.WritePosition (tr.endpos);
					gi.WriteDir (tr.plane.normal);
					gi.multicast (tr.endpos, MULTICAST_PVS);

					if (self->client)
						PlayerNoise(self, tr.endpos, PNOISE_IMPACT);
				}
			}
		}
	}

	// if went through water, determine where the end and make a bubble trail
	if (water)
	{
		vec3_t	pos;

		VectorSubtract (tr.endpos, water_start, dir);
		VectorNormalize (dir);
		VectorMA (tr.endpos, -2, dir, pos);
		if (gi.pointcontents (pos) & MASK_WATER)
			VectorCopy (pos, tr.endpos);
		else
			tr = gi.trace (pos, NULL, NULL, water_start, tr.ent, MASK_WATER);

		VectorAdd (water_start, tr.endpos, pos);
		VectorScale (pos, 0.5, pos);

		gi.WriteByte (svc_temp_entity);
		gi.WriteByte (TE_BUBBLETRAIL);
		gi.WritePosition (water_start);
		gi.WritePosition (tr.endpos);
		gi.multicast (pos, MULTICAST_PVS);
	}
}
开发者ID:kawika194,项目名称:q2src,代码行数:101,代码来源:g_weapon.c

示例11: func_explosive_objective_explode

/*
========================
func_explosive_objective
========================
*/
void func_explosive_objective_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
	vec3_t	origin;
	vec3_t	chunkorigin;
	vec3_t	size;
	int		count;
	int		mass;
	int		enemy;
	int		otherteam;

	//gi.dprintf(DEVELOPER_MSG_GAME, "self: %s\ninflictor: %s\n attacker: %s\n",
	//	self->classname, inflictor->classname, attacker->classname);

	if (!attacker->client ||
		!attacker->client->resp.mos)
		return;

	// bmodel origins are (0 0 0), we need to adjust that here
	VectorScale (self->size, 0.5, size);
	VectorAdd (self->absmin, size, origin);
	VectorCopy (origin, self->s.origin);

	self->takedamage = DAMAGE_NO;

	if (self->dmg)
		T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);

	VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
	VectorNormalize (self->velocity);
	VectorScale (self->velocity, 150, self->velocity);

	// start chunks towards the center
	VectorScale (size, 0.5, size);

	mass = self->mass;
	if (!mass)
		mass = 75;

	// big chunks
	if (mass >= 100)
	{
		count = mass / 100;
		if (count > 8)
			count = 8;
		while(count--)
		{
			chunkorigin[0] = origin[0] + crandom() * size[0];
			chunkorigin[1] = origin[1] + crandom() * size[1];
			chunkorigin[2] = origin[2] + crandom() * size[2];
			ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
		}
	}

	// small chunks
	count = mass / 25;
	if (count > 16)
		count = 16;
	while(count--)
	{
		chunkorigin[0] = origin[0] + crandom() * size[0];
		chunkorigin[1] = origin[1] + crandom() * size[1];
		chunkorigin[2] = origin[2] + crandom() * size[2];
		ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
	}

	G_UseTargets (self, attacker);

	// hack for 2 team games

	if (self->obj_owner != 99) {
		team_list[self->obj_owner]->score -= self->obj_loss;
		enemy = (self->obj_owner) ? 0 : 1;
	} else
		enemy = 99;

	if (self->obj_owner != attacker->client->resp.team_on->index)
		team_list[attacker->client->resp.team_on->index]->score += self->obj_gain;
	else if (self->obj_owner == attacker->client->resp.team_on->index && enemy != 99)
		team_list[enemy]->score += self->obj_gain;

	if (dedicated->value)
		safe_cprintf(NULL, PRINT_HIGH, "%s destroyed by %s [%s]\n", 
			self->obj_name, 
			attacker->client->pers.netname,
			team_list[attacker->client->resp.team_on->index]->teamname);

	centerprintall("%s destroyed by:\n\n%s\n%s",
		self->obj_name, 
		attacker->client->pers.netname,
		team_list[attacker->client->resp.team_on->index]->teamname);

	otherteam = (self->obj_owner+1)%2;
	if ((!team_list[otherteam]->kills_and_points && team_list[otherteam]->score < team_list[otherteam]->need_points) ||
	    (team_list[otherteam]->kills_and_points && team_list[otherteam]->kills < team_list[otherteam]->need_kills))
	  gi.sound(self, CHAN_NO_PHS_ADD, gi.soundindex(va("%s/objectives/touch_cap.wav", team_list[otherteam]->teamid)), 1, 0, 0);
//.........这里部分代码省略.........
开发者ID:basecq,项目名称:q2dos,代码行数:101,代码来源:g_objectives.c

示例12: bfg_explode

/*
=================
fire_bfg
=================
*/
void bfg_explode (edict_t *self)
{
	edict_t *ent;
	float points;
	vec3_t v;
	float dist;

	if (!self)
	{
		return;
	}

	if (self->s.frame == 0)
	{
		/* the BFG effect */
		ent = NULL;

		while ((ent = findradius(ent, self->s.origin, self->dmg_radius)) != NULL)
		{
			if (!ent->takedamage)
			{
				continue;
			}

			if (ent == self->owner)
			{
				continue;
			}

			if (!CanDamage(ent, self))
			{
				continue;
			}

			if (!CanDamage(ent, self->owner))
			{
				continue;
			}

			VectorAdd(ent->mins, ent->maxs, v);
			VectorMA(ent->s.origin, 0.5, v, v);
			VectorSubtract(self->s.origin, v, v);
			dist = VectorLength(v);
			points = self->radius_dmg * (1.0 - sqrt(dist / self->dmg_radius));

			if (ent == self->owner)
			{
				points = points * 0.5;
			}

			gi.WriteByte(svc_temp_entity);
			gi.WriteByte(TE_BFG_EXPLOSION);
			gi.WritePosition(ent->s.origin);
			gi.multicast(ent->s.origin, MULTICAST_PHS);
			T_Damage(ent, self, self->owner, self->velocity, ent->s.origin,
					vec3_origin, (int)points, 0, DAMAGE_ENERGY, MOD_BFG_EFFECT);
		}
	}

	self->nextthink = level.time + FRAMETIME;
	self->s.frame++;

	if (self->s.frame == 5)
	{
		self->think = G_FreeEdict;
	}
}
开发者ID:basecq,项目名称:q2dos,代码行数:72,代码来源:g_weapon.c

示例13: Grenade_Explode

/*
=================
fire_grenade
=================
*/
void Grenade_Explode (edict_t *ent)
{
	vec3_t origin;
	int mod;

	if (!ent)
	{
		return;
	}

	if (ent->owner->client)
	{
		PlayerNoise(ent->owner, ent->s.origin, PNOISE_IMPACT);
	}

	if (ent->enemy)
	{
		float points;
		vec3_t v;
		vec3_t dir;

		VectorAdd(ent->enemy->mins, ent->enemy->maxs, v);
		VectorMA(ent->enemy->s.origin, 0.5, v, v);
		VectorSubtract(ent->s.origin, v, v);
		points = ent->dmg - 0.5 * VectorLength(v);
		VectorSubtract(ent->enemy->s.origin, ent->s.origin, dir);

		if (ent->spawnflags & 1)
		{
			mod = MOD_HANDGRENADE;
		}
		else
		{
			mod = MOD_GRENADE;
		}

		T_Damage(ent->enemy, ent, ent->owner, dir, ent->s.origin, vec3_origin,
				(int)points, (int)points, DAMAGE_RADIUS, mod);
	}

	if (ent->spawnflags & 2)
	{
		mod = MOD_HELD_GRENADE;
	}
	else if (ent->spawnflags & 1)
	{
		mod = MOD_HG_SPLASH;
	}
	else
	{
		mod = MOD_G_SPLASH;
	}

	T_RadiusDamage(ent, ent->owner, ent->dmg, ent->enemy, ent->dmg_radius, mod);

	VectorMA(ent->s.origin, -0.02, ent->velocity, origin);
	gi.WriteByte(svc_temp_entity);

	if (ent->waterlevel)
	{
		if (ent->groundentity)
		{
			gi.WriteByte(TE_GRENADE_EXPLOSION_WATER);
		}
		else
		{
			gi.WriteByte(TE_ROCKET_EXPLOSION_WATER);
		}
	}
	else
	{
		if (ent->groundentity)
		{
			gi.WriteByte(TE_GRENADE_EXPLOSION);
		}
		else
		{
			gi.WriteByte(TE_ROCKET_EXPLOSION);
		}
	}

	gi.WritePosition(origin);
	gi.multicast(ent->s.origin, MULTICAST_PHS);

	G_FreeEdict(ent);
}
开发者ID:basecq,项目名称:q2dos,代码行数:91,代码来源:g_weapon.c

示例14: Trap_Think

// RAFAEL
void Trap_Think (edict_t *ent)
{
	edict_t	*target = NULL;
	edict_t	*best = NULL;
	vec3_t	vec;
	int		len, i;
	int		oldlen = 8000;
	vec3_t	forward, right, up;

	if (!ent)
	{
		return;
	}

	if (ent->timestamp < level.time)
	{
		BecomeExplosion1(ent);
		return;
	}

	ent->nextthink = level.time + 0.1;

	if (!ent->groundentity)
	{
		return;
	}

	/* ok lets do the blood effect */
	if (ent->s.frame > 4)
	{
		if (ent->s.frame == 5)
		{
			if (ent->wait == 64)
			{
				gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/trapdown.wav"),
					   	1, ATTN_IDLE, 0);
			}

			ent->wait -= 2;
			ent->delay += level.time;

			for (i = 0; i < 3; i++)
			{
				best = G_Spawn();

				if (strcmp(ent->enemy->classname, "monster_gekk") == 0)
				{
					best->s.modelindex = gi.modelindex("models/objects/gekkgib/torso/tris.md2");
					best->s.effects |= TE_GREENBLOOD;
				}
				else if (ent->mass > 200)
				{
					best->s.modelindex = gi.modelindex("models/objects/gibs/chest/tris.md2");
					best->s.effects |= TE_BLOOD;
				}
				else
				{
					best->s.modelindex = gi.modelindex("models/objects/gibs/sm_meat/tris.md2");
					best->s.effects |= TE_BLOOD;
				}

				AngleVectors(ent->s.angles, forward, right, up);

				RotatePointAroundVector(vec, up, right, ((360.0 / 3) * i) + ent->delay);
				VectorMA(vec, ent->wait / 2, vec, vec);
				VectorAdd(vec, ent->s.origin, vec);
				VectorAdd(vec, forward, best->s.origin);

				best->s.origin[2] = ent->s.origin[2] + ent->wait;

				VectorCopy(ent->s.angles, best->s.angles);

				best->solid = SOLID_NOT;
				best->s.effects |= EF_GIB;
				best->takedamage = DAMAGE_YES;

				best->movetype = MOVETYPE_TOSS;
				best->svflags |= SVF_MONSTER;
				best->deadflag = DEAD_DEAD;

				VectorClear(best->mins);
				VectorClear(best->maxs);

				best->watertype = gi.pointcontents(best->s.origin);

				if (best->watertype & MASK_WATER)
				{
					best->waterlevel = 1;
				}

				best->nextthink = level.time + 0.1;
				best->think = G_FreeEdict;
				gi.linkentity(best);
			}

			if (ent->wait < 19)
			{
				ent->s.frame++;
			}
//.........这里部分代码省略.........
开发者ID:basecq,项目名称:q2dos,代码行数:101,代码来源:g_weapon.c

示例15: SplitPolygon

void SplitPolygon(vec3_t *polygon,int *signs, int vnum, plane_t *plane, vec3_t *inpts, int *innum, vec3_t *outpts, int *outnum) {

    int out_c = 0;
    int in_c = 0;

    vec3_t *ptA = &polygon[vnum-1];
    vec3_t *ptB, v, newVert;
    int sideA = signs[vnum-1];
    int sideB;
    int i;
    float sect;

    for (i=0;  i<vnum; i++) {

        ptB = &polygon[i];
        sideB = signs[i];

        //is b on "right side"
        if (sideB == 2) {

            if (sideA == 1) {

                // compute the intersection point of the line
                // from point A to point B with the partition
                // plane. This is a simple ray-plane intersection.
                VectorSubtract ((*ptB), (*ptA), v);
                sect = - (DotProduct (plane->normal, (*ptA) )-plane->dist) /
                       DotProduct (plane->normal, v);
                VectorScale (v,sect,v);

                //add a new vertex
                VectorAdd ((*ptA), v, newVert);
                VectorCopy (newVert, inpts[in_c]);
                VectorCopy (newVert, outpts[out_c]);

                out_c++;
                in_c++;
            }
            VectorCopy (polygon[i], outpts[out_c]);
            out_c++;
        }
        //b is on "left" side
        else if (sideB ==1) {

            if (sideA == 2) {

                // compute the intersection point of the line
                // from point A to point B with the partition
                // plane. This is a simple ray-plane intersection.
                VectorSubtract ((*ptB), (*ptA), v);
                sect = - (DotProduct (plane->normal, (*ptA) )-plane->dist) /
                       DotProduct (plane->normal, v);
                VectorScale (v,sect,v);

                //add a new vertex
                VectorAdd ((*ptA), v, newVert);
                VectorCopy (newVert, inpts[in_c]);
                VectorCopy (newVert, outpts[out_c]);

                out_c++;
                in_c++;
            }
            VectorCopy (polygon[i], inpts[in_c]);
            in_c++;
        }
        //b is almost on plane
        else {

            VectorCopy (polygon[i], inpts[in_c]);
            VectorCopy (inpts[in_c], outpts[out_c]);
            in_c++;
            out_c++;
        }
        ptA = ptB;
        sideA = sideB;

        if ((out_c > MAX_POLY_VERT) || (in_c > MAX_POLY_VERT)) {
            Con_Printf ("MAX_POLY_VERT exceeded: %i %i\n", in_c, out_c);

            //just return what we've got
            (*innum) = in_c;
            (*outnum) = out_c;
            return;
        }
    }

    (*innum) = in_c;
    (*outnum) = out_c;
}
开发者ID:gnuzinho,项目名称:TenebraeQuake,代码行数:89,代码来源:gl_svbsp.c


注:本文中的VectorAdd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。