Skip to content

Instantly share code, notes, and snippets.

@gashtio
Created February 1, 2013 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gashtio/4690520 to your computer and use it in GitHub Desktop.
Save gashtio/4690520 to your computer and use it in GitHub Desktop.
Firing events to Coherent UI setting the player position on the map
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