Exemplo n.º 1
0
void CWeaponGravityGun::AddPellet( CGravityPellet *pPellet, CBaseEntity *pAttach, const Vector &surfaceNormal )
{
	Assert(m_pelletCount<MAX_PELLETS);

	m_activePellets[m_pelletCount].localNormal = surfaceNormal;
	if ( pAttach )
	{
		EntityMatrix tmp;
		tmp.InitFromEntity( pAttach );
		m_activePellets[m_pelletCount].localNormal = tmp.WorldToLocalRotation( surfaceNormal );
	}
	m_activePellets[m_pelletCount].pellet = pPellet;
	m_activePellets[m_pelletCount].parent = pAttach;
	m_pelletCount++;
}
void CPhysThruster::SetupForces( IPhysicsObject *pPhys, Vector &linear, AngularImpulse &angular )
{
	Vector forward;
	AngleVectors( GetLocalAngles(), &forward );
	forward = forward * m_force;

	// multiply the force by mass (it's actually just an acceleration)
	if ( m_spawnflags & SF_THRUST_MASS_INDEPENDENT )
	{
		forward = forward * pPhys->GetMass();
	}
	
	EntityMatrix xform;
	xform.InitFromEntity( m_attachedObject );
	Vector origin = xform.LocalToWorld( m_localOrigin );
	forward = xform.LocalToWorldRotation( forward );

	// Adjust for the position of the thruster -- apply proper torque)
	pPhys->CalculateVelocityOffset( forward, origin, linear, angular );

	// Stay in local space always if this flag is set
	if ( m_spawnflags & SF_THRUST_LOCAL_ORIENTATION )
	{
		linear = xform.WorldToLocalRotation( linear );
	}

	if ( !(m_spawnflags & SF_THRUST_FORCE) )
	{
		// clear out force
		linear.Init();
	}

	if ( !(m_spawnflags & SF_THRUST_TORQUE) )
	{
		// clear out torque
		angular.Init();
	}
}