Exemple #1
0
void CStage::UpdateListener()
{
	Matrix34 cam_pose;
	Camera *pCamera;

	// get the pose of the current camera
	pCamera = this->GetCurrentCamera();
	if( pCamera )
	{
		pCamera->GetPose( cam_pose );
	}
	else
	{
		CCopyEntity* pEntity = this->GetEntitySet()->GetCameraEntity();
		if( pEntity )
			cam_pose = pEntity->GetWorldPose();
		else
			cam_pose.Identity();
	}

	// update listener for sound manager
	GetSoundManager().SetListenerPose( cam_pose ); 

	CCopyEntity *pCameraEntity = this->GetEntitySet()->GetCameraEntity();
	if( pCameraEntity )
		GetSoundManager().SetListenerVelocity( pCameraEntity->Velocity() ); 

	GetSoundManager().CommitDeferredSettings();
}
Exemple #2
0
CCopyEntity *EntityManager::CreateEntity( CCopyEntityDesc& rCopyEntityDesc )
{
	if( !rCopyEntityDesc.pBaseEntityHandle )
		return NULL;

	BaseEntityHandle& rBaseEntityHandle = *(rCopyEntityDesc.pBaseEntityHandle);

//	LOG_PRINT( "creating a copy entity of " + string(rBaseEntityHandle.GetBaseEntityName()) );

	BaseEntity *pBaseEntity = GetBaseEntity( rBaseEntityHandle );
	if( !pBaseEntity )
		return NULL;

	BaseEntity& rBaseEntity = *(pBaseEntity);

//	LOG_PRINT( "checking the initial position of " + rBaseEntity.GetNameString() );

	// determine the entity group id
	// priority (higher to lower):
	// (id set to copy entity desc) -> (id set to base entity)
	int entity_group_id = ENTITY_GROUP_INVALID_ID;
	if( rCopyEntityDesc.sGroupID != ENTITY_GROUP_INVALID_ID )
	{
		entity_group_id = rCopyEntityDesc.sGroupID;
	}
	else
	{
		// try the group of base entity
		entity_group_id = rBaseEntity.GetEntityGroupID();
	}

	if( false )
//	if( !rBaseEntity.m_bNoClip )
//	 && rCopyEntityDesc.DontCreateIfOverlapIsDetected )
	{	// check for overlaps with other entities
		// to see if the new entity is in a valid position
//		if( rCopyEnt.bvType == BVTYPE_AABB || rCopyEnt.bvType == BVTYPE_DOT )
//		{
			STrace tr;
			tr.sTraceType = TRACETYPE_IGNORE_NOCLIP_ENTITIES;
			tr.vEnd       = rCopyEntityDesc.WorldPose.vPosition;
			tr.bvType     = rBaseEntity.m_BoundingVolumeType;
			tr.aabb       = rBaseEntity.m_aabb;
			tr.GroupIndex = entity_group_id;
			if( rBaseEntity.m_bNoClipAgainstMap )
				tr.sTraceType |= TRACETYPE_IGNORE_MAP;
			m_pStage->CheckPosition( tr );
			if(tr.in_solid)
			{
				LOG_PRINT( " - cannot create a copy entity due to overlaps: " + string(rBaseEntityHandle.GetBaseEntityName()) );
				return NULL;	// specified position is invalid - cannot create entity
			}
//		}
	}

//	LOG_PRINT( "the copy entity of " + rBaseEntity.GetNameString() + " is in a valid position" );

	// create an entity
	shared_ptr<CCopyEntity> pNewEntitySharedPtr = m_pEntityFactory->CreateEntity( rCopyEntityDesc.TypeID );
	if( !pNewEntitySharedPtr )
	{
		/// too many entities or no entity is defined for rCopyEntityDesc.TypeID
		LOG_PRINT_ERROR( " - cannot create a copy entity of '" + string(rBaseEntityHandle.GetBaseEntityName()) + "'" );
		return NULL;
	}

	CCopyEntity *pNewCopyEnt = pNewEntitySharedPtr.get();

	pNewCopyEnt->m_TypeID    = rCopyEntityDesc.TypeID;

	// copy parameter values from base entity (entity attributes set)
	SetBasicEntityAttributes( pNewCopyEnt, rBaseEntity );

	// copy parameter values from entity desc

	pNewCopyEnt->SetName( rCopyEntityDesc.strName );

	pNewCopyEnt->SetWorldPose( rCopyEntityDesc.WorldPose );

	pNewCopyEnt->Velocity()  = rCopyEntityDesc.vVelocity;
	pNewCopyEnt->fSpeed      = rCopyEntityDesc.fSpeed;

	pNewCopyEnt->m_MeshHandle = rCopyEntityDesc.MeshObjectHandle;

	pNewCopyEnt->f1 = rCopyEntityDesc.f1;
	pNewCopyEnt->f2 = rCopyEntityDesc.f2;
	pNewCopyEnt->f3 = rCopyEntityDesc.f3;
	pNewCopyEnt->f4 = rCopyEntityDesc.f4;
	pNewCopyEnt->f5 = 0.0f;
	pNewCopyEnt->s1 = rCopyEntityDesc.s1;
	pNewCopyEnt->v1 = rCopyEntityDesc.v1;
	pNewCopyEnt->v2 = rCopyEntityDesc.v2;
	pNewCopyEnt->iExtraDataIndex = rCopyEntityDesc.iExtraDataIndex;
	pNewCopyEnt->pUserData = rCopyEntityDesc.pUserData;

	pNewCopyEnt->sState   = 0;
	pNewCopyEnt->bInSolid = false;

	pNewCopyEnt->GroupIndex = entity_group_id;

//	pNewCopyEnt->GroupIndex = rCopyEntityDesc.sGroupID;

	pNewCopyEnt->touch_plane.dist   = 0;
	pNewCopyEnt->touch_plane.normal = Vector3(0,0,0);

	InitEntity( pNewEntitySharedPtr, rCopyEntityDesc.pParent, pBaseEntity, rCopyEntityDesc.pPhysActorDesc );

	pNewCopyEnt->Init( rCopyEntityDesc );

	LOG_PRINT_VERBOSE( " - created a copy entity of " + rBaseEntity.GetNameString() );

	return pNewCopyEnt;
}
Exemple #3
0
void EntityManager::InitEntity( boost::shared_ptr<CCopyEntity> pNewCopyEntPtr,
							 CCopyEntity *pParent,
							 BaseEntity *pBaseEntity,
							 CActorDesc* pPhysActorDesc )
{
	CCopyEntity* pNewCopyEnt = pNewCopyEntPtr.get();

	// Mark the entity as in use
	pNewCopyEnt->inuse = true;

	pNewCopyEnt->m_pSelf = pNewCopyEntPtr;

	pNewCopyEnt->pBaseEntity = pBaseEntity;
	BaseEntity& rBaseEntity = (*pBaseEntity);

	pNewCopyEnt->m_pStage = m_pStage;

	// set id and increment the counter
	pNewCopyEnt->m_ID = m_EntityIDConter++;

	// z-sort is disabled by default initialization
	// Entities that have translucent polygons have to turn on their copy entities'
	// 'BETYPE_USE_ZSORT' in InitCopyEntity()
	if( pNewCopyEnt->m_TypeID == CCopyEntityTypeID::ALPHA_ENTITY )
	{
		// For alpha entity, always use the  z-sorting
		pNewCopyEnt->RaiseEntityFlags( BETYPE_USE_ZSORT );
	}
	else
	{
		// Otherwise, disable z-sorting by default
		pNewCopyEnt->ClearEntityFlags( BETYPE_USE_ZSORT );
	}

	// set the glare type
	if( rBaseEntity.m_EntityFlag & BETYPE_GLARESOURCE )
	{
		pNewCopyEnt->RaiseEntityFlags( BETYPE_GLARESOURCE );
	}
	else if( rBaseEntity.m_EntityFlag & BETYPE_GLAREHINDER )
	{
		pNewCopyEnt->RaiseEntityFlags( BETYPE_GLAREHINDER );
	}

	// update world aabb
	pNewCopyEnt->world_aabb.TransformCoord( pNewCopyEnt->local_aabb, pNewCopyEnt->GetWorldPosition() );


	// link the new copy-entity to the top of 'm_pEntityInUse'
	if( m_pEntityInUse )
		pNewCopyEnt->SetNext( m_pEntityInUse );
	else
		pNewCopyEnt->SetNextToNull(); // first entity in the link list

	m_pEntityInUse = pNewCopyEntPtr;


	// set the created time of the entity
	pNewCopyEnt->m_CreatedTime = m_pStage->GetElapsedTime();

	// set parent entity
	pNewCopyEnt->m_pParent = pParent;
	if( pNewCopyEnt->m_pParent )
	{
		// 'pNewCopyEnt' is being created as a child of another copy entity
		pNewCopyEnt->m_pParent->AddChild( pNewCopyEnt->m_pSelf );	// establish link from the parent to this entity
	}

//	LOG_PRINT( "linking a copy entity of " + rBaseEntity.GetNameString() + " to the tree" );

	// link the new copy-entity to the entity-tree
	Link( pNewCopyEnt );

	// update light information
	if( pNewCopyEnt->Lighting() )
	{
		pNewCopyEnt->ClearLights();
//		UpdateLightInfo( pNewCopyEnt );

		pNewCopyEnt->sState |= CESTATE_LIGHT_INFORMATION_INVALID;
	}

	// create object for physics simulation
	if( pNewCopyEnt->GetEntityFlags() & BETYPE_RIGIDBODY )
	{
		CActor *pPhysActor = NULL;
		if( pPhysActorDesc )
		{
			pPhysActorDesc->WorldPose = pNewCopyEnt->GetWorldPose();// * pNewCopyEnt->GetActorLocalPose();
			pPhysActorDesc->BodyDesc.LinearVelocity = pNewCopyEnt->Velocity();

			// each entity has its own actor desc
			pPhysActor = m_pStage->GetPhysicsScene()->CreateActor( *pPhysActorDesc );
		}
		else if( pBaseEntity->GetPhysicsActorDesc().IsValid() )
		{
			// actor desc is defined by entity attributes
			CActorDesc actor_desc = pBaseEntity->GetPhysicsActorDesc();
			actor_desc.WorldPose = pNewCopyEnt->GetWorldPose();
			actor_desc.BodyDesc.LinearVelocity = pNewCopyEnt->Velocity();
//			pNewCopyEnt->pPhysicsActor = m_pStage->GetPhysicsScene()->CreateActor( actor_desc );
			pPhysActor = m_pStage->GetPhysicsScene()->CreateActor( actor_desc );
		}

		if( pPhysActor )
		{
			pNewCopyEnt->m_vecpPhysicsActor.resize( 1 );
			pNewCopyEnt->m_vecpPhysicsActor[0] = pPhysActor;
			pPhysActor->m_pFrameworkData = pNewCopyEnt;
		}
	}

	// When all the basic properties are copied, InitCopyEntity() is called to 
	// do additional initialization specific to each base entity.
	rBaseEntity.InitCopyEntity( pNewCopyEnt );
}
void GravityGun::Update( float dt )
{
    if( !IsWeaponSelected() )
        return;

//	Vector3 vOwnerMuzzlePos = rWeaponSystem.m_vMuzzlePosition + rWeaponSystem.m_vMuzzleDirection * 0.25f
//		                                                      + rWeaponSystem.m_vMuzzleDir_Up * 0.90f;

    Vector3 vOwnerMuzzlePos = m_MuzzleEndWorldPose.vPosition;

    CCopyEntity *pTarget = m_Target.GetRawPtr();
    if( pTarget )
    {
        // calc the translation from the center of the target to the muzzle position
        Vector3 vDist = vOwnerMuzzlePos - pTarget->GetWorldPosition();

        float fDistSq = Vec3LengthSq(vDist);
        if( m_fMaxRange * m_fMaxRange < fDistSq )
        {
            m_iHoldingTargetToggle = 0;
//			m_pTarget->pPhysicsActor->SetAllowFreezing( true );
            m_Target.Reset();
            return;
        }

        STrace tr;
        tr.bvType = BVTYPE_DOT;
        tr.vStart = vOwnerMuzzlePos;
        Vector3 vGoal = pTarget->GetWorldPosition();
        tr.vGoal = vGoal;
        tr.sTraceType = TRACETYPE_IGNORE_NOCLIP_ENTITIES;
        /*
        		CTrace tr;
        		tr.BVType    = BVTYPE_DOT;
        		tr.vStart    = &vOwnerMuzzlePos;
        		tr.vGoal     = &pTarget->GetWorldPosition();
        		tr.TypeFlags = CTrace::FLAG_IGNORE_NOCLIP_ENTITIES;//TRACETYPE_IGNORE_NOCLIP_ENTITIES;
        */
        // check trace
        CStageSharedPtr pStage = m_pStage.lock();
        if( pStage )
            pStage->ClipTrace( tr );

        if( tr.pTouchedEntity != pTarget )
        {
            // found an obstacle between the player and the target object
            // - unable to hold the target any more
            m_iHoldingTargetToggle = 0;
//			m_pTarget->pPhysicsActor->SetAllowFreezing( true );
            m_Target.Reset();
            return;
        }

        if( fDistSq < m_fGraspRange * m_fGraspRange || m_aTriggerState[1] == 1 )
        {
            // the gravity gun is holding the target object

            // account for the target object's size so that it does not bump into the shooter
            float fDist = sqrtf(fDistSq);
            Vector3 vDir = vDist / fDist;		// normalization
            fDist -= ( pTarget->fRadius + 0.2f );
            vDist = vDir * fDist;

            // calc relative velocity
            Vector3 vRVel = pTarget->Velocity() - m_vMuzzleEndVelocity;

            Vector3 vForce;
//			vForce = m_fPosGain * vDist - m_fSpeedGain * vRVel;
//			m_pTarget->ApplyWorldImpulse( vForce, m_pTarget->GetWorldPosition());


            if( 6.0f < fDist )
                vForce = vDir * 6.0f * 2.5f;
            else if( fDist < 0.6f )
                vForce = vDir * fDist * 8.0f;
            else
//				vForce = vDir * fDist * 2.5f;
                vForce = vDir * ( fDist * 2.0f + 3.0f );

            vForce += m_vMuzzleEndVelocity;

            physics::CActor *pPhysicsActor = pTarget->GetPrimaryPhysicsActor();
            if( pPhysicsActor )
                pPhysicsActor->SetLinearVelocity( vForce );

            /*			Vector3 vPos = m_pTarget->pPhysicsActor->GetPosition();
            			Vector3 vVel = m_pTarget->pPhysicsActor->GetVelocity();
            			SmoothCD( vPos, vPos + vDist, vVel, 0.25f, dt );

            			if( 12.0f * 12.0f < Vec3LengthSq(vVel) )
            			{
            				Vec3Normalize( vVel, vVel );
            				vVel *= 12.0f;
            			}
            			m_pTarget->pPhysicsActor->SetVelocity( vVel );
            */
            return;
        }
        else
        {
            // lost control of the target
            m_iHoldingTargetToggle = 0;

            ReleaseObject();

            return;
        }
    }
}