void ZInterfaceBackground::Draw(void)
{
#ifdef _FASTDEBUG
	MWidget* pWidget = (MWidget*)ZApplication::GetGameInterface()->GetIDLResource()->FindWidget( "CharSelection");
	if ( pWidget)
	{
		if ( ZApplication::GetGameInterface()->GetState() == GUNZ_CHARSELECTION)
			pWidget->Show( true);
	}

	MPicture* pPicture = (MPicture*)ZApplication::GetGameInterface()->GetIDLResource()->FindWidget( "CharSel_TopScreen");
	if ( pPicture)
		pPicture->SetOpacity( 0);

	return;
#endif

	// Set rendering state
	RSetViewport( 0, 0, RGetScreenWidth(), RGetScreenHeight());
	RGetDevice()->SetRenderState( D3DRS_CULLMODE  ,D3DCULL_CW);					// from rbs rendering
	RGetDevice()->SetRenderState( D3DRS_NORMALIZENORMALS , TRUE );
	RGetDevice()->SetSamplerState( 0, D3DSAMP_MINFILTER , D3DTEXF_LINEAR);		// Texture filtering
	RGetDevice()->SetSamplerState( 0, D3DSAMP_MAGFILTER , D3DTEXF_LINEAR);
	RGetDevice()->SetSamplerState( 0, D3DSAMP_MIPFILTER , D3DTEXF_LINEAR);

	// Set camera position and direction
    rvector vCamPos, vCamDir;
	float fForgDensity;

	switch ( m_nSceneNumber)
	{
		case  LOGIN_SCENE_FIXEDSKY :
		{
			// Fixed camera
			vCamPos = m_vCamPosSt;
			vCamDir = m_vCamDirSt;

			// Fixed fog -> black screen
			fForgDensity = 0.0f;

			break;
		}

		case  LOGIN_SCENE_FALLDOWN :
		{
			// Get current clock
			DWORD dwClock = ( timeGetTime() - m_dwClock);

			/*
			// Show maiet logo
			if ( !m_bShowMaietLogo)
			{
				m_bShowMaietLogo = true;
				ZGetScreenEffectManager()->AddScreenEffect( "maiet_logo");
			}
			*/

			// Set fog density
			fForgDensity = dwClock * 15.0f;

			// Set wait time
			if ( dwClock < 500)
				dwClock = 0;
			else
				dwClock -= 500;

			// Play BGM music
			//PenguinGuy
//			if ( dwClock > 2000)
//				ZApplication::GetSoundEngine()->PlayMusic( true);


			// End of scroll camera
			float fSeed = dwClock * 0.00035f;			// 카메라가 전부 다 내려오기 까지 걸리는 시간( dwClock에 곱해주는 값이
														// 작을수록 빨리 내려옴)
			if ( fSeed > 3.14)
			{
				m_nSceneNumber = LOGIN_SCENE_FIXEDCHAR;
//				m_bShowMaietLogo = false;
			}


			// Move camera position & direction
			float fGain = ( cos( fSeed) + 1.0f) / 2.0f;			// 0 < fGain < 1.0
			vCamPos = m_vCamPosEd + ( m_vCamPosSt - m_vCamPosEd) * fGain;
			vCamDir = m_vCamDirEd + ( m_vCamDirSt - m_vCamDirEd) * fGain;

			//if (m_bShowMaietLogo)
			//{
			//	ZGetScreenEffectManager()->UpdateEffects();
				ZGetScreenEffectManager()->DrawEffects();
			//}

			break;
		}

		case  LOGIN_SCENE_FIXEDCHAR :
		{
			// Show menu UI
			MWidget* pWidget = (MWidget*)ZApplication::GetGameInterface()->GetIDLResource()->FindWidget( "CharSelection");
			if ( pWidget)
			{
				if ( ZApplication::GetGameInterface()->GetState() == GUNZ_CHARSELECTION)
					pWidget->Show( true);
			}
			MPicture* pPicture = (MPicture*)ZApplication::GetGameInterface()->GetIDLResource()->FindWidget( "CharSel_TopScreen");
			if ( pPicture)
				pPicture->SetOpacity( 0);

			// Play BGM music
			//PenguinGuy
//			ZApplication::GetSoundEngine()->PlayMusic( true);

			// Fixed camera
			vCamPos = m_vCamPosEd;
			vCamDir = m_vCamDirEd;


			#define FADE_IN_TIME 500
			DWORD dwClock = ( timeGetTime() - m_dwClock);

			float fGain = ((float)dwClock / (float)FADE_IN_TIME);
			if (fGain > 1.0f)
				fGain = 1.0f;

			SetFogMulti(fGain);

			// Cleared fog
			fForgDensity = 50000.0f;
			break;
		}

		case  LOGIN_SCENE_SELECTCHAR :
		{
			// Get current clock
			DWORD dwClock = ( timeGetTime() - m_dwClock);
			float fGain = ( cos( dwClock * 0.0012f) + 1.0f) / 2.0f;
			//vCamPos = m_vCamPosEd + ( m_vCamPosSt - m_vCamPosEd) * fGain;
			//vCamDir = m_vCamDirEd + ( m_vCamDirSt - m_vCamDirEd) * fGain;
			vCamPos = m_vCamPosSt;
			vCamDir = m_vCamDirSt;

			MPicture* pPicture = (MPicture*)ZApplication::GetGameInterface()->GetIDLResource()->FindWidget( "CharSel_TopScreen");
			if ( pPicture)
			{
				// Set wait time
				if ( dwClock < 2000)
					dwClock = 0;
				else
					dwClock -= 2000;

				// Set opacity of black screen
				int nOpacity = (int)( dwClock / 3.0f);
				if ( nOpacity > 255)
					nOpacity = 255;

				pPicture->SetOpacity( nOpacity);
			}

			// Cleared fog
			fForgDensity = 50000.0f;
			break;
		}

		case  LOGIN_ROAMING :
		{
			#define ROAM_SPEED 10000
			DWORD dwClock = ( timeGetTime() - m_dwClock);

			/*if (GetAsyncKeyState(VK_NUMPAD2) & 0x8000)
				off.y -= 1.0f;
			if (GetAsyncKeyState(VK_NUMPAD8) & 0x8000)
				off.y += 1.0f;
			if (GetAsyncKeyState(VK_NUMPAD4) & 0x8000)
				off.x += 1.0f;
			if (GetAsyncKeyState(VK_NUMPAD6) & 0x8000)
				off.x -= 1.0f;
			if (GetAsyncKeyState(VK_NUMPAD7) & 0x8000)
				off.z -= 1.0f;
			if (GetAsyncKeyState(VK_NUMPAD9) & 0x8000)
				off.z += 1.0f;

			vCamPos = m_vCamPosEd + off;
			vCamDir = m_vCamDirEd;

			// Cleared fog
			fForgDensity = 50000.0f;*/

			float fGain = ((float)dwClock / (float)ROAM_SPEED);
			if (fGain > 1.0f)
				fGain = 1.0f;
			//vCamDir = mapVecs[mapIndex].second - mapVecs[mapIndex].first;
			vCamDir = m_vCamDirEd;
			vCamPos = mapVecs[mapIndex].first + ((mapVecs[mapIndex].second - mapVecs[mapIndex].first) * fGain) + D3DXVECTOR3(0.f,-100.f,0.f);

			if (dwClock > ROAM_SPEED) {
				m_dwClock = timeGetTime();				
				mapIndex = rand() % mapVecs.size();
			}

			//fForgDensity = 50000.0f; //Clear
			fForgDensity = ((-4 * fGain * fGain) + (4 * fGain)) * 20000.f;

			break;
		}
	}

	//Fog adjust
	fForgDensity *= m_fFogMulti;

	// Set camera
	RSetCamera( vCamPos, (vCamPos + vCamDir), rvector( 0, 0, 1));

	// Draw
	RSetProjection( D3DX_PI * 70 / 180, RGetScreenWidth() / (float)RGetScreenHeight(), 10.0f, 15000.0f);
	SetFogState( fForgDensity-10000.0f, fForgDensity, 0x00000000);
	D3DXMatrixTranslation( &m_matWorld, 0, 0, 0);
	RGetDevice()->SetTransform( D3DTS_WORLD, &m_matWorld);

	// Draw background
	if ( m_pLogin)
	{
		m_pLogin->Draw();
		m_pLogin->DrawObjects();
	}

	if ( m_pMapDesc)
		m_pMapDesc->DrawMapDesc();

	// Draw effects(smoke, cloud)
//	ZGetEffectManager()->Draw( timeGetTime());

	// Draw maiet logo effect
//	ZGetScreenEffectManager()->DrawEffects();
}
Beispiel #2
0
void ZCamera::Update(float fElapsed)
{
	if (!g_pGame)
	{
		assert(false);
		return;
	}

	if (isnan(m_fAngleX) || isnan(m_fAngleZ))
	{
		DMLog("Camera angle is NaN!\n");
		m_fAngleX = CAMERA_DEFAULT_ANGLEX;
		m_fAngleZ = CAMERA_DEFAULT_ANGLEZ;
	}

	ZCombatInterface*	pCombatInterface = ZGetGameInterface()->GetCombatInterface();
	ZCharacter*			pTargetCharacter = g_pGame->m_pMyCharacter;
	if (TargetCharacterOverride)
	{
		pTargetCharacter = TargetCharacterOverride;
	}

	v3 PlayerPosition{ pTargetCharacter->m_Position };
	v3 PlayerDirection{ pTargetCharacter->CameraDir };
	bool Observing = false;

	auto&& Observer = *pCombatInterface->GetObserver();
	
	if (TargetCharacterOverride)
	{
		Observing = true;
		pTargetCharacter->GetHistory(&PlayerPosition, nullptr,
			g_pGame->GetTime(), &PlayerDirection);
	}
	else if (pCombatInterface->GetObserver()->IsVisible())
	{
		auto&& ObserverTarget = Observer.GetTargetCharacter();
		if (ObserverTarget)
		{
			pTargetCharacter = ObserverTarget;
			Observing = pTargetCharacter != nullptr;
		}

		if (pTargetCharacter)
			pTargetCharacter->GetHistory(&PlayerPosition, nullptr,
				g_pGame->GetTime() - Observer.GetDelay(), &PlayerDirection);
	}

	if (!pTargetCharacter) return;

	m_Target = PlayerPosition + GetTargetOffset(PlayerDirection, pTargetCharacter->GetScale());

	v3 dir;
	if (Observing && GetLookMode() == ZCAMERA_DEFAULT)
	{
		// If we're spectating someone, set the direction to their direction.
		dir = PlayerDirection;

		m_fAngleX = acosf(dir.z);
		v3 HorizontalDir{ dir.x, dir.y, 0.f };
		m_fAngleZ = GetAngleOfVectors(rvector(1, 0, 0), HorizontalDir);
	}
	else
		dir = GetCurrentDir();

	v3 shockoffset{ 0, 0, 0 };
	if (m_bShocked)
	{
		float fA = RANDOMFLOAT * 2 * PI_FLOAT;
		float fB = RANDOMFLOAT * 2 * PI_FLOAT;
		auto velocity = v3(sin(fA)*sin(fB), cos(fA)*sin(fB), cos(fB));

		float fPower = (g_pGame->GetTime() - m_fShockStartTime) / m_fShockDuration;
		if (fPower > 1.f)
		{
			StopShock();
		}
		else
		{
			fPower = 1.f - fPower;

			const float FFMAX_POWER = 300.f;

			float ffPower = fPower * m_fShockPower / FFMAX_POWER;
			ffPower = std::min(ffPower, 1.0f);
			ZGetInput()->SetDeviceForcesXY(ffPower, ffPower);

			fPower = pow(fPower, 1.5f);
			auto ShockVelocity = RANDOMFLOAT * m_fShockPower * velocity;
			shockoffset = fPower * fElapsed * ShockVelocity;
		}
	}

	float fRealDist = m_fDist;
	rvector pos = m_CurrentTarget - dir*m_fDist;

	RBSPPICKINFO bpi;

	if (ZGetGame()->GetWorld()->GetBsp()->Pick(m_Target, -dir, &bpi)
		&& Magnitude(m_Target - bpi.PickPos) < Magnitude(m_Target - pos))
	{
		float fColDist = Magnitude(bpi.PickPos - pos);
		float fTargetDist = Magnitude(m_Target - pos);
		pos = bpi.PickPos + dir;

		fRealDist = Magnitude(m_Target - pos) - 10.f;
	}

	if (pTargetCharacter && pTargetCharacter->GetScale() != 1.0f)
		fRealDist *= pTargetCharacter->GetScale();

	m_CurrentTarget = m_Target;

	bool bCollisionWall = CheckCollisionWall(fRealDist, pos, dir);

	float fAddedZ = 0.0f;
	CalcMaxPayneCameraZ(fRealDist, fAddedZ, m_fAngleX);

	if (bCollisionWall)
	{
		m_fCurrentDist += CAMERA_WALL_TRACKSPEED*(fRealDist - m_fCurrentDist);
	}
	else
	{
		m_fCurrentDist += CAMERA_TRACKSPEED*(fRealDist - m_fCurrentDist);
	}

	if (GetLookMode() == ZCAMERA_DEFAULT || GetLookMode() == ZCAMERA_FREEANGLE) {

		m_Position = m_CurrentTarget - dir*m_fCurrentDist;
		m_Position.z += fAddedZ;

		// Lock the camera height if the player has fallen into the abyss
		if (m_Position.z <= DIE_CRITICAL_LINE)
		{
			rvector campos = pTargetCharacter->GetCenterPos() - pTargetCharacter->GetDirection() * 20.0f;
			m_Position.x = campos.x;
			m_Position.y = campos.y;
			m_Position.z = DIE_CRITICAL_LINE;

			if (GetLookMode() == ZCAMERA_DEFAULT)
			{
				rvector tar = pTargetCharacter->GetCenterPos();
				if (tar.z < (DIE_CRITICAL_LINE - 1000.0f)) tar.z = DIE_CRITICAL_LINE - 1000.0f;
				dir = tar - m_Position;
				Normalize(dir);
			}
		}
	}

	v3 up{ 0, 0, 1 };
	if (m_bShocked)
	{
		rvector CameraPos = m_Position + shockoffset;
		RSetCamera(CameraPos, CameraPos + dir, up);
	}
	else
	{
		RSetCamera(m_Position, m_Position + dir, up);
	}

	if (GetLookMode() == ZCAMERA_FREELOOK)
	{
		if (!_isnan(RCameraDirection.x) && !_isnan(RCameraDirection.y) && !_isnan(RCameraDirection.z))
		{
			ZGetGameInterface()->GetCombatInterface()->GetObserver()->SetFreeLookTarget(RCameraDirection);
		}
	}
}