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


C++ DotProduct函数代码示例

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


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

示例1: sqrt

 double Vector2::Magnitude() const
 {
     return sqrt( DotProduct( *this ) );
 }
开发者ID:jpgaribotti,项目名称:libvector,代码行数:4,代码来源:Vector2.cpp

示例2: PM_DrawPhysEntBBox

/*
================
PM_DrawPhysEntBBox(int num)

================
*/
void PM_DrawPhysEntBBox(int num, int pcolor, float life)
{
	physent_t *pe;
	vec3_t     org;
	int        j;
	vec3_t     tmp;
	vec3_t     p[8];
	float      gap = BOX_GAP;
	vec3_t     modelmins, modelmaxs;

	if(num >= pmove->numphysent ||
	   num <= 0)
		return;

	pe = &pmove->physents[num];

	if(pe->model)
	{
		VectorCopy(pe->origin, org);

		pmove->PM_GetModelBounds(pe->model, modelmins, modelmaxs);
		for(j = 0; j < 8; j++)
		{
			tmp[0] = (j & 1) ? modelmins[0] - gap : modelmaxs[0] + gap;
			tmp[1] = (j & 2) ? modelmins[1] - gap : modelmaxs[1] + gap;
			tmp[2] = (j & 4) ? modelmins[2] - gap : modelmaxs[2] + gap;

			VectorCopy(tmp, p[j]);
		}

		// If the bbox should be rotated, do that
		if(pe->angles[0] || pe->angles[1] || pe->angles[2])
		{
			vec3_t forward, right, up;

			AngleVectorsTranspose(pe->angles, forward, right, up);
			for(j = 0; j < 8; j++)
			{
				VectorCopy(p[j], tmp);
				p[j][0] = DotProduct(tmp, forward);
				p[j][1] = DotProduct(tmp, right);
				p[j][2] = DotProduct(tmp, up);
			}
		}

		// Offset by entity origin, if any.
		for(j = 0; j < 8; j++)
			VectorAdd(p[j], org, p[j]);

		for(j = 0; j < 6; j++)
		{
			PM_DrawRectangle(
			    p[PM_boxpnt[j][1]],
			    p[PM_boxpnt[j][0]],
			    p[PM_boxpnt[j][2]],
			    p[PM_boxpnt[j][3]],
			    pcolor, life);
		}
	}
	else
	{
		for(j = 0; j < 8; j++)
		{
			tmp[0] = (j & 1) ? pe->mins[0] : pe->maxs[0];
			tmp[1] = (j & 2) ? pe->mins[1] : pe->maxs[1];
			tmp[2] = (j & 4) ? pe->mins[2] : pe->maxs[2];

			VectorAdd(tmp, pe->origin, tmp);
			VectorCopy(tmp, p[j]);
		}

		for(j = 0; j < 6; j++)
		{
			PM_DrawRectangle(
			    p[PM_boxpnt[j][1]],
			    p[PM_boxpnt[j][0]],
			    p[PM_boxpnt[j][2]],
			    p[PM_boxpnt[j][3]],
			    pcolor, life);
		}
	}
}
开发者ID:Sh1ft0x0EF,项目名称:HLSDKRevamp,代码行数:88,代码来源:pm_debug.c

示例3: SV_Physics_Toss


//.........这里部分代码省略.........
	}

	SV_CheckVelocity( ent );

	// add gravity
	switch( ent->v.movetype )
	{
	case MOVETYPE_FLY:
	case MOVETYPE_FLYMISSILE:
	case MOVETYPE_BOUNCEMISSILE:
		break;
	default:
		SV_AddGravity( ent );
		break;
	}

	// move angles (with friction)
	switch( ent->v.movetype )
	{
	case MOVETYPE_TOSS:
	case MOVETYPE_BOUNCE:
		SV_AngularMove( ent, host.frametime, ent->v.friction );
		break;         
	default:
		SV_AngularMove( ent, host.frametime, 0.0f );
		break;
	}

	// move origin
	// Base velocity is not properly accounted for since this entity will move again
	// after the bounce without taking it into account
	VectorAdd( ent->v.velocity, ent->v.basevelocity, ent->v.velocity );

	SV_CheckVelocity( ent );
	VectorScale( ent->v.velocity, host.frametime, move );

	VectorSubtract( ent->v.velocity, ent->v.basevelocity, ent->v.velocity );

	trace = SV_PushEntity( ent, move, vec3_origin, NULL );
	if( ent->free ) return;

	SV_CheckVelocity( ent );

	if( trace.allsolid )
	{
		// entity is trapped in another solid
		VectorClear( ent->v.avelocity );
		VectorClear( ent->v.velocity );
		return;
	}

	if( trace.fraction == 1.0f )
	{
		SV_CheckWaterTransition( ent );
		return;
	}

	if( ent->v.movetype == MOVETYPE_BOUNCE )
		backoff = 2.0f - ent->v.friction;
	else if( ent->v.movetype == MOVETYPE_BOUNCEMISSILE )
		backoff = 2.0f;
	else backoff = 1.0f;

	SV_ClipVelocity( ent->v.velocity, trace.plane.normal, ent->v.velocity, backoff );

	// stop if on ground
	if( trace.plane.normal[2] > 0.7f )
	{		
		float	vel;

		VectorAdd( ent->v.velocity, ent->v.basevelocity, move );
		vel = DotProduct( move, move );

		if( ent->v.velocity[2] < sv_gravity->value * host.frametime )
		{
			// we're rolling on the ground, add static friction.
			ent->v.groundentity = trace.ent;
			ent->v.flags |= FL_ONGROUND;
			ent->v.velocity[2] = 0.0f;
		}

		if( vel < 900.0f || ( ent->v.movetype != MOVETYPE_BOUNCE && ent->v.movetype != MOVETYPE_BOUNCEMISSILE ))
		{
			ent->v.flags |= FL_ONGROUND;
			ent->v.groundentity = trace.ent;
			VectorClear( ent->v.avelocity );
			VectorClear( ent->v.velocity );
		}
		else
		{
			VectorScale( ent->v.velocity, (1.0f - trace.fraction) * host.frametime * 0.9f, move );
			VectorMA( move, (1.0f - trace.fraction) * host.frametime * 0.9f, ent->v.basevelocity, move );
			trace = SV_PushEntity( ent, move, vec3_origin, NULL );
			if( ent->free ) return;
		}
	}
	
	// check for in water
	SV_CheckWaterTransition( ent );
}
开发者ID:Fograin,项目名称:hl-subsmod-ex,代码行数:101,代码来源:sv_phys.c

示例4: StudioFrameAdvance

//=========================================================
// Hornet is flying, gently tracking target
//=========================================================
void CHornet::TrackTarget(void)
{
	Vector	vecFlightDir;
	Vector	vecDirToEnemy;
	float	flDelta;

	StudioFrameAdvance();

	if (gpGlobals->time > m_flStopAttack)
	{
		SetTouch(NULL);
		SetThink(&CHornet::SUB_Remove);
		SetNextThink(0.1);
		return;
	}

	// UNDONE: The player pointer should come back after returning from another level
	if (m_hEnemy == NULL)
	{// enemy is dead.
		Look(512);
		m_hEnemy = BestVisibleEnemy();
	}

	if (m_hEnemy != NULL && FVisible(m_hEnemy))
	{
		m_vecEnemyLKP = m_hEnemy->BodyTarget(pev->origin);
	}
	else
	{
		m_vecEnemyLKP = m_vecEnemyLKP + pev->velocity * m_flFlySpeed * 0.1;
	}

	vecDirToEnemy = (m_vecEnemyLKP - pev->origin).Normalize();

	if (pev->velocity.Length() < 0.1)
		vecFlightDir = vecDirToEnemy;
	else
		vecFlightDir = pev->velocity.Normalize();

	// measure how far the turn is, the wider the turn, the slow we'll go this time.
	flDelta = DotProduct(vecFlightDir, vecDirToEnemy);

	if (flDelta < 0.5)
	{// hafta turn wide again. play sound
		switch (RANDOM_LONG(0, 2))
		{
		case 0:	EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM);	break;
		case 1:	EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM);	break;
		case 2:	EMIT_SOUND(ENT(pev), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM);	break;
		}
	}

	if (flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED)
	{// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far.
		flDelta = 0.25;
	}

	pev->velocity = (vecFlightDir + vecDirToEnemy).Normalize();

	if (pev->owner && (pev->owner->v.flags & FL_MONSTER))
	{
		// random pattern only applies to hornets fired by monsters, not players. 

		pev->velocity.x += RANDOM_FLOAT(-0.10, 0.10);// scramble the flight dir a bit.
		pev->velocity.y += RANDOM_FLOAT(-0.10, 0.10);
		pev->velocity.z += RANDOM_FLOAT(-0.10, 0.10);
	}

	switch (m_iHornetType)
	{
	case HORNET_TYPE_RED:
		pev->velocity = pev->velocity * (m_flFlySpeed * flDelta);// scale the dir by the ( speed * width of turn )
		SetNextThink(RANDOM_FLOAT(0.1, 0.3));
		break;
	case HORNET_TYPE_ORANGE:
		pev->velocity = pev->velocity * m_flFlySpeed;// do not have to slow down to turn.
		SetNextThink(0.1);// fixed think time
		break;
	}

	pev->angles = UTIL_VecToAngles(pev->velocity);

	pev->solid = SOLID_BBOX;

	// if hornet is close to the enemy, jet in a straight line for a half second.
	// (only in the single player game)
	if (m_hEnemy != NULL && !g_pGameRules->IsMultiplayer())
	{
		if (flDelta >= 0.4 && (pev->origin - m_vecEnemyLKP).Length() <= 300)
		{
			MESSAGE_BEGIN(MSG_PVS, SVC_TEMPENTITY, pev->origin);
			WRITE_BYTE(TE_SPRITE);
			WRITE_COORD(pev->origin.x);	// pos
			WRITE_COORD(pev->origin.y);
			WRITE_COORD(pev->origin.z);
			WRITE_SHORT(iHornetPuff);		// model
			// WRITE_BYTE( 0 );				// life * 10
//.........这里部分代码省略.........
开发者ID:Hammermaps-DEV,项目名称:Spirit-of-Half-Life-1.9--VC2010,代码行数:101,代码来源:hornet.cpp

示例5: MakeRGBScales


//.........这里部分代码省略.........
						, transparency
	#endif
						) || (i==j))
					{
						continue;
					}
					useback = true;
				}
				else
				{
					continue;
				}
#else
                continue;
#endif
            }

            normal2 = getPlaneFromFaceNumber(patch2->faceNumber)->normal;

            // calculate transferemnce
            VectorSubtract(patch2->origin, origin, delta);
#ifdef HLRAD_TRANSLUCENT
			if (useback)
			{
				VectorSubtract (patch2->origin, backorigin, delta);
			}
#endif
#ifdef HLRAD_ACCURATEBOUNCE
			// move emitter back to its plane
			VectorMA (delta, -PATCH_HUNT_OFFSET, normal2, delta);
#endif

            dist = VectorNormalize(delta);
            dot1 = DotProduct(delta, normal1);
#ifdef HLRAD_TRANSLUCENT
			if (useback)
			{
				dot1 = DotProduct (delta, backnormal);
			}
#endif
            dot2 = -DotProduct(delta, normal2);
#ifdef HLRAD_ACCURATEBOUNCE
#ifdef HLRAD_ACCURATEBOUNCE_ALTERNATEORIGIN
			bool light_behind_surface = false;
			if (dot1 <= NORMAL_EPSILON)
			{
				light_behind_surface = true;
			}
#else
			if (dot1 <= NORMAL_EPSILON)
			{
				continue;
			}
#endif
			if (dot2 * dist <= MINIMUM_PATCH_DISTANCE)
			{
				continue;
			}
#endif
			
#ifdef HLRAD_DIVERSE_LIGHTING
			if (lighting_diversify
	#ifdef HLRAD_ACCURATEBOUNCE_ALTERNATEORIGIN
				&& !light_behind_surface
	#endif
				)
开发者ID:emileb,项目名称:XashXT,代码行数:67,代码来源:vismatrixutil.cpp

示例6: CONPRINT

// draws this grass particle
//extern void RenderFog ( void );	// Fograin92: Disabled
void CGrassParticle::Draw( void )
{
	if (m_bIngoreParticle == true)
		return;

	if(sParticle.pTexture == NULL) {
		CONPRINT("Null texture in particle\n");
		return;
	}

	Vector vForward, vRight, vUp, vDir;
	AngleVectors(v_angles, vForward, vRight, vUp );
	vDir = ( sParticle.vPosition - flPlayerOrigin ).Normalize( );
	if ( DotProduct ( vDir, vForward ) < 0 )
		return;

	int iHealth = 0;

	// lets make sure transparency doesn't overflow or udnerflow
	if (sParticle.iTransparency > 255)
		sParticle.iTransparency = 255;
	if (sParticle.iTransparency < 0)
		sParticle.iTransparency = 0;
	iHealth = sParticle.iTransparency;

	if (pSys->bLOD) // fade out particles that are further away (LOD)
	{
		float flDistance = sqrt(sParticle.flSquareDistanceToPlayer);
		if ((flDistance > m_flLodMinDistance) && (flDistance < m_flLodMaxDistance))
		{
			float flTransparencyFactor = 1 - ((flDistance - m_flLodMinDistance) / (m_flLodMaxDistance - m_flLodMinDistance));
				
			if (flTransparencyFactor > 1)
				flTransparencyFactor = 1;
			if (flTransparencyFactor < 0)
				flTransparencyFactor = 0;
			iHealth *= flTransparencyFactor;
		}
	}

	vec3_t vPoint, vPosition;
	vec3_t vWaveForward, vWaveRight, vWaveUp;

	// We again copy part->origin into another vector to prevent us accidentally messing with it
	VectorCopy( sParticle.vPosition, vPosition );

	AngleVectors(m_vNormal, vForward, vRight, vUp);
	AngleVectors(m_vWaveNormal, vWaveForward, vWaveRight, vWaveUp);

	glColor4ub(sParticle.iRed, sParticle.iGreen, sParticle.iBlue,iHealth);  

	//RenderFog();	// Fograin92: Disabled

	// Finally, we draw the particle
	glBindTexture(GL_TEXTURE_2D, sParticle.pTexture->iID);
	glBegin(GL_QUADS);

	glTexCoord2f(0, 0.95f);
	VectorMA (sParticle.vPosition, sParticle.flSize, vWaveUp, vPoint);
	VectorMA (vPoint, -sParticle.flSize, vWaveRight, vPoint);
	glVertex3fv(vPoint); 

	glTexCoord2f(0.95f, 0.95f); 
	VectorMA (sParticle.vPosition, sParticle.flSize, vWaveUp, vPoint);
	VectorMA (vPoint, sParticle.flSize, vWaveRight, vPoint);
	glVertex3fv(vPoint);

	glTexCoord2f(0.95f, 0);
	VectorMA (sParticle.vPosition, -sParticle.flSize, vUp, vPoint);
	VectorMA (vPoint, sParticle.flSize, vRight, vPoint);
	glVertex3fv(vPoint);

	glTexCoord2f(0, 0);
	VectorMA (sParticle.vPosition, -sParticle.flSize, vUp, vPoint);
	VectorMA (vPoint, -sParticle.flSize, vRight, vPoint);
	glVertex3fv(vPoint); 
   
	glEnd();
}
开发者ID:Hammermaps-DEV,项目名称:SOHL-V1.9-Opposing-Force-Edition,代码行数:81,代码来源:grass_particle.cpp

示例7: R_RecursiveClipBPoly

void R_RecursiveClipBPoly (bedge_t *pedges, mnode_t *pnode, msurface_t *psurf) {
	bedge_t *psideedges[2], *pnextedge, *ptedge;
	int i, side, lastside;
	float dist, frac, lastdist;
	mplane_t *splitplane, tplane;
	mvertex_t *pvert, *plastvert, *ptvert;
	mnode_t *pn;

	psideedges[0] = psideedges[1] = NULL;

	makeclippededge = false;

	// transform the BSP plane into model space
	// FIXME: cache these?
	splitplane = pnode->plane;
	tplane.dist = -PlaneDiff(r_entorigin, splitplane);
	tplane.normal[0] = PlaneDist (entity_rotation[0], splitplane);
	tplane.normal[1] = PlaneDist (entity_rotation[1], splitplane);
	tplane.normal[2] = PlaneDist (entity_rotation[2], splitplane);

	// clip edges to BSP plane
	for ( ; pedges ; pedges = pnextedge) {
		pnextedge = pedges->pnext;

		// set the status for the last point as the previous point
		// FIXME: cache this stuff somehow?
		plastvert = pedges->v[0];
		
		lastdist = DotProduct (plastvert->position, tplane.normal) - tplane.dist;
		lastside = (lastdist <= 0);

		pvert = pedges->v[1];
		
		dist = DotProduct (pvert->position, tplane.normal) - tplane.dist;
		side = (dist <= 0);

		if (side != lastside) {
			// clipped
			if (numbverts >= MAX_BMODEL_VERTS)
				return;

			// generate the clipped vertex
			frac = lastdist / (lastdist - dist);
			ptvert = &pbverts[numbverts++];
			ptvert->position[0] = plastvert->position[0] + frac * (pvert->position[0] -	plastvert->position[0]);
			ptvert->position[1] = plastvert->position[1] + frac * (pvert->position[1] - plastvert->position[1]);
			ptvert->position[2] = plastvert->position[2] + frac * (pvert->position[2] - plastvert->position[2]);

			// split into two edges, one on each side, and remember entering
			// and exiting points
			// FIXME: share the clip edge by having a winding direction flag?
			if (numbedges >= (MAX_BMODEL_EDGES - 1)) {
				Com_Printf ("Out of edges for bmodel\n");
				return;
			}

			ptedge = &pbedges[numbedges];
			ptedge->pnext = psideedges[lastside];
			psideedges[lastside] = ptedge;
			ptedge->v[0] = plastvert;
			ptedge->v[1] = ptvert;

			ptedge = &pbedges[numbedges + 1];
			ptedge->pnext = psideedges[side];
			psideedges[side] = ptedge;
			ptedge->v[0] = ptvert;
			ptedge->v[1] = pvert;

			numbedges += 2;

			if (side == 0) {
				// entering for front, exiting for back
				pfrontenter = ptvert;
				makeclippededge = true;
			} else {
				pfrontexit = ptvert;
				makeclippededge = true;
			}
		} else {
			// add the edge to the appropriate side
			pedges->pnext = psideedges[side];
			psideedges[side] = pedges;
		}
	}

	// if anything was clipped, reconstitute and add the edges along the clip
	// plane to both sides (but in opposite directions)
	if (makeclippededge) {
		if (numbedges >= (MAX_BMODEL_EDGES - 2)) {
			Com_Printf ("Out of edges for bmodel\n");
			return;
		}

		ptedge = &pbedges[numbedges];
		ptedge->pnext = psideedges[0];
		psideedges[0] = ptedge;
		ptedge->v[0] = pfrontexit;
		ptedge->v[1] = pfrontenter;

		ptedge = &pbedges[numbedges + 1];
//.........这里部分代码省略.........
开发者ID:AAS,项目名称:ezquake-source,代码行数:101,代码来源:r_bsp.c

示例8: R_DrawAliasFrameLerp

/*
=================
R_DrawAliasFrameLerp
=================
*/
void R_DrawAliasFrameLerp (maliasmodel_t *paliashdr, entity_t *e)
{
	int			i, j, k, meshnum;
	maliasframe_t	*frame, *oldframe;
	maliasmesh_t	mesh;
	maliasvertex_t	*v, *ov;
	vec3_t		move, delta, vectors[3];
	vec3_t		curScale, oldScale, curNormal, oldNormal;
	vec3_t		tempNormalsArray[MD3_MAX_VERTS];
	vec2_t		tempSkinCoord;
	vec3_t		meshlight, lightcolor;
	float		alpha, meshalpha, thisalpha, shellscale, frontlerp, backlerp = e->backlerp;
	image_t		*skin;
	renderparms_t	skinParms;
	qboolean	shellModel = e->flags & ( RF_SHELL_RED | RF_SHELL_GREEN | RF_SHELL_BLUE | RF_SHELL_DOUBLE | RF_SHELL_HALF_DAM);

	frontlerp = 1.0 - backlerp;

	if (e->flags & RF_TRANSLUCENT)
		alpha = e->alpha;
	else
		alpha = 1.0;

	frame = paliashdr->frames + e->frame;
	oldframe = paliashdr->frames + e->oldframe;

	VectorScale(frame->scale, frontlerp, curScale);
	VectorScale(oldframe->scale, backlerp, oldScale);

	// move should be the delta back to the previous frame * backlerp
	VectorSubtract (e->oldorigin, e->origin, delta);
	AngleVectors (e->angles, vectors[0], vectors[1], vectors[2]);

	move[0] = DotProduct (delta, vectors[0]);	// forward
	move[1] = -DotProduct (delta, vectors[1]);	// left
	move[2] = DotProduct (delta, vectors[2]);	// up

	VectorAdd (move, oldframe->translate, move);

	for (i=0 ; i<3 ; i++)
		move[i] = backlerp*move[i] + frontlerp*frame->translate[i];

	R_SetVertexOverbrights(true);
	R_SetShellBlend (true);

	// new outer loop for whole model
	for (k=0, meshnum=0; k < paliashdr->num_meshes; k++, meshnum++)
	{
		mesh = paliashdr->meshes[k];
		skinParms = mesh.skins[e->skinnum].renderparms;

		// select skin
		if (e->skin)
			skin = e->skin;	// custom player skin
		else
			skin = currentmodel->skins[k][e->skinnum];
		if (!skin)
			skin = r_notexture;
		if ( !shellModel )
			GL_Bind(skin->texnum);
		else if (FlowingShell())
			alpha = 0.7;

		// md3 skin scripting
		if (skinParms.nodraw) 
			continue; // skip this mesh for this skin

		if (skinParms.twosided)
			GL_Disable(GL_CULL_FACE);

		if (skinParms.alphatest && !shellModel)
			GL_Enable(GL_ALPHA_TEST);

		if (skinParms.fullbright)
			VectorSet(meshlight, 1.0f, 1.0f, 1.0f);
		else
			VectorCopy(shadelight, meshlight);

		meshalpha = alpha * skinParms.basealpha;

		if (meshalpha < 1.0f || skinParms.blend)
			GL_Enable (GL_BLEND);
		else
			GL_Disable (GL_BLEND);

		if (skinParms.blend && !shellModel)
			GL_BlendFunc (skinParms.blendfunc_src, skinParms.blendfunc_dst);
		else
			GL_BlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		// md3 skin scripting

		v = mesh.vertexes + e->frame*mesh.num_verts;
		ov = mesh.vertexes + e->oldframe*mesh.num_verts;
		rb_vertex = 0;

//.........这里部分代码省略.........
开发者ID:ptitSeb,项目名称:gravitybone-pandora,代码行数:101,代码来源:r_alias.c

示例9: RB_BeginDrawingView

/*
=================
RB_BeginDrawingView

Any mirrored or portaled views have already been drawn, so prepare
to actually render the visible surfaces for this view
=================
*/
void RB_BeginDrawingView (void) {
	int clearBits = 0;

	// sync with gl if needed
	if ( r_finish->integer == 1 && !glState.finishCalled ) {
		qglFinish ();
		glState.finishCalled = qtrue;
	}
	if ( r_finish->integer == 0 ) {
		glState.finishCalled = qtrue;
	}

	// we will need to change the projection matrix before drawing
	// 2D images again
	backEnd.projection2D = qfalse;

	//
	// set the modelview matrix for the viewer
	//
	SetViewportAndScissor();

	// ensures that depth writes are enabled for the depth clear
	GL_State( GLS_DEFAULT );
	// clear relevant buffers
	clearBits = GL_DEPTH_BUFFER_BIT;

	if ( r_measureOverdraw->integer || r_shadows->integer == 2 )
	{
		clearBits |= GL_STENCIL_BUFFER_BIT;
	}
	if ( r_fastsky->integer && !( backEnd.refdef.rdflags & RDF_NOWORLDMODEL ) )
	{
		clearBits |= GL_COLOR_BUFFER_BIT;	// FIXME: only if sky shaders have been used
#ifdef _DEBUG
		qglClearColor( 0.8f, 0.7f, 0.4f, 1.0f );	// FIXME: get color of sky
#else
		qglClearColor( 0.0f, 0.0f, 0.0f, 1.0f );	// FIXME: get color of sky
#endif
	}
	qglClear( clearBits );

	if ( ( backEnd.refdef.rdflags & RDF_HYPERSPACE ) )
	{
		RB_Hyperspace();
		return;
	}
	else
	{
		backEnd.isHyperspace = qfalse;
	}

	glState.faceCulling = -1;		// force face culling to set next time

	// we will only draw a sun if there was sky rendered in this view
	backEnd.skyRenderedThisView = qfalse;

	// clip to the plane of the portal
	if ( backEnd.viewParms.isPortal ) {
		float	plane[4];
#ifdef IOS
		float		plane2[4];
#else
		double	plane2[4];
#endif // IOS

		plane[0] = backEnd.viewParms.portalPlane.normal[0];
		plane[1] = backEnd.viewParms.portalPlane.normal[1];
		plane[2] = backEnd.viewParms.portalPlane.normal[2];
		plane[3] = backEnd.viewParms.portalPlane.dist;

		plane2[0] = DotProduct (backEnd.viewParms.or.axis[0], plane);
		plane2[1] = DotProduct (backEnd.viewParms.or.axis[1], plane);
		plane2[2] = DotProduct (backEnd.viewParms.or.axis[2], plane);
		plane2[3] = DotProduct (plane, backEnd.viewParms.or.origin) - plane[3];

		qglLoadMatrixf( s_flipMatrix );
		qglClipPlane (GL_CLIP_PLANE0, plane2);
		qglEnable (GL_CLIP_PLANE0);
	} else {
		qglDisable (GL_CLIP_PLANE0);
	}
}
开发者ID:he110world,项目名称:quake3-ios,代码行数:90,代码来源:tr_backend.c

示例10: ShortestLineSegBewteen2LineSegs

float ShortestLineSegBewteen2LineSegs( vec3_t start1, vec3_t end1, vec3_t start2, vec3_t end2, vec3_t close_pnt1, vec3_t close_pnt2 )
{
	float	current_dist, new_dist;
	vec3_t	new_pnt;
	//start1, end1 : the first segment
	//start2, end2 : the second segment

	//output, one point on each segment, the closest two points on the segments.

	//compute some temporaries:
	//vec start_dif = start2 - start1
	vec3_t	start_dif;
	VectorSubtract( start2, start1, start_dif );
	//vec v1 = end1 - start1
	vec3_t	v1;
	VectorSubtract( end1, start1, v1 );
	//vec v2 = end2 - start2
	vec3_t	v2;
	VectorSubtract( end2, start2, v2 );
	//
	float v1v1 = DotProduct( v1, v1 );
	float v2v2 = DotProduct( v2, v2 );
	float v1v2 = DotProduct( v1, v2 );

	//the main computation

	float denom = (v1v2 * v1v2) - (v1v1 * v2v2);

	//if denom is small, then skip all this and jump to the section marked below
	if ( fabs(denom) > 0.001f )
	{
		float s = -( (v2v2*DotProduct( v1, start_dif )) - (v1v2*DotProduct( v2, start_dif )) ) / denom;
		float t = ( (v1v1*DotProduct( v2, start_dif )) - (v1v2*DotProduct( v1, start_dif )) ) / denom;
		qboolean done = qtrue;

		if ( s < 0 )
		{
			done = qfalse;
			s = 0;// and see note below
		}

		if ( s > 1 ) 
		{
			done = qfalse;
			s = 1;// and see note below
		}

		if ( t < 0 ) 
		{
			done = qfalse;
			t = 0;// and see note below
		}

		if ( t > 1 ) 
		{
			done = qfalse;
			t = 1;// and see note below
		}

		//vec close_pnt1 = start1 + s * v1
		VectorMA( start1, s, v1, close_pnt1 );
		//vec close_pnt2 = start2 + t * v2
		VectorMA( start2, t, v2, close_pnt2 );

		current_dist = Distance( close_pnt1, close_pnt2 );
		//now, if none of those if's fired, you are done. 
		if ( done )
		{
			return current_dist;
		}
		//If they did fire, then we need to do some additional tests.

		//What we are gonna do is see if we can find a shorter distance than the above
		//involving the endpoints.
	}
	else
	{
		//******start here for paralell lines with current_dist = infinity****
		current_dist = Q3_INFINITE;
	}

	//test 2 close_pnts first
	/*
	G_FindClosestPointOnLineSegment( start1, end1, close_pnt2, new_pnt );
	new_dist = Distance( close_pnt2, new_pnt );
	if ( new_dist < current_dist )
	{//then update close_pnt1 close_pnt2 and current_dist
		VectorCopy( new_pnt, close_pnt1 );
		VectorCopy( close_pnt2, close_pnt2 );
		current_dist = new_dist;
	}

	G_FindClosestPointOnLineSegment( start2, end2, close_pnt1, new_pnt );
	new_dist = Distance( close_pnt1, new_pnt );
	if ( new_dist < current_dist )
	{//then update close_pnt1 close_pnt2 and current_dist
		VectorCopy( close_pnt1, close_pnt1 );
		VectorCopy( new_pnt, close_pnt2 );
		current_dist = new_dist;
	}
//.........这里部分代码省略.........
开发者ID:BishopExile,项目名称:OpenJK,代码行数:101,代码来源:tri_coll_test.cpp

示例11: R_CullAliasModel

/*
=================
R_CullAliasModel
=================
*/
static qboolean R_CullAliasModel ( vec3_t bbox[8], entity_t *e )
{
	int			i, j;
	vec3_t		mins, maxs, tmp; //angles;
	vec3_t		vectors[3];
	maliasmodel_t	*paliashdr;
	maliasframe_t	*pframe, *poldframe;
	int			mask, aggregatemask = ~0;			

	paliashdr = (maliasmodel_t *)currentmodel->extradata;

	if ( ( e->frame >= paliashdr->num_frames ) || ( e->frame < 0 ) )
	{
		VID_Printf (PRINT_ALL, "R_CullAliasModel %s: no such frame %d\n", 
			currentmodel->name, e->frame);
		e->frame = 0;
	}
	if ( ( e->oldframe >= paliashdr->num_frames ) || ( e->oldframe < 0 ) )
	{
		VID_Printf (PRINT_ALL, "R_CullAliasModel %s: no such oldframe %d\n", 
			currentmodel->name, e->oldframe);
		e->oldframe = 0;
	}

	pframe = paliashdr->frames + e->frame;
	poldframe = paliashdr->frames + e->oldframe;

	// compute axially aligned mins and maxs
	if ( pframe == poldframe )
	{
		VectorCopy(pframe->mins, mins);
		VectorCopy(pframe->maxs, maxs);
	}
	else
	{
		for ( i = 0; i < 3; i++ )
		{
			if (pframe->mins[i] < poldframe->mins[i])
				mins[i] = pframe->mins[i];
			else
				mins[i] = poldframe->mins[i];

			if (pframe->maxs[i] > poldframe->maxs[i])
				maxs[i] = pframe->maxs[i];
			else
				maxs[i] = poldframe->maxs[i];
		}
	}

	// jitspoe's bbox rotation fix
	// compute and rotate bonding box
	e->angles[ROLL] = -e->angles[ROLL]; // roll is backwards
	AngleVectors(e->angles, vectors[0], vectors[1], vectors[2]);
	e->angles[ROLL] = -e->angles[ROLL]; // roll is backwards
	VectorSubtract(vec3_origin, vectors[1], vectors[1]); // AngleVectors returns "right" instead of "left"
	for (i = 0; i < 8; i++)
	{
		tmp[0] = ((i & 1) ? mins[0] : maxs[0]);
		tmp[1] = ((i & 2) ? mins[1] : maxs[1]);
		tmp[2] = ((i & 4) ? mins[2] : maxs[2]);

		bbox[i][0] = vectors[0][0] * tmp[0] + vectors[1][0] * tmp[1] + vectors[2][0] * tmp[2] + e->origin[0];
		bbox[i][1] = vectors[0][1] * tmp[0] + vectors[1][1] * tmp[1] + vectors[2][1] * tmp[2] + e->origin[1];
		bbox[i][2] = vectors[0][2] * tmp[0] + vectors[1][2] * tmp[1] + vectors[2][2] * tmp[2] + e->origin[2];
	}

	// cull
	for (i=0; i<8; i++)
	{
		mask = 0;
		for (j=0; j<4; j++)
		{
			float dp = DotProduct(frustum[j].normal, bbox[i]);
			if ( ( dp - frustum[j].dist ) < 0 )
				mask |= (1<<j);
		}

		aggregatemask &= mask;
	}

	if ( aggregatemask )
		return true;

	return false;
}
开发者ID:ptitSeb,项目名称:gravitybone-pandora,代码行数:90,代码来源:r_alias.c

示例12: VPROF_BUDGET

//-----------------------------------------------------------------------------
// Purpose: Do the headlight
//-----------------------------------------------------------------------------
void CFlashlightEffect::UpdateLightNew(const Vector &vecPos, const Vector &vecForward, const Vector &vecRight, const Vector &vecUp)
{
    VPROF_BUDGET("CFlashlightEffect::UpdateLightNew", VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING);

    FlashlightState_t state;

    // We will lock some of the flashlight params if player is on a ladder, to prevent oscillations due to the trace-rays
    bool bPlayerOnLadder = (C_BasePlayer::GetLocalPlayer()->GetMoveType() == MOVETYPE_LADDER);

    const float flEpsilon = 0.1f;			// Offset flashlight position along vecUp
    const float flDistCutoff = 128.0f;
    const float flDistDrag = 0.2;

    CTraceFilterSkipPlayerAndViewModel traceFilter;
    float flOffsetY = r_flashlightoffsety.GetFloat();

    if (r_swingflashlight.GetBool())
    {
        // This projects the view direction backwards, attempting to raise the vertical
        // offset of the flashlight, but only when the player is looking down.
        Vector vecSwingLight = vecPos + vecForward * -12.0f;
        if (vecSwingLight.z > vecPos.z)
        {
            flOffsetY += (vecSwingLight.z - vecPos.z);
        }
    }

    Vector vOrigin = vecPos + flOffsetY * vecUp;

    // Not on ladder...trace a hull
    if (!bPlayerOnLadder)
    {
        trace_t pmOriginTrace;
        UTIL_TraceHull(vecPos, vOrigin, Vector(-4, -4, -4), Vector(4, 4, 4), MASK_SOLID & ~(CONTENTS_HITBOX), &traceFilter, &pmOriginTrace);

        if (pmOriginTrace.DidHit())
        {
            vOrigin = vecPos;
        }
    }
    else // on ladder...skip the above hull trace
    {
        vOrigin = vecPos;
    }

    // Now do a trace along the flashlight direction to ensure there is nothing within range to pull back from
    int iMask = MASK_OPAQUE_AND_NPCS;
    iMask &= ~CONTENTS_HITBOX;
    iMask |= CONTENTS_WINDOW;

    Vector vTarget = vecPos + vecForward * r_flashlightfar.GetFloat();

    // Work with these local copies of the basis for the rest of the function
    Vector vDir = vTarget - vOrigin;
    Vector vRight = vecRight;
    Vector vUp = vecUp;
    VectorNormalize(vDir);
    VectorNormalize(vRight);
    VectorNormalize(vUp);

    // Orthonormalize the basis, since the flashlight texture projection will require this later...
    vUp -= DotProduct(vDir, vUp) * vDir;
    VectorNormalize(vUp);
    vRight -= DotProduct(vDir, vRight) * vDir;
    VectorNormalize(vRight);
    vRight -= DotProduct(vUp, vRight) * vUp;
    VectorNormalize(vRight);

    AssertFloatEquals(DotProduct(vDir, vRight), 0.0f, 1e-3);
    AssertFloatEquals(DotProduct(vDir, vUp), 0.0f, 1e-3);
    AssertFloatEquals(DotProduct(vRight, vUp), 0.0f, 1e-3);

    trace_t pmDirectionTrace;
    UTIL_TraceHull(vOrigin, vTarget, Vector(-4, -4, -4), Vector(4, 4, 4), iMask, &traceFilter, &pmDirectionTrace);

    if (r_flashlightvisualizetrace.GetBool() == true)
    {
        debugoverlay->AddBoxOverlay(pmDirectionTrace.endpos, Vector(-4, -4, -4), Vector(4, 4, 4), QAngle(0, 0, 0), 0, 0, 255, 16, 0);
        debugoverlay->AddLineOverlay(vOrigin, pmDirectionTrace.endpos, 255, 0, 0, false, 0);
    }

    float flDist = (pmDirectionTrace.endpos - vOrigin).Length();
    if (flDist < flDistCutoff)
    {
        // We have an intersection with our cutoff range
        // Determine how far to pull back, then trace to see if we are clear
        float flPullBackDist = bPlayerOnLadder ? r_flashlightladderdist.GetFloat() : flDistCutoff - flDist;	// Fixed pull-back distance if on ladder
        m_flDistMod = Lerp(flDistDrag, m_flDistMod, flPullBackDist);

        if (!bPlayerOnLadder)
        {
            trace_t pmBackTrace;
            UTIL_TraceHull(vOrigin, vOrigin - vDir*(flPullBackDist - flEpsilon), Vector(-4, -4, -4), Vector(4, 4, 4), iMask, &traceFilter, &pmBackTrace);
            if (pmBackTrace.DidHit())
            {
                // We have an intersection behind us as well, so limit our m_flDistMod
                float flMaxDist = (pmBackTrace.endpos - vOrigin).Length() - flEpsilon;
//.........这里部分代码省略.........
开发者ID:Yosam02,项目名称:game,代码行数:101,代码来源:flashlighteffect.cpp

示例13: CG_DamageFeedback

/*
==============
CG_DamageFeedback
==============
*/
void CG_DamageFeedback( int yawByte, int pitchByte, int damage ) {
	float		left, front, up;
	float		kick;
	int			health;
	float		scale;
	vec3_t		dir;
	vec3_t		angles;
	float		dist;
	float		yaw, pitch;

	//FIXME: Based on MOD, do different kinds of damage effects,
	//		for example, Borg damage could progressively tint screen green and raise FOV?

	// the lower on health you are, the greater the view kick will be
	health = cg.snap->ps.stats[STAT_HEALTH];
	if ( health < 40 ) {
		scale = 1;
	} else {
		scale = 40.0 / health;
	}
	kick = damage * scale;

	if (kick < 5)
		kick = 5;
	if (kick > 10)
		kick = 10;

	// if yaw and pitch are both 255, make the damage always centered (falling, etc)
	if ( yawByte == 255 && pitchByte == 255 ) {
		cg.damageX = 0;
		cg.damageY = 0;
		cg.v_dmg_roll = 0;
		cg.v_dmg_pitch = -kick;
	} else {
		// positional
		pitch = pitchByte / 255.0 * 360;
		yaw = yawByte / 255.0 * 360;

		angles[PITCH] = pitch;
		angles[YAW] = yaw;
		angles[ROLL] = 0;

		AngleVectors( angles, dir, NULL, NULL );
		VectorSubtract( vec3_origin, dir, dir );

		front = DotProduct (dir, cg.refdef.viewaxis[0] );
		left = DotProduct (dir, cg.refdef.viewaxis[1] );
		up = DotProduct (dir, cg.refdef.viewaxis[2] );

		dir[0] = front;
		dir[1] = left;
		dir[2] = 0;
		dist = VectorLength( dir );
		if ( dist < 0.1 ) {
			dist = 0.1f;
		}

		cg.v_dmg_roll = kick * left;

		cg.v_dmg_pitch = -kick * front;

		if ( front <= 0.1 ) {
			front = 0.1f;
		}
		cg.damageX = -left / front;
		cg.damageY = up / dist;
	}

	// clamp the position
	if ( cg.damageX > 1.0 ) {
		cg.damageX = 1.0;
	}
	if ( cg.damageX < - 1.0 ) {
		cg.damageX = -1.0;
	}

	if ( cg.damageY > 1.0 ) {
		cg.damageY = 1.0;
	}
	if ( cg.damageY < - 1.0 ) {
		cg.damageY = -1.0;
	}

	// don't let the screen flashes vary as much
	if ( kick > 10 ) {
		kick = 10;
	}
	cg.damageValue = kick;
	cg.v_dmg_time = cg.time + DAMAGE_TIME;
	cg.damageTime = cg.snap->serverTime;
}
开发者ID:AlexXT,项目名称:OpenJK,代码行数:96,代码来源:cg_playerstate.cpp

示例14: R_MeshQueue_BeginScene

void R_MeshQueue_BeginScene(void)
{
	mqt_count = 0;
	mqt_viewplanedist = DotProduct(r_refdef.view.origin, r_refdef.view.forward);
	mqt_viewmaxdist = 0;
}
开发者ID:paulvortex,项目名称:DpOmnicide,代码行数:6,代码来源:meshqueue.c

示例15: AI_AddNode_Door

/*
* AI_AddNode_Door
* Drop a node at each side of the door
* and force them to link. Only typical
* doors are covered.
*/
static int AI_AddNode_Door( edict_t *ent )
{
	edict_t	*other;
	vec3_t mins, maxs;
	vec3_t door_origin, movedir, moveangles;
	vec3_t moveaxis[3];
	vec3_t MOVEDIR_UP = { 0, 0, 1 };
	float nodeOffset = NODE_DENSITY * 0.75f;
	int i, j;
	int dropped[4];

	if( ent->flags & FL_TEAMSLAVE )
		return NODE_INVALID; // only team master will drop the nodes

	for( i = 0; i < 4; i++ )
		dropped[i] = NODE_INVALID;

	//make box formed by all team members boxes
	VectorCopy( ent->r.absmin, mins );
	VectorCopy( ent->r.absmax, maxs );

	for( other = ent->teamchain; other; other = other->teamchain )
	{
		AddPointToBounds( other->r.absmin, mins, maxs );
		AddPointToBounds( other->r.absmax, mins, maxs );
	}

	for( i = 0; i < 3; i++ )
		door_origin[i] = ( maxs[i] + mins[i] ) * 0.5;

	VectorSubtract( ent->moveinfo.end_origin, ent->moveinfo.start_origin, movedir );
	VectorNormalizeFast( movedir );
	VecToAngles( movedir, moveangles );

	AnglesToAxis( moveangles, moveaxis );

	//add nodes in "side" direction

	nodes[nav.num_nodes].flags = 0;
	VectorMA( door_origin, nodeOffset, moveaxis[1], nodes[nav.num_nodes].origin );
#ifdef SHOW_JUMPAD_GUESS
	AI_JumpadGuess_ShowPoint( nodes[nav.num_nodes].origin, PATH_AMMO_BOX_MODEL );
#endif
	if( AI_DropNodeOriginToFloor( nodes[nav.num_nodes].origin, NULL ) )
	{
		nodes[nav.num_nodes].flags |= AI_FlagsForNode( nodes[nav.num_nodes].origin, NULL );
		dropped[0] = nav.num_nodes;
		nav.num_nodes++;
	}

	nodes[nav.num_nodes].flags = 0;
	VectorMA( door_origin, -nodeOffset, moveaxis[1], nodes[nav.num_nodes].origin );
#ifdef SHOW_JUMPAD_GUESS
	AI_JumpadGuess_ShowPoint( nodes[nav.num_nodes].origin, PATH_AMMO_BOX_MODEL );
#endif
	if( AI_DropNodeOriginToFloor( nodes[nav.num_nodes].origin, NULL ) )
	{
		nodes[nav.num_nodes].flags |= AI_FlagsForNode( nodes[nav.num_nodes].origin, NULL );
		dropped[1] = nav.num_nodes;
		nav.num_nodes++;
	}

	// if moving in the Y axis drop also in the other crossing direction and hope the
	// bad ones are inhibited by a solid
	if( DotProduct( MOVEDIR_UP, moveaxis[0] ) > 0.8 || DotProduct( MOVEDIR_UP, moveaxis[0] ) < -0.8 )
	{
		nodes[nav.num_nodes].flags = 0;
		VectorMA( door_origin, nodeOffset, moveaxis[2], nodes[nav.num_nodes].origin );
#ifdef SHOW_JUMPAD_GUESS
		AI_JumpadGuess_ShowPoint( nodes[nav.num_nodes].origin, PATH_AMMO_BOX_MODEL );
#endif
		if( AI_DropNodeOriginToFloor( nodes[nav.num_nodes].origin, NULL ) )
		{
			nodes[nav.num_nodes].flags |= AI_FlagsForNode( nodes[nav.num_nodes].origin, NULL );
			dropped[2] = nav.num_nodes;
			nav.num_nodes++;
		}

		nodes[nav.num_nodes].flags = 0;
		VectorMA( door_origin, -nodeOffset, moveaxis[2], nodes[nav.num_nodes].origin );
#ifdef SHOW_JUMPAD_GUESS
		AI_JumpadGuess_ShowPoint( nodes[nav.num_nodes].origin, PATH_AMMO_BOX_MODEL );
#endif
		if( AI_DropNodeOriginToFloor( nodes[nav.num_nodes].origin, NULL ) )
		{
			nodes[nav.num_nodes].flags |= AI_FlagsForNode( nodes[nav.num_nodes].origin, NULL );
			dropped[3] = nav.num_nodes;
			nav.num_nodes++;
		}
	}

	// link those we dropped
	for( i = 0; i < 4; i++ )
	{
//.........这里部分代码省略.........
开发者ID:Racenet,项目名称:racesow,代码行数:101,代码来源:ai_nodes.c


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