Exemplo n.º 1
0
string
AttachedClauses::Print_str(void){
if(!IsAttached())
   return GetKnowledge()->Print_str()+" <<";
if(IsAttached() && ! WereUnified())
   return GetKnowledge()->Print_str()+" ?= "+GetAttached()->Print_str();
if(IsAttached() && WereUnified())
   return GetKnowledge()->Print_str()+" == "+GetAttached()->Print_str()+" >> "+GetUnified()->Print_str();

cerr<<"\nAttachedClauses::Print_str(void) .....FATAL ERROR(inappropriate case";
throw(INAPPROPRIATE_CASE);
exit(EXIT_FAILURE);
}
Exemplo n.º 2
0
string
AttachedClauses::Print_Tex_str(void){
if(!IsAttached())
   return GetKnowledge()->Print_Tex_str();
if(IsAttached() && ! WereUnified())
   return GetKnowledge()->Print_Tex_str()+" \\stackrel{?}{=} "+GetAttached()->Print_Tex_str();
if(IsAttached() && WereUnified())
   return GetKnowledge()->Print_Tex_str()+" = "+GetAttached()->Print_Tex_str()+" \\equiv " +GetUnified()->Print_Tex_str();

cerr<<"\nAttachedClauses::Print_Tex_str... warning(inappropriate case)\n";
throw(INAPPROPRIATE_CASE);
exit(EXIT_FAILURE);

}
Exemplo n.º 3
0
void LoomWidget::UpdateStage()
{
    Pos dir;
    double full;

    double w = BridgeWidget::GetWidth();
    double h = BridgeWidget::GetHeight();

    switch(_technique)
    {
        case SLIDE_LEFT:
            dir = Pos(1,0);
            full = w;
        break;

        case SLIDE_RIGHT:
            dir = Pos(-1,0);
            full = w;
        break;

        case SLIDE_UP:
            dir = Pos(0,1);
            full = h;
        break;

        case SLIDE_DOWN:
            dir = Pos(0,-1);
            full = h;
        break;
    }
    
    int visible_pixels = full * _stage;
    double begin = full - _min_visible_pixels;

    if ( visible_pixels >= _min_visible_pixels )
    {
        
        GetAttached()->SetPosition( dir * full*(1-_stage) );
    }
    else
    {
        _stage = 1 - begin/full;
        GetAttached()->SetPosition( dir*begin );
        if (!_loom_mode) { _running=false; _one_more_dirty=true; OnVanishStop.Send(); }
    }
}
Exemplo n.º 4
0
void
AttachedClauses::Unify(vector<string>* __param){
if(GetKnowledge() == NULL || GetAttached() == NULL){
   cerr<<"\nAttachedClauses::Unify ... FATAL ERROR (bad initialization)\n";
   throw(INAPPROPRIATE_CASE);
   exit(EXIT_FAILURE);
   }
if((GetKnowledge()->GetNonAffineInequations()->size() > 0 ) && (GetAttached()->GetNonAffineInequations()->size() > 0)){
   SetUnifiedClauses(GetKnowledge()->Unify(GetAttached(),__param));
   WereUnified(GetUnified() != NULL);
/*   cout<<"\nAttachedClauses::Unify ... F\n";
   if(WereUnified())
      Print();*/
   return;
   }
WereUnified(false);
return;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Output : float
//-----------------------------------------------------------------------------
float CGrabController::ComputeError()
{
	if ( m_errorTime <= 0 )
		return 0;

	CBaseEntity *pAttached = GetAttached();
	if ( pAttached )
	{
		Vector pos;
		IPhysicsObject *pObj = pAttached->VPhysicsGetObject();
		
		if ( pObj )
		{	
			pObj->GetShadowPosition( &pos, NULL );

			float error = (m_shadow.targetPosition - pos).Length();
			if ( m_errorTime > 0 )
			{
				if ( m_errorTime > 1 )
				{
					m_errorTime = 1;
				}
				float speed = error / m_errorTime;
				if ( speed > m_shadow.maxSpeed )
				{
					error *= 0.5;
				}
				m_error = (1-m_errorTime) * m_error + error * m_errorTime;
			}
		}
		else
		{
			DevMsg( "Object attached to Physcannon has no physics object\n" );
			DetachEntity( false );
			return 9999; // force detach
		}
	}
	
	if ( pAttached->IsEFlagSet( EFL_IS_BEING_LIFTED_BY_BARNACLE ) )
	{
		m_error *= 3.0f;
	}

	m_errorTime = 0;

	return m_error;
}
Exemplo n.º 6
0
void CGrabController::DetachEntity( void )
{
	CBaseEntity *pEntity = GetAttached();
	if ( pEntity )
	{
		IPhysicsObject *pPhys = pEntity->VPhysicsGetObject();
		if ( pPhys )
		{
			// on the odd chance that it's gone to sleep while under anti-gravity
			pPhys->Wake();
			pPhys->SetDamping( NULL, &m_saveRotDamping );
			PhysClearGameFlags( pPhys, FVPHYSICS_PLAYER_HELD );
		}
	}
	m_attachedEntity = NULL;
	physenv->DestroyMotionController( m_controller );
	m_controller = NULL;
}
void CGrabController::SetTargetPosition( const Vector &target, const QAngle &targetOrientation )
{
	m_shadow.targetPosition = target;
	m_shadow.targetRotation = targetOrientation;

	m_timeToArrive = gpGlobals->frametime;

	CBaseEntity *pAttached = GetAttached();
	if ( pAttached )
	{
		IPhysicsObject *pObj = pAttached->VPhysicsGetObject();
		
		if ( pObj != NULL )
		{
			pObj->Wake();
		}
		else
		{
			DetachEntity( false );
		}
	}
}
void CGrabController::DetachEntity( bool bClearVelocity )
{
	Assert(!PhysIsInCallback());
	CBaseEntity *pEntity = GetAttached();
	if ( pEntity )
	{
		// Restore the LS blocking state
		pEntity->SetBlocksLOS( m_bCarriedEntityBlocksLOS );
		IPhysicsObject *pList[VPHYSICS_MAX_OBJECT_LIST_COUNT];
		int count = pEntity->VPhysicsGetObjectList( pList, ARRAYSIZE(pList) );
		for ( int i = 0; i < count; i++ )
		{
			IPhysicsObject *pPhys = pList[i];
			if ( !pPhys )
				continue;

			// on the odd chance that it's gone to sleep while under anti-gravity
			pPhys->EnableDrag( true );
			pPhys->Wake();
			pPhys->SetMass( m_savedMass[i] );
			pPhys->SetDamping( NULL, &m_savedRotDamping[i] );
			PhysClearGameFlags( pPhys, FVPHYSICS_PLAYER_HELD );
			if ( bClearVelocity )
			{
				PhysForceClearVelocity( pPhys );
			}
			else
			{
				ClampPhysicsVelocity( pPhys, player_walkspeed.GetFloat() * 1.5f, 2.0f * 360.0f );
			}

		}
	}

	m_attachedEntity = NULL;
	physenv->DestroyMotionController( m_controller );
	m_controller = NULL;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CGrabController::UpdateObject( CBasePlayer *pPlayer, float flError )
{
 	CBaseEntity *pEntity = GetAttached();
	if ( !pEntity || ComputeError() > flError || pPlayer->GetGroundEntity() == pEntity || !pEntity->VPhysicsGetObject() )
	{
		return false;
	}

	//Adrian: Oops, our object became motion disabled, let go!
	IPhysicsObject *pPhys = pEntity->VPhysicsGetObject();
	if ( pPhys && pPhys->IsMoveable() == false )
	{
		return false;
	}

	Vector forward, right, up;
	QAngle playerAngles = pPlayer->EyeAngles();
	AngleVectors( playerAngles, &forward, &right, &up );
	
	float pitch = AngleDistance(playerAngles.x,0);

	if( !m_bAllowObjectOverhead )
	{
		playerAngles.x = clamp( pitch, -75, 75 );
	}
	else
	{
		playerAngles.x = clamp( pitch, -90, 75 );
	}

	
	
	// Now clamp a sphere of object radius at end to the player's bbox
	Vector radial = physcollision->CollideGetExtent( pPhys->GetCollide(), vec3_origin, pEntity->GetAbsAngles(), -forward );
	Vector player2d = pPlayer->CollisionProp()->OBBMaxs();
	float playerRadius = player2d.Length2D();
	float radius = playerRadius + fabs(DotProduct( forward, radial ));

	float distance = 24 + ( radius * 2.0f );

	// Add the prop's distance offset
	distance += m_flDistanceOffset;

	Vector start = pPlayer->Weapon_ShootPosition();
	Vector end = start + ( forward * distance );

	trace_t	tr;
	CTraceFilterSkipTwoEntities traceFilter( pPlayer, pEntity, COLLISION_GROUP_NONE );
	Ray_t ray;
	ray.Init( start, end );
	enginetrace->TraceRay( ray, MASK_SOLID_BRUSHONLY, &traceFilter, &tr );

	if ( tr.fraction < 0.5 )
	{
		end = start + forward * (radius*0.5f);
	}
	else if ( tr.fraction <= 1.0f )
	{
		end = start + forward * ( distance - radius );
	}
	Vector playerMins, playerMaxs, nearest;
	pPlayer->CollisionProp()->WorldSpaceAABB( &playerMins, &playerMaxs );
	Vector playerLine = pPlayer->CollisionProp()->WorldSpaceCenter();
	CalcClosestPointOnLine( end, playerLine+Vector(0,0,playerMins.z), playerLine+Vector(0,0,playerMaxs.z), nearest, NULL );

	if( !m_bAllowObjectOverhead )
	{
		Vector delta = end - nearest;
		float len = VectorNormalize(delta);
		if ( len < radius )
		{
			end = nearest + radius * delta;
		}
	}

	//Show overlays of radius
	if ( g_debug_physcannon.GetBool() )
	{
		NDebugOverlay::Box( end, -Vector( 2,2,2 ), Vector(2,2,2), 0, 255, 0, true, 0 );

		NDebugOverlay::Box( GetAttached()->WorldSpaceCenter(), 
							-Vector( radius, radius, radius), 
							Vector( radius, radius, radius ),
							255, 0, 0,
							true,
							0.0f );
	}

	QAngle angles = TransformAnglesFromPlayerSpace( m_attachedAnglesPlayerSpace, pPlayer );
	
	// If it has a preferred orientation, update to ensure we're still oriented correctly.
	Pickup_GetPreferredCarryAngles( pEntity, pPlayer, pPlayer->EntityToWorldTransform(), angles );

	// We may be holding a prop that has preferred carry angles
	if ( m_bHasPreferredCarryAngles )
	{
		matrix3x4_t tmp;
		ComputePlayerMatrix( pPlayer, tmp );
		angles = TransformAnglesToWorldSpace( m_vecPreferredCarryAngles, tmp );
	}

	matrix3x4_t attachedToWorld;
	Vector offset;
	AngleMatrix( angles, attachedToWorld );
	VectorRotate( m_attachedPositionObjectSpace, attachedToWorld, offset );

	SetTargetPosition( end - offset, angles );

	return true;
}
Exemplo n.º 10
0
bool LoomWidget::IsOver(const Pos &pos) const
{
    Pos position = GetAttached()->GetPosition();
    return Rect( position.x, position.y,GetWidth(), GetHeight() ).IsInside(pos.x, pos.y);
}
Exemplo n.º 11
0
void LoomWidget::UpdateSize()
{
    Resize( GetAttached()->GetWidth(), GetAttached()->GetHeight() );
    UpdateStage();
}