Created
February 1, 2013 10:24
-
-
Save gashtio/4690520 to your computer and use it in GitHub Desktop.
Firing events to Coherent UI setting the player position on the map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CCoherentUISystem::UpdateHUD() | |
{ | |
static Vec3 lastPosition = Vec3Constants<Vec3::value_type>::fVec3_Zero; | |
static float lastRotation = 0; | |
CCoherentViewListener* pHUDListener = NULL; | |
pHUDListener = ( m_ViewListeners.size() > VL_HUD ? m_ViewListeners[VL_HUD].get() : NULL ); | |
if ( pHUDListener ) | |
{ | |
CCamera& camera = gEnv->pSystem->GetViewCamera(); | |
Vec3 viewDir = camera.GetViewdir(); | |
float rotation = cry_atan2f( viewDir.y, viewDir.x ) * 180.0f / 3.14159f; | |
// Adjust rotation so it is the same as in the game | |
rotation = -rotation - 135.0f; | |
Coherent::UI::View* pView = pHUDListener->GetView(); | |
if ( pView && pHUDListener->IsReadyForBindings() ) | |
{ | |
if (rotation != lastRotation) | |
{ | |
pView->TriggerEvent( "SetAbsoluteCompassRotation", rotation ); | |
// Adjust the rotation for the map, too... | |
pView->TriggerEvent( "SetPlayerRotationOnMap", rotation - 45.0f ); | |
lastRotation = rotation; | |
} | |
Vec3 cameraPosition = camera.GetPosition(); | |
if ((cameraPosition - lastPosition).GetLengthSquared() > VEC_EPSILON) | |
{ | |
pView->TriggerEvent( "SetPlayerPositionOnMap", cameraPosition.x, cameraPosition.y ); | |
lastPosition = cameraPosition; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment