Exemplo n.º 1
0
vec3_t CTriMenu::MakePointOrtho( vec2_t vOrg )
{
	vec3_t vForward, vRight, vUp, vTotalOrg, vFRight, vFUp;

	if(CL_IsThirdPerson())
	{
		extern vec3_t g_vecCamAngles;
		AngleVectors( g_vecCamAngles, vForward, vRight, vUp );
	}
	// Use first person angles
	else
	{
		AngleVectors( g_vPlayerAngles , vForward, vRight, vUp );
	}

	vTotalOrg = g_vViewOrg + vForward*5;
	
	float flTmp[3] = {1, 1, 0};
	flTmp[0] = ( 2* vOrg.x ) - 1;
	flTmp[1] = ( 2 *vOrg.y) - 1;

	/*vFRight = */gEngfuncs.pTriAPI->ScreenToWorld( flTmp, vFRight ); 
	// software mode fallback casue screentoworld doesnt work there
	if( !IEngineStudio.IsHardware( ) )
	{
		vFRight = vRight+(vRight*( 6.5* vOrg.x - 3.75 )/.5 );
		vFUp = vUp+(vUp*( 4.9*vOrg.y - 2.95 )/.5);

		vFRight = vFRight + vTotalOrg + vFUp + ( vForward * 1.5 );
	}

	// add forward so it doesnt clip the view
	return vFRight;//vTotalOrg + vFRight + vFUp + ( vForward * 1.5 );
}
Exemplo n.º 2
0
void CEnvironment::Update()
{
	Vector vecOrigin = Hud().GetOrigin();

	if( g_iUser1 > 0 && g_iUser1 != OBS_ROAMING )
	{
		if( cl_entity_t* pFollowing = gEngfuncs.GetEntityByIndex( g_iUser2 ) )
		{
			vecOrigin = pFollowing->origin;
		}
	}

	vecOrigin.z += 36.0f;

	if( cl_weather->value > 3.0 )
	{
		gEngfuncs.Cvar_SetValue( "cl_weather", 3.0 );
	}

	m_flWeatherValue = cl_weather->value;

	if( !IEngineStudio.IsHardware() )
		m_flWeatherValue = 0;

	m_vecWeatherOrigin = vecOrigin;

	UpdateWind();

	if( m_bGrassActive )
	{
		UpdateGrass();
	}

	if( m_flWeatherTime <= gEngfuncs.GetClientTime() )
	{
		switch( m_WeatherType )
		{
		case WeatherType::NONE: break;

		case WeatherType::RAIN:
			{
				UpdateRain();
				break;
			}

		case WeatherType::SNOW:
			{
				UpdateSnow();
				break;
			}
		}
	}

	m_flOldTime = gEngfuncs.GetClientTime();
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------------
// Purpose: Load proper engine .dll and get pointer to either DSound and primary buffer or HWAVEOUT ( NT 4.0, e.g. )
//-----------------------------------------------------------------------------
void LoadSoundAPIs( void )
{
	hEngine = ::LoadLibrary( IEngineStudio.IsHardware() ? "hw.dll" : "sw.dll" );
	if ( hEngine )
	{
		if ( Eng_LoadFunctions( hEngine ) )
		{
			if ( engineapi.S_GetDSPointer && engineapi.S_GetWAVPointer )
			{
				engineapi.S_GetDSPointer(&lpDS, &lpDSBuf);
				lpHW = (HWAVEOUT FAR *)engineapi.S_GetWAVPointer();
			}
		}
	}
}
Exemplo n.º 4
0
void InitScreenGlow()
{
	if (IEngineStudio.IsHardware() != 1)
		return;

	if (CVAR_GET_FLOAT("r_glow") == 0)
		return;

	if (CVAR_GET_FLOAT("r_glow") == 1){
		InitScreenGlowShader();	//AJH don't need r_glowmode, use r_glow 0/1/2 instead

	}
	else if (CVAR_GET_FLOAT("r_glow") == 2){
		InitScreenGlowLowEnd();	//AJH don't need r_glowmode, use r_glow 0/1/2 instead
	}
}
Exemplo n.º 5
0
void RenderScreenGlow()
{
 	if (IEngineStudio.IsHardware() != 1)
		return;

	if (CVAR_GET_FLOAT("r_glow") == 0)	 //check the cvar for the glow is on.
		return;

	if (CVAR_GET_FLOAT("r_glow") == 1){	//check the mode is shader
		RenderScreenGlowShader();	//AJH don't need r_glowmode, use r_glow 0/1/2 instead
	}

	else if (CVAR_GET_FLOAT("r_glow") == 2){ //If its not a shader its the lowend
		RenderScreenGlowLowEnd();	//AJH don't need r_glowmode, use r_glow 0/1/2 instead
	}
}
/*
====================
StudioMergeBones

====================
*/
void CStudioModelRenderer::StudioMergeBones ( model_t *m_pSubModel )
{
	int					i, j;
	double				f;
	int					do_hunt = true;

	mstudiobone_t		*pbones;
	mstudioseqdesc_t	*pseqdesc;
	mstudioanim_t		*panim;

	static float		pos[MAXSTUDIOBONES][3];
	float				bonematrix[3][4];
	static vec4_t		q[MAXSTUDIOBONES];

	if (m_pCurrentEntity->curstate.sequence >=  m_pStudioHeader->numseq) 
	{
		m_pCurrentEntity->curstate.sequence = 0;
	}

	pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->curstate.sequence;

	f = StudioEstimateFrame( pseqdesc );

	if (m_pCurrentEntity->latched.prevframe > f)
	{
		//Con_DPrintf("%f %f\n", m_pCurrentEntity->prevframe, f );
	}

	panim = StudioGetAnim( m_pSubModel, pseqdesc );
	StudioCalcRotations( pos, q, pseqdesc, panim, f );

	pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex);


	for (i = 0; i < m_pStudioHeader->numbones; i++) 
	{
		for (j = 0; j < m_nCachedBones; j++)
		{
			if (stricmp(pbones[i].name, m_nCachedBoneNames[j]) == 0)
			{
				MatrixCopy( m_rgCachedBoneTransform[j], (*m_pbonetransform)[i] );
				MatrixCopy( m_rgCachedLightTransform[j], (*m_plighttransform)[i] );
				break;
			}
		}
		if (j >= m_nCachedBones)
		{
			QuaternionMatrix( q[i], bonematrix );

			bonematrix[0][3] = pos[i][0];
			bonematrix[1][3] = pos[i][1];
			bonematrix[2][3] = pos[i][2];

			if (pbones[i].parent == -1) 
			{
				if ( IEngineStudio.IsHardware() )
				{
					ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_pbonetransform)[i]);

					// MatrixCopy should be faster...
					//ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
					MatrixCopy( (*m_pbonetransform)[i], (*m_plighttransform)[i] );
				}
				else
				{
					ConcatTransforms ((*m_paliastransform), bonematrix, (*m_pbonetransform)[i]);
					ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
				}

				// Apply client-side effects to the transformation matrix
				StudioFxTransform( m_pCurrentEntity, (*m_pbonetransform)[i] );
			} 
			else 
			{
				ConcatTransforms ((*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i]);
				ConcatTransforms ((*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i]);
			}
		}
	}
}
/*
====================
StudioSetupBones

====================
*/
void CStudioModelRenderer::StudioSetupBones ( void )
{
	int					i;
	double				f;

	mstudiobone_t		*pbones;
	mstudioseqdesc_t	*pseqdesc;
	mstudioanim_t		*panim;

	static float		pos[MAXSTUDIOBONES][3];
	static vec4_t		q[MAXSTUDIOBONES];
	float				bonematrix[3][4];

	static float		pos2[MAXSTUDIOBONES][3];
	static vec4_t		q2[MAXSTUDIOBONES];
	static float		pos3[MAXSTUDIOBONES][3];
	static vec4_t		q3[MAXSTUDIOBONES];
	static float		pos4[MAXSTUDIOBONES][3];
	static vec4_t		q4[MAXSTUDIOBONES];

	if (m_pCurrentEntity->curstate.sequence >=  m_pStudioHeader->numseq) 
	{
		m_pCurrentEntity->curstate.sequence = 0;
	}

	pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->curstate.sequence;

	f = StudioEstimateFrame( pseqdesc );

	if (m_pCurrentEntity->latched.prevframe > f)
	{
		//Con_DPrintf("%f %f\n", m_pCurrentEntity->prevframe, f );
	}

	panim = StudioGetAnim( m_pRenderModel, pseqdesc );
	StudioCalcRotations( pos, q, pseqdesc, panim, f );

	if (pseqdesc->numblends > 1)
	{
		float				s;
		float				dadt;

		panim += m_pStudioHeader->numbones;
		StudioCalcRotations( pos2, q2, pseqdesc, panim, f );

		dadt = StudioEstimateInterpolant();
		s = (m_pCurrentEntity->curstate.blending[0] * dadt + m_pCurrentEntity->latched.prevblending[0] * (1.0 - dadt)) / 255.0;

		StudioSlerpBones( q, pos, q2, pos2, s );

		if (pseqdesc->numblends == 4)
		{
			panim += m_pStudioHeader->numbones;
			StudioCalcRotations( pos3, q3, pseqdesc, panim, f );

			panim += m_pStudioHeader->numbones;
			StudioCalcRotations( pos4, q4, pseqdesc, panim, f );

			s = (m_pCurrentEntity->curstate.blending[0] * dadt + m_pCurrentEntity->latched.prevblending[0] * (1.0 - dadt)) / 255.0;
			StudioSlerpBones( q3, pos3, q4, pos4, s );

			s = (m_pCurrentEntity->curstate.blending[1] * dadt + m_pCurrentEntity->latched.prevblending[1] * (1.0 - dadt)) / 255.0;
			StudioSlerpBones( q, pos, q3, pos3, s );
		}
	}
	
	if (m_fDoInterp &&
		m_pCurrentEntity->latched.sequencetime &&
		( m_pCurrentEntity->latched.sequencetime + 0.2 > m_clTime ) && 
		( m_pCurrentEntity->latched.prevsequence < m_pStudioHeader->numseq ))
	{
		// blend from last sequence
		static float		pos1b[MAXSTUDIOBONES][3];
		static vec4_t		q1b[MAXSTUDIOBONES];
		float				s;

		pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->latched.prevsequence;
		panim = StudioGetAnim( m_pRenderModel, pseqdesc );
		// clip prevframe
		StudioCalcRotations( pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );

		if (pseqdesc->numblends > 1)
		{
			panim += m_pStudioHeader->numbones;
			StudioCalcRotations( pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );

			s = (m_pCurrentEntity->latched.prevseqblending[0]) / 255.0;
			StudioSlerpBones( q1b, pos1b, q2, pos2, s );

			if (pseqdesc->numblends == 4)
			{
				panim += m_pStudioHeader->numbones;
				StudioCalcRotations( pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );

				panim += m_pStudioHeader->numbones;
				StudioCalcRotations( pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe );

				s = (m_pCurrentEntity->latched.prevseqblending[0]) / 255.0;
				StudioSlerpBones( q3, pos3, q4, pos4, s );

				s = (m_pCurrentEntity->latched.prevseqblending[1]) / 255.0;
				StudioSlerpBones( q1b, pos1b, q3, pos3, s );
			}
		}

		s = 1.0 - (m_clTime - m_pCurrentEntity->latched.sequencetime) / 0.2;
		StudioSlerpBones( q, pos, q1b, pos1b, s );
	}
	else
	{
		//Con_DPrintf("prevframe = %4.2f\n", f);
		m_pCurrentEntity->latched.prevframe = f;
	}

	pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex);

	// calc gait animation
	if (m_pPlayerInfo && m_pPlayerInfo->gaitsequence != 0)
	{
		if (m_pPlayerInfo->gaitsequence >= m_pStudioHeader->numseq) 
		{
			m_pPlayerInfo->gaitsequence = 0;
		}

		pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pPlayerInfo->gaitsequence;

		panim = StudioGetAnim( m_pRenderModel, pseqdesc );
		StudioCalcRotations( pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe );

		for (i = 0; i < m_pStudioHeader->numbones; i++)
		{
			if (strcmp( pbones[i].name, "Bip01 Spine") == 0)
				break;
			memcpy( pos[i], pos2[i], sizeof( pos[i] ));
			memcpy( q[i], q2[i], sizeof( q[i] ));
		}
	}


	for (i = 0; i < m_pStudioHeader->numbones; i++) 
	{
		QuaternionMatrix( q[i], bonematrix );

		bonematrix[0][3] = pos[i][0];
		bonematrix[1][3] = pos[i][1];
		bonematrix[2][3] = pos[i][2];

		if (pbones[i].parent == -1) 
		{
			if ( IEngineStudio.IsHardware() )
			{
				ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_pbonetransform)[i]);

				// MatrixCopy should be faster...
				//ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
				MatrixCopy( (*m_pbonetransform)[i], (*m_plighttransform)[i] );
			}
			else
			{
				ConcatTransforms ((*m_paliastransform), bonematrix, (*m_pbonetransform)[i]);
				ConcatTransforms ((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
			}

			// Apply client-side effects to the transformation matrix
			StudioFxTransform( m_pCurrentEntity, (*m_pbonetransform)[i] );
		} 
		else 
		{
			ConcatTransforms ((*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i]);
			ConcatTransforms ((*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i]);
		}
	}
}
/*
====================
StudioSetUpTransform

====================
*/
void CStudioModelRenderer::StudioSetUpTransform (int trivial_accept)
{
	int				i;
	vec3_t			angles;
	vec3_t			modelpos;

// tweek model origin	
	//for (i = 0; i < 3; i++)
	//	modelpos[i] = m_pCurrentEntity->origin[i];

	VectorCopy( m_pCurrentEntity->origin, modelpos );

// TODO: should really be stored with the entity instead of being reconstructed
// TODO: should use a look-up table
// TODO: could cache lazily, stored in the entity
	angles[ROLL] = m_pCurrentEntity->curstate.angles[ROLL];
	angles[PITCH] = m_pCurrentEntity->curstate.angles[PITCH];
	angles[YAW] = m_pCurrentEntity->curstate.angles[YAW];

	//Con_DPrintf("Angles %4.2f prev %4.2f for %i\n", angles[PITCH], m_pCurrentEntity->index);
	//Con_DPrintf("movetype %d %d\n", m_pCurrentEntity->movetype, m_pCurrentEntity->aiment );
	if (m_pCurrentEntity->curstate.movetype == MOVETYPE_STEP) 
	{
		float			f = 0;
		float			d;

		// don't do it if the goalstarttime hasn't updated in a while.

		// NOTE:  Because we need to interpolate multiplayer characters, the interpolation time limit
		//  was increased to 1.0 s., which is 2x the max lag we are accounting for.

		if ( ( m_clTime < m_pCurrentEntity->curstate.animtime + 1.0f ) &&
			 ( m_pCurrentEntity->curstate.animtime != m_pCurrentEntity->latched.prevanimtime ) )
		{
			f = (m_clTime - m_pCurrentEntity->curstate.animtime) / (m_pCurrentEntity->curstate.animtime - m_pCurrentEntity->latched.prevanimtime);
			//Con_DPrintf("%4.2f %.2f %.2f\n", f, m_pCurrentEntity->curstate.animtime, m_clTime);
		}

		if (m_fDoInterp)
		{
			// ugly hack to interpolate angle, position. current is reached 0.1 seconds after being set
			f = f - 1.0;
		}
		else
		{
			f = 0;
		}

		for (i = 0; i < 3; i++)
		{
			modelpos[i] += (m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i]) * f;
		}

		// NOTE:  Because multiplayer lag can be relatively large, we don't want to cap
		//  f at 1.5 anymore.
		//if (f > -1.0 && f < 1.5) {}

//			Con_DPrintf("%.0f %.0f\n",m_pCurrentEntity->msg_angles[0][YAW], m_pCurrentEntity->msg_angles[1][YAW] );
		for (i = 0; i < 3; i++)
		{
			float ang1, ang2;

			ang1 = m_pCurrentEntity->angles[i];
			ang2 = m_pCurrentEntity->latched.prevangles[i];

			d = ang1 - ang2;
			if (d > 180)
			{
				d -= 360;
			}
			else if (d < -180)
			{	
				d += 360;
			}

			angles[i] += d * f;
		}
		//Con_DPrintf("%.3f \n", f );
	}
	else if ( m_pCurrentEntity->curstate.movetype != MOVETYPE_NONE ) 
	{
		VectorCopy( m_pCurrentEntity->angles, angles );
	}

	//Con_DPrintf("%.0f %0.f %0.f\n", modelpos[0], modelpos[1], modelpos[2] );
	//Con_DPrintf("%.0f %0.f %0.f\n", angles[0], angles[1], angles[2] );

	angles[PITCH] = -angles[PITCH];
	AngleMatrix (angles, (*m_protationmatrix));

	if ( !IEngineStudio.IsHardware() )
	{
		static float viewmatrix[3][4];

		VectorCopy (m_vRight, viewmatrix[0]);
		VectorCopy (m_vUp, viewmatrix[1]);
		VectorInverse (viewmatrix[1]);
		VectorCopy (m_vNormal, viewmatrix[2]);

		(*m_protationmatrix)[0][3] = modelpos[0] - m_vRenderOrigin[0];
		(*m_protationmatrix)[1][3] = modelpos[1] - m_vRenderOrigin[1];
		(*m_protationmatrix)[2][3] = modelpos[2] - m_vRenderOrigin[2];

		ConcatTransforms (viewmatrix, (*m_protationmatrix), (*m_paliastransform));

		// do the scaling up of x and y to screen coordinates as part of the transform
		// for the unclipped case (it would mess up clipping in the clipped case).
		// Also scale down z, so 1/z is scaled 31 bits for free, and scale down x and y
		// correspondingly so the projected x and y come out right
		// FIXME: make this work for clipped case too?
		if (trivial_accept)
		{
			for (i=0 ; i<4 ; i++)
			{
				(*m_paliastransform)[0][i] *= m_fSoftwareXScale *
						(1.0 / (ZISCALE * 0x10000));
				(*m_paliastransform)[1][i] *= m_fSoftwareYScale *
						(1.0 / (ZISCALE * 0x10000));
				(*m_paliastransform)[2][i] *= 1.0 / (ZISCALE * 0x10000);

			}
		}
	}

	(*m_protationmatrix)[0][3] = modelpos[0];
	(*m_protationmatrix)[1][3] = modelpos[1];
	(*m_protationmatrix)[2][3] = modelpos[2];
}
Exemplo n.º 9
0
void RenderScreenGlowLowEnd(void)
{

     // check to see if we can render it.
	if (IEngineStudio.IsHardware() != 1){
		return;
	}

/*	AJH - This is redundant as the function now returns if r_glow!=2
	//check the cvar for the glow is on.
     if (CVAR_GET_FLOAT("r_glow") == 0)
          return;
*/
	 //check the mode is low-end
	if (CVAR_GET_FLOAT("r_glow") != 2)	//AJH don't need r_glowmode, use r_glow 0/1/2 instead
		return;

	if (!bGlowLowEndInitialised)
		InitScreenGlowLowEnd();

	if (!bGlowLowEndInitialised){ //if the initialisation dosent work for some reason
		gEngfuncs.Cvar_SetValue( "r_glow", 0 ); //AJH may as well set this here too.
		return;
	}
    // enable some OpenGL stuff
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glColor3f(1,1,1);
    glDisable(GL_DEPTH_TEST);

    // STEP 1: Grab the screen and put it into a texture
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth, ScreenHeight, 0);

    // STEP 2: Set up an orthogonal projection
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, 1, 1, 0, 0.1, 100);

	// STEP 3: Render the current scene to a new, lower-res texture, darkening non-bright areas of the scene
    // by multiplying it with itself a few times.
    glViewport(0, 0, ScreenWidth/4, ScreenHeight/4);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);

    glBlendFunc(GL_DST_COLOR, GL_ZERO);

    glDisable(GL_BLEND);

    DrawQuad(ScreenWidth, ScreenHeight);

    glEnable(GL_BLEND);

    for (int i = 0; i < CVAR_GET_FLOAT("r_glowdark"); i++)
		DrawQuad(ScreenWidth, ScreenHeight);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiGlowTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 4: Blur the now darkened scene in the horizontal direction.
    float blurAlpha = 1 / (CVAR_GET_FLOAT("r_glowblur")*2 + 1);

    glColor4f(1,1,1,blurAlpha);

    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    for (i = 0; i <= CVAR_GET_FLOAT("r_glowblur"); i++) {
	    DrawQuad(ScreenWidth/4, ScreenHeight/4, -i, 0);
		DrawQuad(ScreenWidth/4, ScreenHeight/4, i, 0);
    }

    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 5: Blur the horizontally blurred image in the vertical direction.
    glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    for (i = 0; i <= CVAR_GET_FLOAT("r_glowblur"); i++) {
		DrawQuad(ScreenWidth/4, ScreenHeight/4, 0, -i);
		DrawQuad(ScreenWidth/4, ScreenHeight/4, 0, i);
    }

    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

    // STEP 6: Combine the blur with the original image.
    glViewport(0, 0, ScreenWidth, ScreenHeight);

    glDisable(GL_BLEND);

    DrawQuad(ScreenWidth/4, ScreenHeight/4);

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    for (i = 0; i < CVAR_GET_FLOAT("r_glowstrength"); i++) {
		DrawQuad(ScreenWidth/4, ScreenHeight/4);
    }

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiScreenTex);

    DrawQuad(ScreenWidth, ScreenHeight);

    // STEP 7: Restore the original projection and modelview matrices and disable rectangular textures.
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glDisable(GL_TEXTURE_RECTANGLE_NV);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_BLEND);
	glClear(GL_DEPTH_BUFFER_BIT);
}
Exemplo n.º 10
0
void RenderScreenGlowShader(void)
{
	// check to see if we can render it.
	if (IEngineStudio.IsHardware() != 1){
		return;
	}
/*	AJH - This is redundant as the function now returns if r_glow!=1
	//check the cvar for the glow is on.
    if (CVAR_GET_FLOAT("r_glow") == 0)
         return;
*/
	//if the mode isn't shader then return.
	if (CVAR_GET_FLOAT("r_glow") != 1)
		  return;

    if (!bGlowShaderInitialised)
		InitScreenGlowShader();

	if (!bGlowShaderInitialised){ //if the initialisation dosent work for some reason
		gEngfuncs.Cvar_SetValue( "r_glow", 0 );
		return;
	}

    // STEP 1: Grab the screen and put it into a texture
    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth, ScreenHeight, 0);

    // STEP 2: Set up an orthogonal projection
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, 1, 1, 0, 0.1, 100);

    glColor3f(1,1,1);

    // STEP 3: Initialize Cg programs and parameters for darken
    cgGLEnableProfile(g_cgVertProfile);
    cgGLEnableProfile(g_cgFragProfile);

    cgGLBindProgram(g_cgVP_GlowDarken);
    cgGLBindProgram(g_cgFP_GlowDarken);

    cgGLSetStateMatrixParameter(g_cgpVP0_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    // STEP 4: Render the current scene texture to a new, lower-res texture, darkening non-bright areas of the scene
    glViewport(0, 0, ScreenWidth/4, ScreenHeight/4);
    pglActiveTextureARB(GL_TEXTURE0_ARB);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);

    DrawQuad(ScreenWidth, ScreenHeight);

    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiBlurTex);
    glCopyTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, GL_RGB, 0, 0, ScreenWidth/4, ScreenHeight/4, 0);

	// STEP 5: Initialise Cg programs and parameters for blurring
	cgGLBindProgram(g_cgVP_GlowBlur);
	cgGLBindProgram(g_cgFP_GlowBlur);

	cgGLSetStateMatrixParameter(g_cgpVP1_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    // STEP 6: Apply blur
    int iNumBlurSteps = CVAR_GET_FLOAT("r_glowblur"); //use new CVAR --FragBait0
    for (int i = 0; i < iNumBlurSteps; i++) {
         DoBlur(g_uiBlurTex, g_uiBlurTex, ScreenWidth/4, ScreenHeight/4, ScreenWidth/4, ScreenHeight/4, 1, 0);
         DoBlur(g_uiBlurTex, g_uiBlurTex, ScreenWidth/4, ScreenHeight/4, ScreenWidth/4, ScreenHeight/4, 0, 1);
    }

    // STEP 7: Set up Cg for combining blurred glow with original scene
    cgGLBindProgram(g_cgVP_GlowCombine);
    cgGLBindProgram(g_cgFP_GlowCombine);

    cgGLSetStateMatrixParameter(g_cgpVP2_ModelViewMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiSceneTex);

    pglActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_RECTANGLE_NV);
    glBindTexture(GL_TEXTURE_RECTANGLE_NV, g_uiBlurTex);

    // STEP 8: Do the combination, rendering to the screen without grabbing it to a texture
    glViewport(0, 0, ScreenWidth, ScreenHeight);

	DrawQuad(ScreenWidth/4, ScreenHeight/4);

    // STEP 9: Restore the original projection and modelview matrices and disable rectangular textures on all units
	glMatrixMode(GL_PROJECTION);
    glPopMatrix();

    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    cgGLDisableProfile(g_cgVertProfile);
    cgGLDisableProfile(g_cgFragProfile);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE1_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE2_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE3_ARB);
    glDisable(GL_TEXTURE_RECTANGLE_NV);

    pglActiveTextureARB(GL_TEXTURE0_ARB);
	glClear(GL_DEPTH_BUFFER_BIT);
}
void CGameStudioModelRenderer::StudioSetupBones(void)
{
	int i;
	double f;

	mstudiobone_t *pbones;
	mstudioseqdesc_t *pseqdesc;
	mstudioanim_t *panim;

	static float pos[MAXSTUDIOBONES][3];
	static vec4_t q[MAXSTUDIOBONES];
	float bonematrix[3][4];

	static float pos2[MAXSTUDIOBONES][3];
	static vec4_t q2[MAXSTUDIOBONES];
	static float pos3[MAXSTUDIOBONES][3];
	static vec4_t q3[MAXSTUDIOBONES];
	static float pos4[MAXSTUDIOBONES][3];
	static vec4_t q4[MAXSTUDIOBONES];

	if (!m_pCurrentEntity->player)
	{
		CStudioModelRenderer::StudioSetupBones();
		return;
	}

	if (m_pCurrentEntity->curstate.sequence >= m_pStudioHeader->numseq)
		m_pCurrentEntity->curstate.sequence = 0;

	pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->curstate.sequence;
	panim = StudioGetAnim(m_pRenderModel, pseqdesc);

	f = StudioEstimateFrame(pseqdesc);

	if (m_pPlayerInfo->gaitsequence == ANIM_WALK_SEQUENCE)
	{
		if (m_pCurrentEntity->curstate.blending[0] <= 26)
		{
			m_pCurrentEntity->curstate.blending[0] = 0;
			m_pCurrentEntity->latched.prevseqblending[0] = m_pCurrentEntity->curstate.blending[0];
		}
		else
		{
			m_pCurrentEntity->curstate.blending[0] -= 26;
			m_pCurrentEntity->latched.prevseqblending[0] = m_pCurrentEntity->curstate.blending[0];
		}
	}

	if (pseqdesc->numblends == 9)
	{
		float s = m_pCurrentEntity->curstate.blending[0];
		float t = m_pCurrentEntity->curstate.blending[1];

		if (s <= 127.0)
		{
			s = (s * 2.0);

			if (t <= 127.0)
			{
				t = (t * 2.0);

				StudioCalcRotations(pos, q, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 1);
				StudioCalcRotations(pos2, q2, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 3);
				StudioCalcRotations(pos3, q3, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 4);
				StudioCalcRotations(pos4, q4, pseqdesc, panim, f);
			}
			else
			{
				t = 2.0 * (t - 127.0);

				panim = LookupAnimation(pseqdesc, 3);
				StudioCalcRotations(pos, q, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 4);
				StudioCalcRotations(pos2, q2, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 6);
				StudioCalcRotations(pos3, q3, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 7);
				StudioCalcRotations(pos4, q4, pseqdesc, panim, f);
			}
		}
		else
		{
			s = 2.0 * (s - 127.0);

			if (t <= 127.0)
			{
				t = (t * 2.0);

				panim = LookupAnimation(pseqdesc, 1);
				StudioCalcRotations(pos, q, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 2);
				StudioCalcRotations(pos2, q2, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 4);
				StudioCalcRotations(pos3, q3, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 5);
				StudioCalcRotations(pos4, q4, pseqdesc, panim, f);
			}
			else
			{
				t = 2.0 * (t - 127.0);

				panim = LookupAnimation(pseqdesc, 4);
				StudioCalcRotations(pos, q, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 5);
				StudioCalcRotations(pos2, q2, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 7);
				StudioCalcRotations(pos3, q3, pseqdesc, panim, f);
				panim = LookupAnimation(pseqdesc, 8);
				StudioCalcRotations(pos4, q4, pseqdesc, panim, f);
			}
		}

		s /= 255.0;
		t /= 255.0;

		StudioSlerpBones(q, pos, q2, pos2, s);
		StudioSlerpBones(q3, pos3, q4, pos4, s);
		StudioSlerpBones(q, pos, q3, pos3, t);
	}
	else
	{
		StudioCalcRotations(pos, q, pseqdesc, panim, f);
	}

	if (m_fDoInterp && m_pCurrentEntity->latched.sequencetime && (m_pCurrentEntity->latched.sequencetime + 0.2 > m_clTime) && (m_pCurrentEntity->latched.prevsequence < m_pStudioHeader->numseq))
	{
		static float pos1b[MAXSTUDIOBONES][3];
		static vec4_t q1b[MAXSTUDIOBONES];
		float s = m_pCurrentEntity->latched.prevseqblending[0];
		float t = m_pCurrentEntity->latched.prevseqblending[1];

		pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->latched.prevsequence;
		panim = StudioGetAnim(m_pRenderModel, pseqdesc);

		if (pseqdesc->numblends == 9)
		{
			if (s <= 127.0)
			{
				s = (s * 2.0);

				if (t <= 127.0)
				{
					t = (t * 2.0);

					StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 1);
					StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 3);
					StudioCalcRotations(pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 4);
					StudioCalcRotations(pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
				}
				else
				{
					t = 2.0 * (t - 127.0);

					panim = LookupAnimation(pseqdesc, 3);
					StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 4);
					StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 6);
					StudioCalcRotations(pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 7);
					StudioCalcRotations(pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
				}
			}
			else
			{
				s = 2.0 * (s - 127.0);

				if (t <= 127.0)
				{
					t = (t * 2.0);

					panim = LookupAnimation(pseqdesc, 1);
					StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 2);
					StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 4);
					StudioCalcRotations(pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 5);
					StudioCalcRotations(pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
				}
				else
				{
					t = 2.0 * (t - 127.0);

					panim = LookupAnimation(pseqdesc, 4);
					StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 5);
					StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 7);
					StudioCalcRotations(pos3, q3, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
					panim = LookupAnimation(pseqdesc, 8);
					StudioCalcRotations(pos4, q4, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
				}
			}

			s /= 255.0;
			t /= 255.0;

			StudioSlerpBones(q1b, pos1b, q2, pos2, s);
			StudioSlerpBones(q3, pos3, q4, pos4, s);
			StudioSlerpBones(q1b, pos1b, q3, pos3, t);
		}
		else
		{
			StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
		}

		s = 1.0 - (m_clTime - m_pCurrentEntity->latched.sequencetime) / 0.2;
		StudioSlerpBones(q, pos, q1b, pos1b, s);
	}
	else
	{
		m_pCurrentEntity->latched.prevframe = f;
	}

	pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex);

	if (m_pPlayerInfo && (m_pCurrentEntity->curstate.sequence < ANIM_FIRST_DEATH_SEQUENCE || m_pCurrentEntity->curstate.sequence > ANIM_LAST_DEATH_SEQUENCE) && (m_pCurrentEntity->curstate.sequence < ANIM_FIRST_EMOTION_SEQUENCE || m_pCurrentEntity->curstate.sequence > ANIM_LAST_EMOTION_SEQUENCE) && m_pCurrentEntity->curstate.sequence != ANIM_SWIM_1 && m_pCurrentEntity->curstate.sequence != ANIM_SWIM_2)
	{
		int copy = 1;

		if (m_pPlayerInfo->gaitsequence >= m_pStudioHeader->numseq)
			m_pPlayerInfo->gaitsequence = 0;

		pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex ) + m_pPlayerInfo->gaitsequence;

		panim = StudioGetAnim(m_pRenderModel, pseqdesc);
		StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe);

		for (i = 0; i < m_pStudioHeader->numbones; i++)
		{
			if (!strcmp(pbones[i].name, "Bip01 Spine"))
				copy = 0;
			else if (!strcmp(pbones[pbones[i].parent].name, "Bip01 Pelvis"))
				copy = 1;

			if (copy)
			{
				memcpy(pos[i], pos2[i], sizeof(pos[i]));
				memcpy(q[i], q2[i], sizeof(q[i]));
			}
		}
	}

	for (i = 0; i < m_pStudioHeader->numbones; i++)
	{
		QuaternionMatrix(q[i], bonematrix);

		bonematrix[0][3] = pos[i][0];
		bonematrix[1][3] = pos[i][1];
		bonematrix[2][3] = pos[i][2];

		if (pbones[i].parent == -1)
		{
			if (IEngineStudio.IsHardware())
			{
				ConcatTransforms((*m_protationmatrix), bonematrix, (*m_pbonetransform)[i]);
				MatrixCopy((*m_pbonetransform)[i], (*m_plighttransform)[i]);
			}
			else
			{
				ConcatTransforms((*m_paliastransform), bonematrix, (*m_pbonetransform)[i]);
				ConcatTransforms((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
			}

			StudioFxTransform(m_pCurrentEntity, (*m_pbonetransform)[i]);
		}
		else
		{
			ConcatTransforms((*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i]);
			ConcatTransforms((*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i]);
		}
	}
}
/*
====================
StudioSetupBones

====================
*/
void CGameStudioModelRenderer::StudioSetupBones(void)
{
	int    i;
	double f;

	mstudiobone_t *   pbones;
	mstudioseqdesc_t *pseqdesc;
	mstudioanim_t *   panim;

	static float  pos[MAXSTUDIOBONES][3];
	static vec4_t q[MAXSTUDIOBONES];
	float         bonematrix[3][4];

	static float  pos2[MAXSTUDIOBONES][3];
	static vec4_t q2[MAXSTUDIOBONES];
	static float  pos3[MAXSTUDIOBONES][3];
	static vec4_t q3[MAXSTUDIOBONES];
	static float  pos4[MAXSTUDIOBONES][3];
	static vec4_t q4[MAXSTUDIOBONES];

	// Use default bone setup for nonplayers
	if(!m_pCurrentEntity->player)
	{
		CStudioModelRenderer::StudioSetupBones();
		return;
	}

	// Bound sequence number.
	if(m_pCurrentEntity->curstate.sequence >= m_pStudioHeader->numseq)
	{
		m_pCurrentEntity->curstate.sequence = 0;
	}

	pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->curstate.sequence;

	if(m_pPlayerInfo && m_pPlayerInfo->gaitsequence != 0)
	{
		f = m_pPlayerInfo->gaitframe;
	}
	else
	{
		f = StudioEstimateFrame(pseqdesc);
	}

	// This game knows how to do three way blending
	if(pseqdesc->numblends == 3)
	{
		float s;

		// Get left anim
		panim = StudioGetAnim(m_pRenderModel, pseqdesc);

		// Blending is 0-127 == Left to Middle, 128 to 255 == Middle to right
		if(m_pCurrentEntity->curstate.blending[0] <= 127)
		{
			StudioCalcRotations(pos, q, pseqdesc, panim, f);

			// Scale 0-127 blending up to 0-255
			s = m_pCurrentEntity->curstate.blending[0];
			s = (s * 2.0);
		}
		else
		{
			// Skip ahead to middle
			panim += m_pStudioHeader->numbones;

			StudioCalcRotations(pos, q, pseqdesc, panim, f);

			// Scale 127-255 blending up to 0-255
			s = m_pCurrentEntity->curstate.blending[0];
			s = 2.0 * (s - 127.0);
		}

		// Normalize interpolant
		s /= 255.0;

		// Go to middle or right
		panim += m_pStudioHeader->numbones;

		StudioCalcRotations(pos2, q2, pseqdesc, panim, f);

		// Spherically interpolate the bones
		StudioSlerpBones(q, pos, q2, pos2, s);
	}
	else
	{
		panim = StudioGetAnim(m_pRenderModel, pseqdesc);
		StudioCalcRotations(pos, q, pseqdesc, panim, f);
	}

	// Are we in the process of transitioning from one sequence to another.
	if(m_fDoInterp &&
	   m_pCurrentEntity->latched.sequencetime &&
	   (m_pCurrentEntity->latched.sequencetime + 0.2 > m_clTime) &&
	   (m_pCurrentEntity->latched.prevsequence < m_pStudioHeader->numseq))
	{
		// blend from last sequence
		static float  pos1b[MAXSTUDIOBONES][3];
		static vec4_t q1b[MAXSTUDIOBONES];
		float         s;

		// Blending value into last sequence
		unsigned char prevseqblending = m_pCurrentEntity->latched.prevseqblending[0];

		// Point at previous sequenece
		pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + m_pCurrentEntity->latched.prevsequence;

		// Know how to do three way blends
		if(pseqdesc->numblends == 3)
		{
			float s;

			// Get left animation
			panim = StudioGetAnim(m_pRenderModel, pseqdesc);

			if(prevseqblending <= 127)
			{
				// Set up bones based on final frame of previous sequence
				StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);

				s = prevseqblending;
				s = (s * 2.0);
			}
			else
			{
				// Skip to middle blend
				panim += m_pStudioHeader->numbones;

				StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);

				s = prevseqblending;
				s = 2.0 * (s - 127.0);
			}

			// Normalize
			s /= 255.0;

			panim += m_pStudioHeader->numbones;
			StudioCalcRotations(pos2, q2, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);

			// Interpolate bones
			StudioSlerpBones(q1b, pos1b, q2, pos2, s);
		}
		else
		{
			panim = StudioGetAnim(m_pRenderModel, pseqdesc);
			// clip prevframe
			StudioCalcRotations(pos1b, q1b, pseqdesc, panim, m_pCurrentEntity->latched.prevframe);
		}

		// Now blend last frame of previous sequence with current sequence.
		s = 1.0 - (m_clTime - m_pCurrentEntity->latched.sequencetime) / 0.2;
		StudioSlerpBones(q, pos, q1b, pos1b, s);
	}
	else
	{
		m_pCurrentEntity->latched.prevframe = f;
	}

	// Now convert quaternions and bone positions into matrices
	pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex);

	for(i = 0; i < m_pStudioHeader->numbones; i++)
	{
		QuaternionMatrix(q[i], bonematrix);

		bonematrix[0][3] = pos[i][0];
		bonematrix[1][3] = pos[i][1];
		bonematrix[2][3] = pos[i][2];

		if(pbones[i].parent == -1)
		{
			if(IEngineStudio.IsHardware())
			{
				ConcatTransforms((*m_protationmatrix), bonematrix, (*m_pbonetransform)[i]);
				ConcatTransforms((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
			}
			else
			{
				ConcatTransforms((*m_paliastransform), bonematrix, (*m_pbonetransform)[i]);
				ConcatTransforms((*m_protationmatrix), bonematrix, (*m_plighttransform)[i]);
			}

			// Apply client-side effects to the transformation matrix
			StudioFxTransform(m_pCurrentEntity, (*m_pbonetransform)[i]);
		}
		else
		{
			ConcatTransforms((*m_pbonetransform)[pbones[i].parent], bonematrix, (*m_pbonetransform)[i]);
			ConcatTransforms((*m_plighttransform)[pbones[i].parent], bonematrix, (*m_plighttransform)[i]);
		}
	}
}
Exemplo n.º 13
0
void Tri_DrawScaledSprite( HSPRITE hSprite, int frame, int r, int g, int b, int a, const RenderMode renderMode, const float flScale, ITriCoordFallback& callback, const wrect_t* pSpriteRect )
{
	if( hSprite == INVALID_HSPRITE )
	{
		gEngfuncs.Con_DPrintf( "Tri_DrawScaledSprite: hSprite is invalid!\n" );
		return;
	}

	const int iOrigWidth = gEngfuncs.pfnSPR_Width( hSprite, frame );
	const int iOrigHeight = gEngfuncs.pfnSPR_Height( hSprite, frame );

	wrect_t subRect;

	if( pSpriteRect )
	{
		subRect = *pSpriteRect;
	}
	else
	{
		subRect.left = subRect.top = 0;
		subRect.right = iOrigWidth;
		subRect.bottom = iOrigHeight;
	}

	int x, y;

	//Fallback on Software; no scaling or render mode support. - Solokiller
	if( !IEngineStudio.IsHardware() )
	{
		//Always scale 1. - Solokiller
		callback.Calculate( hSprite, frame, subRect, 1.0f, x, y );

		gEngfuncs.pfnSPR_Set( hSprite, r, g, b );

		gEngfuncs.pfnSPR_DrawHoles( frame, x, y, pSpriteRect );

		return;
	}

	wrect_t rect;

	//Trim a pixel border around it, since it blends. - Solokiller
	rect.left = subRect.left * flScale + ( flScale - 1 );
	rect.top = subRect.top * flScale + ( flScale - 1 );
	rect.right = subRect.right * flScale - ( flScale - 1 );
	rect.bottom = subRect.bottom * flScale - ( flScale - 1 );

	const int iWidth = iOrigWidth * flScale;
	const int iHeight = iOrigHeight * flScale;

	callback.Calculate( hSprite, frame, rect, flScale, x, y );

	model_t* pCrosshair = const_cast<model_t*>( gEngfuncs.GetSpritePointer( hSprite ) );

	auto TriAPI = gEngfuncs.pTriAPI;

	TriAPI->SpriteTexture( pCrosshair, frame );

	TriAPI->Color4fRendermode( r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f, renderMode );
	TriAPI->RenderMode( renderMode );

	float flLeft = 0;
	float flTop = 0;
	float flRight = 1.0;
	float flBottom = 1.0f;

	int iImgWidth = iWidth;
	int iImgHeight = iHeight;

	AdjustSubRect( iWidth, iHeight, &flLeft, &flRight, &flTop, &flBottom, &iImgWidth, &iImgHeight, &rect );

	TriAPI->Begin( TriangleMode::TRI_QUADS );

	TriAPI->TexCoord2f( flLeft, flTop );
	TriAPI->Vertex3f( x, y, 0 );

	TriAPI->TexCoord2f( flRight, flTop );
	TriAPI->Vertex3f( x + iImgWidth, y, 0 );

	TriAPI->TexCoord2f( flRight, flBottom );
	TriAPI->Vertex3f( x + iImgWidth, y + iImgHeight, 0 );

	TriAPI->TexCoord2f( flLeft, flBottom );
	TriAPI->Vertex3f( x, y + iImgHeight, 0 );

	TriAPI->End();
}
Exemplo n.º 14
0
int CHudHealth::Draw(float flTime)
{
	int r = 0, g = 0, b = 0;
	int x = 0, y = 0;
	int iDraw = 0;

	if ( gHUD.m_iHideHUDDisplay & (HIDEHUD_ALL) )
		return 1;

	if(g_iTeamNumber == UNDEFINED || g_iTeamNumber == SPECS )
	{
		gHUD.m_iHideHUDDisplay |= HIDEHUD_HEALTH;
		return 1;
	}

	if(g_iUser1 != 0)
		return 1;

	m_flHealth = g_flHealth;

	if ( !m_hSprite )
		m_hSprite = LoadSprite(PAIN_NAME);

	//hocked on here as this is a good palce as they are related.
	if(IEngineStudio.IsHardware())
		iDraw = gBackground.Draw(flTime);

	if(iDraw == 0)
	{
		gHUD.m_iHideHUDDisplay |= HIDEHUD_HEALTH;
		return 1;
	}
	else
	{
		gHUD.m_iHideHUDDisplay &= ~HIDEHUD_HEALTH;
	}

	gStamina.Draw(flTime);

	if(ScreenWidth >= 640)
		gMiddle.Draw(flTime);
	gHintBox.Draw(flTime);

	UnpackRGB(r, g, b, RGB_WHITEISH);

	HSPRITE m_hSprite = gHUD.GetSprite( m_HUD_health );
	wrect_t *m_SpriteArea = &gHUD.GetSpriteRect( m_HUD_health );

	int x_length, y_length;      // positions of the spots

	y_length = gHUD.GetSpriteRect(m_HUD_health).bottom - gHUD.GetSpriteRect(m_HUD_health).top;
	x_length = gHUD.GetSpriteRect(m_HUD_health).right - gHUD.GetSpriteRect(m_HUD_health).left;

	if(ScreenWidth >= 640)
		x = 5;
	else
		x = 2;	

	y = (YRES(480) - (y_length + ((ScreenWidth >= 640) ? 5 : 3)));

	if(!IEngineStudio.IsHardware())
	{
		UnpackRGB(r, g, b, RGB_WHITEISH);
		gStamina.Draw(flTime);
			
		if(ScreenWidth >= 640)
			x = 5;
		else
			x = 2;	

		y = (YRES(480) - (20 + ((ScreenWidth >= 640) ? 5 : 3)));		

		gHUD.DrawHudNumber(x, y, DHN_2DIGITS | DHN_DRAWZERO, m_flHealth, r, g, b);
		return 1;
	}

	SPR_Set(m_hSprite, r, g, b);

	int iClipLevel = (y_length - ((m_flHealth * y_length) / MAX_HEALTH));
	//clipper starts at the clipping level. its height is the full amount of health take away the mamount clipped
	SPR_EnableScissor(x, y+iClipLevel, 24 , y_length-iClipLevel);
	SPR_DrawHoles(0, x, y, m_SpriteArea);
	SPR_DisableScissor();

	DrawDamage(flTime);
	return DrawPain(flTime);
}
Exemplo n.º 15
0
void AvHSpriteDraw(int spriteHandle, int frame, float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2)
{

    gEngfuncs.pTriAPI->RenderMode(gRenderMode);
    gEngfuncs.pTriAPI->CullFace(TRI_NONE);
    
    struct model_s* spritePtr = (struct model_s*)(gEngfuncs.GetSpritePointer(spriteHandle));
    ASSERT(spritePtr);

    if (!gEngfuncs.pTriAPI->SpriteTexture(spritePtr, frame))
    {
        return;
    }

    Vertex vertex[8];

    vertex[0].x = x1;
    vertex[0].y = y1;
    vertex[0].u = u1;
    vertex[0].v = v1;

    vertex[1].x = x2;
    vertex[1].y = y1;
    vertex[1].u = u2;
    vertex[1].v = v1;

    vertex[2].x = x2;
    vertex[2].y = y2;
    vertex[2].u = u2;
    vertex[2].v = v2;

    vertex[3].x = x1;
    vertex[3].y = y2;
    vertex[3].u = u1;
    vertex[3].v = v2;

    int numVertices = 4;

    float pw = SPR_Width(spriteHandle, frame);
    float ph = SPR_Height(spriteHandle, frame);

    float uOffset = 0;
    float vOffset = 0;

    if (IEngineStudio.IsHardware() == 2)
    {

        // Direct3D addresses textures differently than OpenGL so compensate
        // for that here.

        uOffset = 0.5 / pw;
        vOffset = 0.5 / ph;
  
    }

    // Apply the transformation to the vertices.
    
    for (int i = 0; i < numVertices; ++i)
    {

        if (vertex[i].u < 0.25 / pw)
        {
            vertex[i].u = 0.25 / pw;
        }

        if (vertex[i].v < 0.25 / ph)
        {
            vertex[i].v = 0.25 / ph;
        }

        if (vertex[i].u > 1 - 0.25 / pw)
        {
            vertex[i].u = 1 - 0.25 / pw;
        }

        if (vertex[i].v > 1 - 0.25 / ph)
        {
            vertex[i].v = 1 - 0.25 / ph;
        }

        vertex[i].u += uOffset;
        vertex[i].v += vOffset;
        
        float x = vertex[i].x;
        float y = vertex[i].y;
        
        vertex[i].x = x * gTransform[0][0] + y * gTransform[0][1] + gTransform[0][2];
        vertex[i].y = x * gTransform[1][0] + y * gTransform[1][1] + gTransform[1][2];

    }

    if (gClippingEnabled)
    {
    
        // Clip the polygon to each side of the clipping rectangle. This isn't the
        // fastest way to clip a polygon against a rectangle, but it's probably the
        // simplest.

        ClipPolygon(vertex, numVertices,  1,  0, -gClipRectX1);
        ClipPolygon(vertex, numVertices, -1,  0,  gClipRectX2);
        ClipPolygon(vertex, numVertices,  0,  1, -gClipRectY1);
        ClipPolygon(vertex, numVertices,  0, -1,  gClipRectY2);

    }

    // Compensate for the overbrightening effect.

	float gammaScale = 1.0f / gHUD.GetGammaSlope();
	gEngfuncs.pTriAPI->Color4f(gammaScale * gColor[0], gammaScale * gColor[1], gammaScale * gColor[2], gColor[3]);

    // Output the vertices.

    if (gDrawMode == kSpriteDrawModeFilled)
    {
        gEngfuncs.pTriAPI->Begin(TRI_TRIANGLE_FAN);

        for (int j = 0; j < numVertices; ++j)
        {

            Vector worldPoint;
            
            if (gVGUIEnabled)
            {
                worldPoint.x = (vertex[j].x - gVGUIOffsetX) * gViewportXScale + gViewportXOffset;
                worldPoint.y = (vertex[j].y - gVGUIOffsetY) * gViewportYScale + gViewportYOffset;
                worldPoint.z = 1;
            }
            else
            {
                worldPoint = gViewOrigin +
                    gViewXAxis * vertex[j].x +
                    gViewYAxis * vertex[j].y +
                    gViewZAxis * (gDepth + gDepthOffset);
            }

            gEngfuncs.pTriAPI->TexCoord2f(vertex[j].u, vertex[j].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint);

        }
    
        gEngfuncs.pTriAPI->End();

    }
    else if (gDrawMode == kSpriteDrawModeBorder)
    {

        gEngfuncs.pTriAPI->Begin(TRI_LINES);

        for (int j = 0; j < numVertices; ++j)
        {

            int k = (j + 1) % numVertices;

            Vector worldPoint1;
            Vector worldPoint2;
            
            if (gVGUIEnabled)
            {

                worldPoint1.x = vertex[j].x - gVGUIOffsetX;
                worldPoint1.y = vertex[j].y - gVGUIOffsetY;
                worldPoint1.z = 1;

                worldPoint2.x = vertex[k].x - gVGUIOffsetX;
                worldPoint2.y = vertex[k].y - gVGUIOffsetY;
                worldPoint2.z = 1;
            
            }
            else
            {
                
                worldPoint1 = gViewOrigin +
                    gViewXAxis * vertex[j].x +
                    gViewYAxis * vertex[j].y +
                    gViewZAxis * (gDepth + gDepthOffset);

                worldPoint2 = gViewOrigin +
                    gViewXAxis * vertex[k].x +
                    gViewYAxis * vertex[k].y +
                    gViewZAxis * (gDepth + gDepthOffset);
            
            }

            gEngfuncs.pTriAPI->TexCoord2f(vertex[j].u, vertex[j].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint1);

            gEngfuncs.pTriAPI->TexCoord2f(vertex[k].u, vertex[k].v);
            gEngfuncs.pTriAPI->Vertex3fv((float*)&worldPoint2);
        
        }

        gEngfuncs.pTriAPI->End();

    }

    gDepth += kDepthIncrement; 

}
Exemplo n.º 16
0
void CStudioModelRenderer::StudioSetUpTransform(int trivial_accept)
{
	int i;
	vec3_t angles;
	vec3_t modelpos;

	VectorCopy(m_pCurrentEntity->origin, modelpos);

	angles[ROLL] = m_pCurrentEntity->curstate.angles[ROLL];
	angles[PITCH] = m_pCurrentEntity->curstate.angles[PITCH];
	angles[YAW] = m_pCurrentEntity->curstate.angles[YAW];

	if (m_pCurrentEntity->curstate.movetype == MOVETYPE_STEP)
	{
		float f = 0;
		float d;

		if ((m_clTime < m_pCurrentEntity->curstate.animtime + 1.0f) && (m_pCurrentEntity->curstate.animtime != m_pCurrentEntity->latched.prevanimtime))
			f = (m_clTime - m_pCurrentEntity->curstate.animtime) / (m_pCurrentEntity->curstate.animtime - m_pCurrentEntity->latched.prevanimtime);

		if (m_fDoInterp)
			f = f - 1.0;
		else
			f = 0;

		for (i = 0; i < 3; i++)
			modelpos[i] += (m_pCurrentEntity->origin[i] - m_pCurrentEntity->latched.prevorigin[i]) * f;

		for (i = 0; i < 3; i++)
		{
			float ang1, ang2;

			ang1 = m_pCurrentEntity->angles[i];
			ang2 = m_pCurrentEntity->latched.prevangles[i];

			d = ang1 - ang2;

			if (d > 180)
				d -= 360;
			else if (d < -180)
				d += 360;

			angles[i] += d * f;
		}
	}
	else if (m_pCurrentEntity->curstate.movetype != MOVETYPE_NONE)
	{
		VectorCopy(m_pCurrentEntity->angles, angles);
	}

	angles[PITCH] = -angles[PITCH];
	AngleMatrix(angles, (*m_protationmatrix));

	if (!IEngineStudio.IsHardware())
	{
		static float viewmatrix[3][4];

		VectorCopy(m_vRight, viewmatrix[0]);
		VectorCopy(m_vUp, viewmatrix[1]);
		VectorInverse(viewmatrix[1]);
		VectorCopy(m_vNormal, viewmatrix[2]);

		(*m_protationmatrix)[0][3] = modelpos[0] - m_vRenderOrigin[0];
		(*m_protationmatrix)[1][3] = modelpos[1] - m_vRenderOrigin[1];
		(*m_protationmatrix)[2][3] = modelpos[2] - m_vRenderOrigin[2];

		ConcatTransforms(viewmatrix, (*m_protationmatrix), (*m_paliastransform));

		if (trivial_accept)
		{
			for (i = 0; i < 4; i++)
			{
				(*m_paliastransform)[0][i] *= m_fSoftwareXScale * (1.0 / (ZISCALE * 0x10000));
				(*m_paliastransform)[1][i] *= m_fSoftwareYScale * (1.0 / (ZISCALE * 0x10000));
				(*m_paliastransform)[2][i] *= 1.0 / (ZISCALE * 0x10000);
			}
		}
	}

	(*m_protationmatrix)[0][3] = modelpos[0];
	(*m_protationmatrix)[1][3] = modelpos[1];
	(*m_protationmatrix)[2][3] = modelpos[2];
}