//----------------------------------------------------------------------------- // appply translation to this matrix in the input space //----------------------------------------------------------------------------- inline void VMatrix::PreTranslate( const Vector &vTrans ) { Vector tmp; Vector3DMultiplyPosition( *this, vTrans, tmp ); m[0][3] = tmp.x; m[1][3] = tmp.y; m[2][3] = tmp.z; }
void ViewTransform( const Vector &worldSpace, Vector &viewSpace ) { const VMatrix &viewMatrix = engine->WorldToViewMatrix(); Vector3DMultiplyPosition( viewMatrix, worldSpace, viewSpace ); }
inline Vector VMatrix::VMul4x3( const Vector &vVec ) const { Vector vResult; Vector3DMultiplyPosition( *this, vVec, vResult ); return vResult; }
void C_Hairball::ClientThink() { // Do some AI-type stuff.. move the entity around. //C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); //m_vecAngles = SetAbsAngles( pPlayer->GetAbsAngles() ); // copy player angles. Assert( !GetMoveParent() ); // Sophisticated AI. m_flCurSpinTime += gpGlobals->frametime; if ( m_flCurSpinTime < m_flSpinDuration ) { float div = m_flCurSpinTime / m_flSpinDuration; QAngle angles = GetLocalAngles(); angles.x += m_flSpinRateX * SmoothCurve( div ); angles.y += m_flSpinRateY * SmoothCurve( div ); SetLocalAngles( angles ); } else { // Flip between stopped and starting. if ( fabs( m_flSpinRateX ) > 0.01f ) { m_flSpinRateX = m_flSpinRateY = 0; m_flSpinDuration = RandomFloat( 1, 2 ); } else { static float flXSpeed = 3; static float flYSpeed = flXSpeed * 0.1f; m_flSpinRateX = RandomFloat( -M_PI*flXSpeed, M_PI*flXSpeed ); m_flSpinRateY = RandomFloat( -M_PI*flYSpeed, M_PI*flYSpeed ); m_flSpinDuration = RandomFloat( 1, 4 ); } m_flCurSpinTime = 0; } if ( m_flSitStillTime > 0 ) { m_flSitStillTime -= gpGlobals->frametime; if ( m_flSitStillTime <= 0 ) { // Shoot out some random lines and find the longest one. m_vMoveDir.Init( 1, 0, 0 ); float flLongestFraction = 0; for ( int i=0; i < 15; i++ ) { Vector vDir( RandomFloat( -1, 1 ), RandomFloat( -1, 1 ), RandomFloat( -1, 1 ) ); VectorNormalize( vDir ); trace_t trace; UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin() + vDir * 10000, MASK_SOLID, NULL, COLLISION_GROUP_NONE, &trace ); if ( trace.fraction != 1.0 ) { if ( trace.fraction > flLongestFraction ) { flLongestFraction = trace.fraction; m_vMoveDir = vDir; } } } m_vMoveDir *= 650; // set speed. m_flSitStillTime = -1; // Move in this direction.. } } else { // Move in the specified direction. Vector vEnd = GetAbsOrigin() + m_vMoveDir * gpGlobals->frametime; trace_t trace; UTIL_TraceLine( GetAbsOrigin(), vEnd, MASK_SOLID, NULL, COLLISION_GROUP_NONE, &trace ); if ( trace.fraction < 1 ) { // Ok, stop moving. m_flSitStillTime = RandomFloat( 1, 3 ); } else { SetLocalOrigin( GetLocalOrigin() + m_vMoveDir * gpGlobals->frametime ); } } // Transform the base hair positions so we can lock them down. VMatrix mTransform; mTransform.SetupMatrixOrgAngles( GetLocalOrigin(), GetLocalAngles() ); for ( int i=0; i < m_HairPositions.Count(); i++ ) { Vector3DMultiplyPosition( mTransform, m_HairPositions[i], m_TransformedHairPositions[i] ); } if ( m_bFirstThink ) { m_bFirstThink = false; for ( int i=0; i < m_HairPositions.Count(); i++ ) { for ( int j=0; j < m_nNodesPerHair; j++ ) { m_Nodes[i*m_nNodesPerHair+j].Init( m_TransformedHairPositions[i] ); } } } // Simulate the physics and apply constraints. m_Physics.Simulate( m_Nodes.Base(), m_Nodes.Count(), &m_Delegate, gpGlobals->frametime, 0.98 ); }