void CNPC_SecobModportal1::Touch( CBaseEntity *pOther )
{
	BaseClass::Touch( pOther );
	


	// Did the player touch me?
	if ( pOther->IsPlayer() )
	{
	
		const char *PlayerSteamID = engine->GetPlayerNetworkIDString(pOther->edict()); //Finds the current players Steam ID.		
		if( PlayerSteamID == NULL)
		return;
		char Portal2Name[ 512 ];
		Q_strncpy( Portal2Name, "Portal2_" ,sizeof(Portal2Name));
		Q_strncat( Portal2Name, PlayerSteamID,sizeof(Portal2Name), COPY_ALL_CHARACTERS );
		
		// We look for Portal2 for our teleport point because we are Portal1.
		CBaseEntity *pEnt = NULL;
		pEnt = gEntList.FindEntityByName( pEnt, Portal2Name, NULL, pOther, pOther );
		if (!pEnt )
		{
			return;
		}
	
	EmitSound( "PortalPlayer.EnterPortal" );
	
	//PORTAL TRIGGER CODE.
			// Don't touch entities that came through us and haven't left us yet.
		/*EHANDLE hHandle;
		hHandle = pOther;
		if ( m_hDisabledForEntities.Find(hHandle) != m_hDisabledForEntities.InvalidIndex() )
		{
			Msg("    IGNORED\n", GetDebugName(), pOther->GetDebugName() );
			return;
		}
		Pickup_ForcePlayerToDropThisObject( pOther );*/
	
		pOther->SetGroundEntity( NULL );
	
	// Build a this --> remote transformation
		VMatrix matMyModelToWorld, matMyInverse;
		matMyModelToWorld = pOther->EntityToWorldTransform();
		MatrixInverseGeneral ( matMyModelToWorld, matMyInverse );

		// Teleport our object
		VMatrix matRemotePortalTransform = pEnt->EntityToWorldTransform();
		Vector ptNewOrigin, vLook, vRight, vUp, vNewLook;
		pOther->GetVectors( &vLook, &vRight, &vUp );

		// Move origin
		ptNewOrigin = matMyInverse * pOther->GetAbsOrigin();
		ptNewOrigin = matRemotePortalTransform * Vector( ptNewOrigin.x, -ptNewOrigin.y, ptNewOrigin.z );

		// Re-aim camera
		vNewLook	= matMyInverse.ApplyRotation( vLook );
		vNewLook	= matRemotePortalTransform.ApplyRotation( Vector( -vNewLook.x, -vNewLook.y, vNewLook.z ) );

		// Reorient the physics
	 	Vector vVelocity, vOldVelocity;
		pOther->GetVelocity( &vOldVelocity );
		vVelocity = matMyInverse.ApplyRotation( vOldVelocity );
		vVelocity = matRemotePortalTransform.ApplyRotation( Vector( -vVelocity.x, -vVelocity.y, vVelocity.z ) );

				QAngle qNewAngles;
		VectorAngles( vNewLook, qNewAngles );
		
		if ( pOther->IsPlayer() )
		{
			((CBasePlayer*)pOther)->SnapEyeAngles(qNewAngles);
		}

		Vector vecOldPos = pOther->WorldSpaceCenter();


		// place player at the new destination

		pOther->Teleport( &ptNewOrigin, &qNewAngles, &vVelocity );

		// test collision on the new teleport location
		Vector vMin, vMax, vCenter;
		pOther->CollisionProp()->WorldSpaceAABB( &vMin, &vMax );
		vCenter = (vMin + vMax) * 0.5f;
		vMin -= vCenter;
		vMax -= vCenter;

		Vector vStart, vEnd;
		vStart	= ptNewOrigin;
		vEnd	= ptNewOrigin;

		Ray_t ray;
		ray.Init( vStart, vEnd, vMin, vMax );
		trace_t tr;
		this->TestCollision( ray, pOther->PhysicsSolidMaskForEntity(), tr );

		// Teleportation caused us to hit something, deal with it.
		if ( tr.DidHit() )
		{
			
		}
		
		EmitSound( "PortalPlayer.ExitPortal" );
		
		Vector forward, right, up;

		Vector oldorigin = pOther->GetAbsOrigin();

		AngleVectors ( pOther->GetAbsAngles(), &forward, &right, &up);
		
		// Try to move into the world
		if ( !FindPassableSpace( pOther, forward, 1, oldorigin ) )
		{
			if ( !FindPassableSpace( pOther, right, 1, oldorigin ) )
			{
				if ( !FindPassableSpace( pOther, right, -1, oldorigin ) )		// left
				{
					if ( !FindPassableSpace( pOther, up, 1, oldorigin ) )	// up
					{
						if ( !FindPassableSpace( pOther, up, -1, oldorigin ) )	// down
						{
							if ( !FindPassableSpace( pOther, forward, -1, oldorigin ) )	// back
							{
								pOther->TakeDamage( CTakeDamageInfo( this, this, 1000, DMG_DISSOLVE ) );
							}
						}
					}
				}
			}
		}
	pOther->SetAbsOrigin( oldorigin );
	}
}
예제 #2
0
//-----------------------------------------------------------------------------
// Purpose: Upon touching a non-filtered entity, CTriggerPortal teleports them to it's
//			remote portal location.
// Input  : *pOther - 
//-----------------------------------------------------------------------------
void CTriggerPortal::Touch( CBaseEntity *pOther )
{
	// If we are enabled, and allowed to react to the touched entity
	if ( PassesTriggerFilters(pOther) )
	{
		// If we somehow lost our pointer to the remote portal, get a new one
		if ( m_hRemotePortal == NULL )
		{
			Disable();
			return;
		}

		bool bDebug = portal_debug.GetBool();
		if ( bDebug )
		{
			Msg("%s TOUCH: for %s\n", GetDebugName(), pOther->GetDebugName() );
		}

		// Don't touch entities that came through us and haven't left us yet.
		EHANDLE hHandle;
		hHandle = pOther;
		if ( m_hDisabledForEntities.Find(hHandle) != m_hDisabledForEntities.InvalidIndex() )
		{
			Msg("    IGNORED\n", GetDebugName(), pOther->GetDebugName() );
			return;
		}

		Pickup_ForcePlayerToDropThisObject( pOther );

		// de-ground this entity
        pOther->SetGroundEntity( NULL );

		// Build a this --> remote transformation
		VMatrix matMyModelToWorld, matMyInverse;
		matMyModelToWorld = this->EntityToWorldTransform();
		MatrixInverseGeneral ( matMyModelToWorld, matMyInverse );

		// Teleport our object
		VMatrix matRemotePortalTransform = m_hRemotePortal->EntityToWorldTransform();
		Vector ptNewOrigin, vLook, vRight, vUp, vNewLook;
		pOther->GetVectors( &vLook, &vRight, &vUp );

		// Move origin
		ptNewOrigin = matMyInverse * pOther->GetAbsOrigin();
		ptNewOrigin = matRemotePortalTransform * Vector( ptNewOrigin.x, -ptNewOrigin.y, ptNewOrigin.z );

		// Re-aim camera
		vNewLook	= matMyInverse.ApplyRotation( vLook );
		vNewLook	= matRemotePortalTransform.ApplyRotation( Vector( -vNewLook.x, -vNewLook.y, vNewLook.z ) );

		// Reorient the physics
	 	Vector vVelocity, vOldVelocity;
		pOther->GetVelocity( &vOldVelocity );
		vVelocity = matMyInverse.ApplyRotation( vOldVelocity );
		vVelocity = matRemotePortalTransform.ApplyRotation( Vector( -vVelocity.x, -vVelocity.y, vVelocity.z ) );

		QAngle qNewAngles;
		VectorAngles( vNewLook, qNewAngles );
		
		if ( pOther->IsPlayer() )
		{
			((CBasePlayer*)pOther)->SnapEyeAngles(qNewAngles);
		}

		Vector vecOldPos = pOther->WorldSpaceCenter();
		if ( bDebug )
		{
			NDebugOverlay::Box( pOther->GetAbsOrigin(), pOther->WorldAlignMins(), pOther->WorldAlignMaxs(), 255,0,0, 8, 20 );
			NDebugOverlay::Axis( pOther->GetAbsOrigin(), pOther->GetAbsAngles(), 10.0f, true, 50 );
		}

		// place player at the new destination
		CTriggerPortal *pPortal = m_hRemotePortal.Get();
		pPortal->DisableForIncomingEntity( pOther );
		pOther->Teleport( &ptNewOrigin, &qNewAngles, &vVelocity );

		if ( bDebug )
		{
			NDebugOverlay::Box( pOther->GetAbsOrigin(), pOther->WorldAlignMins(), pOther->WorldAlignMaxs(), 0,255,0, 8, 20 );
			NDebugOverlay::Line( vecOldPos, pOther->WorldSpaceCenter(), 0,255,0, true, 20 );
			NDebugOverlay::Axis( pOther->GetAbsOrigin(), pOther->GetAbsAngles(), 10.0f, true, 50 );

			Msg("%s TELEPORTED: %s\n", GetDebugName(), pOther->GetDebugName() );
		}

		// test collision on the new teleport location
		Vector vMin, vMax, vCenter;
		pOther->CollisionProp()->WorldSpaceAABB( &vMin, &vMax );
		vCenter = (vMin + vMax) * 0.5f;
		vMin -= vCenter;
		vMax -= vCenter;

		Vector vStart, vEnd;
		vStart	= ptNewOrigin;
		vEnd	= ptNewOrigin;

		Ray_t ray;
		ray.Init( vStart, vEnd, vMin, vMax );
		trace_t tr;
		pPortal->TestCollision( ray, pOther->PhysicsSolidMaskForEntity(), tr );

		// Teleportation caused us to hit something, deal with it.
		if ( tr.DidHit() )
		{
			
		}

		
	}
}
예제 #3
0
			if(sv_surface_rotate.GetBool())
			{
				angle = view->GetViewSetup()->angles.y+180.0f;

				//ConMsg("Angle = %f\n", angle);
				pRenderContext->Rotate(angle, 0.0f, 0.0f, 1.0f);

				//VMatrix rotationMatrix2 = SetupMatrixAngles(view->GetViewSetup()->angles);
				//pRenderContext->MultMatrix(rotationMatrix2);
				//VMatrix rotationMatrix = rotationMatrix2.InverseTR(); //SetupMatrixAngles(-(view->GetViewSetup()->angles));

				rotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), -angle);
				invRotationMatrix = SetupMatrixAxisRot(Vector(0.0f, 0.0f, 1.0f), angle);
				Vector eye = view->GetViewSetup()->origin;
				transformedEye = (eye-center)*(1.0f/m_flRadius);
				transformedEye = rotationMatrix.ApplyRotation(transformedEye);
			}
			else
			{
				rotationMatrix.Identity();
				invRotationMatrix.Identity();
				transformedEye.Init();
				angle = 0.0f;
			}

			if(sv_surface_use_tiler.GetBool())
			{
				tiler->beginFrame(Point3D(0.0f, 0.0f, 0.0f), (void*)&pRenderContext, !(sv_surface_draw_margin.GetBool()));
			}
			else
			{