//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CWarsWeapon::GetShootOriginAndDirection( Vector &vShootOrigin, Vector &vShootDirection) { CBaseEntity *pOwner = GetOwner(); if( !pOwner ) return; CUnitBase *pUnit = pOwner->MyUnitPointer(); if( !pUnit ) return; #if 0 #ifdef CLIENT_DLL if( pUnit->GetCommander() && !ShouldDrawLocalPlayer() ) { QAngle vDummy; C_BasePlayer *player = ToBasePlayer( pUnit->GetCommander() ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vShootOrigin, vDummy ) ) { AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); return; } } } #endif // CLIENT_DLL #endif // 0 vShootOrigin = pUnit->Weapon_ShootPosition(); AngleVectors( QAngle(pUnit->m_fEyePitch, pUnit->m_fEyeYaw, 0.0), &vShootDirection ); }
void CBeam::OnDataChanged( DataUpdateType_t updateType ) { MarkMessageReceived(); // Make sure that the correct model is referenced for this entity SetModelPointer( modelinfo->GetModel( GetModelIndex() ) ); // Convert weapon world models to viewmodels if they're weapons being carried by the local player for (int i=0;i<MAX_BEAM_ENTS;i++) { C_BaseEntity *pEnt = m_hAttachEntity[i].Get(); if ( pEnt ) { C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>(pEnt); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); C_BaseViewModel *pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead m_hAttachEntity.Set( i, pViewModel ); } } } } // Compute the bounds here... Vector mins, maxs; ComputeBounds( mins, maxs ); SetCollisionBounds( mins, maxs ); }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } C_BasePlayer *player = ToBasePlayer( pEnt ); bool bUseViewModel = false; if ( C_BasePlayer::IsLocalPlayer( pEnt ) ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD_ENT( pEnt ); bUseViewModel = !player->ShouldDrawLocalPlayer(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && bUseViewModel ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh ) { ACTIVE_SPLITSCREEN_PLAYER_GUARD( hh ); C_BaseCombatWeapon *pWpn = ToBaseCombatWeapon( pEnt ); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); if( !player && pWpn->GetOwner() && pWpn->GetOwner()->IsUnit() ) { player = pWpn->GetOwner()->MyUnitPointer()->GetCommander(); } pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; break; } } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iAttachment = data.m_nAttachmentIndex;; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead IClientRenderable *pRenderable = data.GetRenderable(); if ( !pRenderable ) return vecStart; C_BaseEntity *pEnt = data.GetEntity(); // This check should probably be for all multiplayer games, investigate later #if defined( HL2MP ) || defined( TF_CLIENT_DLL ) || defined( TF_CLASSIC_CLIENT ) if ( pEnt && pEnt->IsDormant() ) return vecStart; #endif C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>( pEnt ); if ( pWpn && pWpn->ShouldDrawUsingViewModel() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); // Use GetRenderedWeaponModel() instead? pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pRenderable = pViewModel; } } // Get the attachment origin if ( !pRenderable->GetAttachment( iAttachment, vecStart, vecAngles ) ) { DevMsg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, modelinfo->GetModelName( pRenderable->GetModel() ) ); } } return vecStart; }
bool C_BaseCombatWeapon::GetShootPosition( Vector &vOrigin, QAngle &vAngles ) { // Get the entity because the weapon doesn't have the right angles. C_BaseCombatCharacter *pEnt = ToBaseCombatCharacter( GetOwner() ); if ( pEnt ) { if ( pEnt == C_BasePlayer::GetLocalPlayer() ) { vAngles = pEnt->EyeAngles(); } else { vAngles = pEnt->GetRenderAngles(); } } else { vAngles.Init(); } QAngle vDummy; if ( IsActiveByLocalPlayer() && !input->CAM_IsThirdPerson() ) { C_BasePlayer *player = ToBasePlayer( pEnt ); C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); if ( vm->GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } } else { // Thirdperson int iAttachment = LookupAttachment( "muzzle" ); if ( GetAttachment( iAttachment, vOrigin, vDummy ) ) { return true; } } vOrigin = GetRenderOrigin(); return false; }
void C_HLTVCamera::CalcInEyeCamView( Vector& eyeOrigin, QAngle& eyeAngles, float& fov ) { C_BasePlayer *pPlayer = UTIL_PlayerByIndex( m_iTraget1 ); if ( !pPlayer ) return; if ( !pPlayer->IsAlive() ) { // if dead, show from 3rd person CalcChaseCamView( eyeOrigin, eyeAngles, fov ); return; } m_aCamAngle = pPlayer->EyeAngles(); m_vCamOrigin = pPlayer->GetAbsOrigin(); m_flFOV = pPlayer->GetFOV(); if ( pPlayer->GetFlags() & FL_DUCKING ) { m_vCamOrigin += VEC_DUCK_VIEW; } else { m_vCamOrigin += VEC_VIEW; } eyeOrigin = m_vCamOrigin; eyeAngles = m_aCamAngle; fov = m_flFOV; pPlayer->CalcViewModelView( eyeOrigin, eyeAngles); C_BaseViewModel *pViewModel = pPlayer->GetViewModel( 0 ); if ( pViewModel ) { Assert( pViewModel->GetOwner() == pPlayer ); pViewModel->UpdateVisibility(); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- Vector GetTracerOrigin( const CEffectData &data ) { Vector vecStart = data.m_vStart; QAngle vecAngles; int iEntIndex = data.m_nEntIndex; // Attachment? if ( data.m_fFlags & TRACER_FLAG_USEATTACHMENT ) { int iAttachment = data.m_vStart[0]; C_BaseViewModel *pViewModel = NULL; // If the entity specified is a weapon being carried by this player, use the viewmodel instead C_BaseEntity *pEnt = ClientEntityList().GetEnt( iEntIndex ); if ( !pEnt ) return vecStart; C_BaseCombatWeapon *pWpn = dynamic_cast<C_BaseCombatWeapon *>(pEnt); if ( pWpn && pWpn->IsCarriedByLocalPlayer() ) { C_BasePlayer *player = ToBasePlayer( pWpn->GetOwner() ); pViewModel = player ? player->GetViewModel( 0 ) : NULL; if ( pViewModel ) { // Get the viewmodel and use it instead pEnt = pViewModel; } } // Get the attachment origin if ( !pEnt->GetAttachment( iAttachment, vecStart, vecAngles ) ) { Msg( "GetTracerOrigin: Couldn't find attachment %d on model %s\n", iAttachment, pEnt->GetModelName() ); } } return vecStart; }
//----------------------------------------------------------------------------- // Purpose: // Input : fTimeDelta - //----------------------------------------------------------------------------- void C_ExtinguisherJet::Update( float fTimeDelta ) { if ( m_bEmit == false ) return; C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( m_bUseMuzzlePoint ) { C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL; if ( vm ) { int iAttachment = vm->LookupAttachment( "muzzle" ); Vector origin; QAngle angles; vm->GetAttachment( iAttachment, origin, angles ); Assert( !GetMoveParent() ); SetLocalOrigin( origin ); SetLocalAngles( angles ); } } trace_t tr; Vector shotDir, vRight, vUp; AngleVectors( GetAbsAngles(), &shotDir, &vRight, &vUp ); //FIXME: Muzzle point is incorrect on the model! if ( m_bUseMuzzlePoint ) { shotDir.Negate(); } Vector endPoint = GetAbsOrigin() + ( shotDir * 150.0f ); UTIL_TraceLine( GetAbsOrigin(), endPoint, MASK_SHOT, NULL, COLLISION_GROUP_NONE, &tr ); bool hitWall = ( tr.fraction < 1.0f ); //Add normal jet if ( m_pEmitter.IsValid() ) { SimpleParticle *pParticle; m_pEmitter->SetSortOrigin( GetAbsOrigin() ); float tempDelta = fTimeDelta; //FIXME: All particles need to be within this loop while( m_ParticleSpawn.NextEvent( tempDelta ) ) { pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.2f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 32, 48 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 164 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } //Add muzzle effect pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() ); if ( pParticle ) { pParticle->m_flDieTime = 0.1f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f ); pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = random->RandomInt( 8, 16 ); pParticle->m_uchStartAlpha = random->RandomInt( 128, 255 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector dir; QAngle ofsAngles; ofsAngles.Random( -64.0f, 64.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 32, 64 ); } //Add a wall effect if needed if ( hitWall ) { AddExtinguisherDecal( tr ); Vector offDir; offDir.Random( -16.0f, 16.0f ); pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, ( tr.endpos + ( tr.plane.normal * 8.0f ) ) + offDir ); if ( pParticle ) { pParticle->m_flDieTime = 0.4f; pParticle->m_flLifetime = 0.0f; pParticle->m_flRoll = random->RandomInt( 0, 360 ); pParticle->m_flRollDelta= random->RandomFloat( -2.0f, 2.0f ); pParticle->m_uchStartSize = random->RandomInt( 8, 16 ); pParticle->m_uchEndSize = random->RandomInt( 24, 32 ); pParticle->m_uchStartAlpha = random->RandomInt( 64, 128 ); pParticle->m_uchEndAlpha = 0; int cScale = random->RandomInt( 192, 255 ); pParticle->m_uchColor[0] = cScale; pParticle->m_uchColor[1] = cScale; pParticle->m_uchColor[2] = cScale; Vector rDir; rDir = tr.plane.normal; rDir[0] += random->RandomFloat( -0.9f, 0.9f ); rDir[1] += random->RandomFloat( -0.9f, 0.9f ); rDir[2] += random->RandomFloat( -0.9f, 0.9f ); pParticle->m_vecVelocity = rDir * random->RandomInt( 32, 64 ); } } //Add small ember-like particles if ( random->RandomInt( 0, 1 ) == 0 ) { m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() ); pParticle = (SimpleParticle *) m_pEmberEmitter->AddParticle( sizeof(SimpleParticle), m_pEmberEmitter->GetPMaterial( "particle/particle_smokegrenade" ), GetAbsOrigin() ); assert(pParticle); if ( pParticle ) { pParticle->m_flLifetime = 0.0f; pParticle->m_flDieTime = 1.0f; pParticle->m_flRoll = 0; pParticle->m_flRollDelta = 0; pParticle->m_uchColor[0] = 255; pParticle->m_uchColor[1] = 255; pParticle->m_uchColor[2] = 255; pParticle->m_uchStartAlpha = 255; pParticle->m_uchEndAlpha = 0; pParticle->m_uchStartSize = 1; pParticle->m_uchEndSize = 0; Vector dir; QAngle ofsAngles; ofsAngles.Random( -8.0f, 8.0f ); ofsAngles += GetAbsAngles(); AngleVectors( ofsAngles, &dir ); if ( m_bUseMuzzlePoint ) { dir.Negate(); } pParticle->m_vecVelocity = dir * random->RandomInt( 400, 800 ); } } } } // Inner beam CBeamSegDraw beamDraw; CBeamSeg seg; const int numPoints = 4; Vector beamPoints[numPoints]; beamPoints[0] = GetAbsOrigin(); // Create our beam points int i; for ( i = 0; i < numPoints; i++ ) { beamPoints[i] = GetAbsOrigin() + ( shotDir * (32*i*i) ); beamPoints[i] += vRight * sin( gpGlobals->curtime * 4.0f ) * (2.0f*i); beamPoints[i] += vUp * sin( gpGlobals->curtime * 8.0f ) * (1.0f*i); beamPoints[i] += shotDir * sin( gpGlobals->curtime * (16.0f*i) ) * (1.0f*i); } IMaterial *pMat = materials->FindMaterial( "particle/particle_smokegrenade", NULL ); beamDraw.Start( numPoints, pMat ); //Setup and draw those points for( i = 0; i < numPoints; i++ ) { float t = (float) i / (numPoints - 1); float color = 1.0f * (1.0f - t); seg.m_vColor = Vector( color, color, color ); seg.m_vPos = beamPoints[i]; seg.m_flTexCoord = (float)i/(float)(numPoints-1) - ((gpGlobals->curtime - (int)gpGlobals->curtime) * 4.0f ); seg.m_flWidth = 4.0f + ( (64.0f*t) * (fabs( sin( gpGlobals->curtime * 16.0f ) )) ); seg.m_flAlpha = color; beamDraw.NextSeg( &seg ); } beamDraw.End(); }
//----------------------------------------------------------------------------- // Purpose: Render current view into specified rectangle // Input : *rect - //----------------------------------------------------------------------------- void CViewRender::Render( vrect_t *rect ) { /*static*/ std::vector<smCoord3f> view_head_pos; /*static*/ std::vector<smRotEuler> view_head_rot; static float learnt_x = 0.0; static float learnt_y = 0.0; static float learnt_z = fa_default_depth; static float learnt_xRot = fa_default_pitch; static float learnt_yRot = 0.0; static float learnt_zRot = 0.0; int i = 0; fa_fov_min = ( fov_desired.GetInt() + fov_fapi_window_adj_amount.GetInt() ); Assert(s_DbgSetupOrigin == m_View.origin); Assert(s_DbgSetupAngles == m_View.angles); VPROF_BUDGET( "CViewRender::Render", "CViewRender::Render" ); vrect_t vr = *rect; // Stub out the material system if necessary. CMatStubHandler matStub; bool drawViewModel; engine->EngineStats_BeginFrame(); // Assume normal vis m_bForceNoVis = false; C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. float aspectRatio = engine->GetScreenAspectRatio() * 0.75f; // / (4/3) if(pPlayer && pPlayer->IsAlive() && face_api.m_bFaceAPIHasCamera) { int head_pos_size = 0; if(!fa_paused) { // Warning: this code does not take parellel operations into account if(head_confidence > 0.0f) { view_head_pos.push_back(latest_head_pos); view_head_rot.push_back(latest_head_rot); } // Restore to a neutral position on loss of the head by // scaling down the last recieved head position static float lost_time = 0.0f; if(fa_lost) { if(head_confidence == 0.0f && view_head_pos.size() > 0) { if(lost_time == 0.0f) { lost_time = engine->Time(); } else if(engine->Time() > lost_time + fa_lost_pause) { smCoord3f previous_offset = view_head_pos.back(); previous_offset.x *= fa_lost_scale; previous_offset.y *= fa_lost_scale; previous_offset.z = ((previous_offset.z - learnt_z) * fa_lost_scale) + learnt_z; smRotEuler previous_rotation = view_head_rot.back(); previous_rotation.x_rads = ((previous_rotation.x_rads - learnt_xRot) * fa_lost_scale) + learnt_xRot; previous_rotation.y_rads *= fa_lost_scale; previous_rotation.z_rads *= fa_lost_scale; view_head_pos.push_back(previous_offset); view_head_rot.push_back(previous_rotation); } } else { if(lost_time > 0.0f) { /*char log[40]; sprintf(log, "lost the head for %f seconds", engine->Time() - lost_time); record(log);*/ lost_time = 0.0f; } } } // Use a while statement in case the user has decreased the // smoothing rate since last time head_pos_size = view_head_pos.size(); while( head_pos_size > fa_smoothing ) { view_head_pos.erase(view_head_pos.begin()); view_head_rot.erase(view_head_rot.begin()); } } x = 0.0f; y = 0.0f; z = 0.0f; float xRot = 0.0f; float yRot = 0.0f; float zRot = 0.0f; // Compute the smoothed head movements head_pos_size = view_head_pos.size(); if(head_pos_size > 0) { for(i = 0; i < head_pos_size; i++) { x += view_head_pos[i].x; y += view_head_pos[i].y; z += view_head_pos[i].z; xRot += view_head_rot[i].x_rads; yRot += view_head_rot[i].y_rads; zRot += view_head_rot[i].z_rads; } x /= view_head_pos.size(); y /= view_head_pos.size(); z /= view_head_pos.size(); xRot /= view_head_pos.size(); yRot /= view_head_pos.size(); zRot /= view_head_pos.size(); } // Corrects the arching that occurs when moving towards the camera if(fa_arcCorrection) y += (z - fa_default_depth) * fa_arcCorrection_scale; // Show the head data //if(fa_show_preHeadData) DevMsg(" pre: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", x, y, z, xRot, yRot, zRot); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. // Learns the player's neutral position static bool reset_learning = false; if(!fa_learning) { if(reset_learning) { learnt_x = 0.0f; learnt_y = 0.0f; learnt_z = fa_default_depth; learnt_xRot = fa_default_pitch; learnt_yRot = 0.0f; learnt_zRot = 0.0f; reset_learning = true; } } else if(fa_learning && head_confidence > 0.0f && !fa_paused) { float diff, change; diff = learnt_x - x; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_x -= change : learnt_x = x; x -= learnt_x; diff = learnt_y - y; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_y -= change : learnt_y = y; y -= learnt_y; diff = learnt_z - z; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_z -= change : learnt_z = z; z = fa_default_depth + (z - learnt_z); diff = learnt_xRot - xRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_xRot -= change : learnt_xRot = xRot; xRot = fa_default_pitch + (xRot - learnt_xRot); diff = learnt_yRot - yRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_yRot -= change : learnt_yRot = yRot; yRot -= learnt_yRot; diff = learnt_zRot - zRot; (diff != 0.0f) ? change = (0.0000001 * fa_learning_influence) / diff : change = 0.0f; (fabs(change) < fabs(diff)) ? learnt_zRot -= change : learnt_zRot = zRot; zRot -= learnt_zRot; reset_learning = true; } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. // Resets the tracker on low confidence static float reset_time = 0.0f; static float waiting_for_reset = 0.0f; if(fa_confidenceMinimum) { if(waiting_for_reset > 0.0f) { if(head_confidence > 0.0f) { /*char log[40]; sprintf(log, "Reset FaceAPI engine and regained head after %f seconds", engine->Time() - waiting_for_reset); record(log);*/ waiting_for_reset = 0.0f; } } else if(head_confidence < fa_confidenceMinimum_threshold && learnt_x <= fabs(fa_confidenceMinimum_widthRange) && learnt_zRot <= fabs(fa_confidenceMinimum_yollRange)) { if(reset_time == 0.0f) { reset_time = engine->Time() + fa_confidenceMinimum_timeout; } else if(engine->Time() > reset_time) { //char logMsg[256]; reset_time = 0.0f; face_api.reset(); waiting_for_reset = engine->Time(); // The learnt values were probably wrong, so reset them learnt_x = 0.0f; learnt_y = 0.0f; learnt_z = fa_default_depth; learnt_xRot = fa_default_pitch; learnt_yRot = 0.0f; learnt_zRot = 0.0f; /*sprintf(logMsg, "confidence droped below %.2f%% for %.2f seconds, whilst (learnt) head.width <= |%.2f| and (learnt) head.roll <= |%.2f|", fa_confidenceMinimum_threshold, fa_confidenceMinimum_timeout, fa_confidenceMinimum_widthRange, fa_confidenceMinimum_yollRange); record(logMsg);*/ } } else { reset_time = 0.0f; } } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. if(faceapi_mode.GetInt() > 1 && !engine->IsPaused()) { // alters the fov based user's head position float forward = fa_fov_depthScale * (z + fa_fov_depthOffset); float head_fov = fa_fov_min + (1 - fa_fov_influence) * default_fov.GetFloat() + fa_fov_influence * (2 * radToDeg(atan((fa_fov_screenWidth / 2) / (forward)))); m_View.fov = ScaleFOVByWidthRatio( head_fov, aspectRatio ); m_View.fovViewmodel = m_View.fov * fa_fov_modelViewScale; // rotate the camera based on the user's head offsets m_View.angles[YAW] += fa_camRotByHeadOff_globalScale * fa_camRotByHeadOff_yawScale * radToDeg(atan(x / z)); m_View.angles[PITCH] += fa_camRotByHeadOff_globalScale * fa_camRotByHeadOff_pitchScale * radToDeg(atan(y / z)); // offset the camera based on the user's head offsets float depth, height, width; depth = fa_camOffByHeadOff_depthScale * fa_camOffByHeadOff_globalScale * (z - fa_default_depth); m_View.origin.x -= depth * cos(degToRad(m_View.angles[YAW])); m_View.origin.y -= depth * sin(degToRad(m_View.angles[YAW])); width = fa_camOffByHeadOff_widthScale * fa_camOffByHeadOff_globalScale * x; m_View.origin.y -= width * cos(degToRad(m_View.angles[YAW])); m_View.origin.x += width * sin(degToRad(m_View.angles[YAW])); height = fa_camOffByHeadOff_heightScale * fa_camOffByHeadOff_globalScale * y; m_View.origin.z += height; // Alters the vanishing point based on the user's head offset offHor = -fa_vanish_depth * (x / z); offVert = -fa_vanish_depth * (y / z); m_View.m_bOffCenter = true; m_View.m_flOffCenterTop = 1.0f - offVert; m_View.m_flOffCenterBottom = 0.0f - offVert; m_View.m_flOffCenterLeft = 0.0f - offHor; m_View.m_flOffCenterRight = 1.0f - offHor; } else { m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); m_View.m_bOffCenter = false; offHor = 0.0f; offVert = 0.0f; } // Show the head data //if(fa_show_postHeadData) DevMsg(" post: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", x, y, z, xRot, yRot, zRot); // Show the learnt head data //if(fa_show_learntHeadData) DevMsg("learnt: pos\tx:%f\ty:%f\tz:%f\n rot\tx:%f\ty:%f\tz:%f\n", learnt_x, learnt_y, learnt_z, learnt_xRot, learnt_yRot, learnt_zRot); // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. if((faceapi_mode.GetInt() == 1 || faceapi_mode.GetInt() == 3) && !engine->IsPaused()) { //float offPeer = 0.0f; float rollPeer = 0.0f; //float yawPeer = 0.0f; /*if(fa_peering_off) if(x > fa_peering_offStart) offPeer = (x - fa_peering_offStart) / (fa_peering_offEnd - fa_peering_offStart); else if(x < -fa_peering_offStart) offPeer = (x + fa_peering_offStart) / (fa_peering_offEnd - fa_peering_offStart);*/ if(fa_peering_roll) if(zRot > fa_peering_rollStart) rollPeer = -(zRot - fa_peering_rollStart) / (fa_peering_rollEnd - fa_peering_rollStart); else if(zRot < -fa_peering_rollStart) rollPeer = -(zRot + fa_peering_rollStart) / (fa_peering_rollEnd - fa_peering_rollStart); /*if(fa_peering_yaw) if(yRot > fa_peering_yawStart) yawPeer = -(yRot - fa_peering_yawStart) / (fa_peering_yawEnd - fa_peering_yawStart); else if(yRot < -fa_peering_yawStart) yawPeer = -(yRot + fa_peering_yawStart) / (fa_peering_yawEnd - fa_peering_yawStart);*/ float peer = /*offPeer + */rollPeer /*+ yawPeer*/; if(peer > 1.0f) peer = 1.0f; if(peer < -1.0f) peer = -1.0f; if(peer != 0.0f) { peer = pow(fabs(peer), fa_peering_ease) * (fabs(peer) / peer); QAngle angles = pPlayer->GetViewModel()->GetAbsAngles(); angles[PITCH] += fabs(peer) * fa_peering_gunTilt; pPlayer->GetViewModel()->SetAbsAngles(angles); m_View.angles[ROLL] += peer * fa_peering_headTilt; Vector eyes, eye_offset; eyes = pPlayer->EyePosition(); float hor_move = peer * fa_peering_size; eye_offset.y = -hor_move * cos(degToRad(m_View.angles[YAW])); eye_offset.x = hor_move * sin(degToRad(m_View.angles[YAW])); eye_offset.z = 0.0f; // Don't allow peering through walls trace_t tr; UTIL_TraceHull(eyes, eyes + eye_offset, PEER_HULL_MIN, PEER_HULL_MAX, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr); eye_offset.z = -fabs(peer) * fa_peering_headLower; m_View.origin += eye_offset * tr.fraction; static float peer_right = 0.0f; if(peer_right == 0.0f && peer == 1.0f) { peer_right = engine->Time(); } else if(peer_right != 0.0f && peer != 1.0f) { /*char log[40]; sprintf(log, "peered right for %f seconds", engine->Time() - peer_right); record(log);*/ peer_right = 0.0f; } static float peer_left = 0.0f; if(peer_left == 0.0f && peer == -1.0f) { peer_left = engine->Time(); } else if(peer_left != 0.0f && peer != -1.0f) { /*char log[40]; sprintf(log, "peered left for %f seconds", engine->Time() - peer_left); record(log);*/ peer_left = 0.0f; } } } // IMPORTANT: Please acknowledge the author Torben Sko ([email protected], torbensko.com/software/head_tracking), // if you: // 1.1 Use or replicate any of the code pertaining to the utilisation of the head tracking data. // 1.2 Use any of the custom assets, including the modified crossbow and the human // character model. rotate_x = 0.0f; rotate_y = 0.0f; if(fa_plyRotByHeadRot) { if(fabs(yRot) > fa_plyRotByHeadRot_yawMin) { float n_yRot = (fabs(yRot) - fa_plyRotByHeadRot_yawMin) / (fa_plyRotByHeadRot_yawMax - fa_plyRotByHeadRot_yawMin); if(n_yRot > 1.0f) n_yRot = 1.0f; if(n_yRot > 0.0f) n_yRot = pow(n_yRot, fa_plyRotByHeadRot_ease); rotate_x = n_yRot * fa_plyRotByHeadRot_yawSpeed * (yRot / fabs(yRot)); } float off_xRot = xRot - learnt_xRot; if(fabs(off_xRot) > fa_plyRotByHeadRot_pitchMin) { float n_xRot = (fabs(off_xRot) - fa_plyRotByHeadRot_pitchMin) / (fa_plyRotByHeadRot_pitchMax - fa_plyRotByHeadRot_pitchMin); if(n_xRot > 1.0f) n_xRot = 1.0f; if(n_xRot > 0.0f) n_xRot = pow(n_xRot, fa_plyRotByHeadRot_ease); rotate_y = n_xRot * fa_plyRotByHeadRot_pitchSpeed * (off_xRot / fabs(off_xRot)); } } } else { m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); } //m_View.fov = ScaleFOVByWidthRatio( m_View.fov, aspectRatio ); //m_View.fovViewmodel = ScaleFOVByWidthRatio( m_View.fovViewmodel, aspectRatio ); // Let the client mode hook stuff. g_pClientMode->PreRender(&m_View); g_pClientMode->AdjustEngineViewport( vr.x, vr.y, vr.width, vr.height ); ToolFramework_AdjustEngineViewport( vr.x, vr.y, vr.width, vr.height ); float flViewportScale = mat_viewportscale.GetFloat(); float engineAspectRatio = engine->GetScreenAspectRatio(); m_View.x = vr.x; m_View.y = vr.y; m_View.width = vr.width * flViewportScale; m_View.height = vr.height * flViewportScale; m_View.m_flAspectRatio = ( engineAspectRatio > 0.0f ) ? engineAspectRatio : ( (float)m_View.width / (float)m_View.height ); int nClearFlags = VIEW_CLEAR_DEPTH | VIEW_CLEAR_STENCIL; if( gl_clear_randomcolor.GetBool() ) { CMatRenderContextPtr pRenderContext( materials ); pRenderContext->ClearColor3ub( rand()%256, rand()%256, rand()%256 ); pRenderContext->ClearBuffers( true, false, false ); pRenderContext->Release(); } else if ( gl_clear.GetBool() ) { nClearFlags |= VIEW_CLEAR_COLOR; } // Determine if we should draw view model ( client mode override ) drawViewModel = g_pClientMode->ShouldDrawViewModel(); if ( cl_leveloverview.GetFloat() > 0 ) { SetUpOverView(); nClearFlags |= VIEW_CLEAR_COLOR; drawViewModel = false; } // Apply any player specific overrides //C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer ) { // Override view model if necessary if ( !pPlayer->m_Local.m_bDrawViewmodel ) { drawViewModel = false; } } if(fa_weapon) drawViewModel = false; render->SetMainView( m_View.origin, m_View.angles ); int flags = RENDERVIEW_DRAWHUD; if ( drawViewModel ) { flags |= RENDERVIEW_DRAWVIEWMODEL; } RenderView( m_View, nClearFlags, flags ); g_pClientMode->PostRender(); engine->EngineStats_EndFrame(); #if !defined( _X360 ) // Stop stubbing the material system so we can see the budget panel matStub.End(); #endif CViewSetup view2d; // Draw all of the UI stuff "fullscreen" view2d.x = rect->x; view2d.y = rect->y; view2d.width = rect->width; view2d.height = rect->height; render->Push2DView( view2d, 0, NULL, GetFrustum() ); render->VGui_Paint( PAINT_UIPANELS ); render->PopView( GetFrustum() ); }