/* * Position the notification relative to the block it is * talking about. */ void GameController::HandleNotificationUpdateCallback(void *handler, void *notification) { hdVec2 screenPos; hdVec2 aa,bb; /* Volatile - both the notification and handler may go away at any time */ if (handler == NULL || notification == NULL) return; GameController *self = (GameController *)handler; Polygon* note = (Polygon *)notification; Block* block = (Block *)note->GetRelative(); if (NULL == note->GetWorld()) return; if (block != NULL) { self->ConvertInterfaceToScreen(screenPos, block->GetWorldCenter().x, block->GetWorldCenter().y); aa.Set(screenPos.x - 35.0f, screenPos.y + 30.0f); bb.Set(aa.x + 70, aa.y + 35); note->RemoveAllPoints(); note->AddPoint(aa.x, aa.y); note->AddPoint(aa.x, bb.y); note->AddPoint(bb.x, bb.y); note->AddPoint(bb.x, aa.y); } }
void GameController::PlayerReadyMoveProjection(hdTimeInterval interval) { // While the projection is not at the starting position (0.0, upper.x = level.upper.x) // move a fraction of the difference between the aabb and the destination. float dx, dy; dx = dy = 0.0f; Block* keyBlock = NULL; // find block with tag of 1001 - camera focuses on this block when player is ready... for (int i = 0; i < GetCurrentLevel()->GetBlockCount(); i++) { if (GetCurrentLevel()->GetBlocks()[i]->GetTag() == 1001) { keyBlock = (Block*)GetCurrentLevel()->GetBlocks()[i]; SetSelectedTotemBlock(keyBlock); break; } } if (keyBlock == NULL) { /* * HACK HACK HACK * * Focus on the center if there is no key block. */ float worldCenterX = (m_worldAABB.upper.x + m_worldAABB.lower.x) / 2.0f; float projCenterX = m_projection->GetAABB().lower.x + ((m_projection->GetAABB().upper.x - m_projection->GetAABB().lower.x) / 2.0f); if (m_projection->GetAABB().upper.y <= m_worldAABB.upper.y) { // move clamped to diff between y dy = 0.2f; } if (projCenterX <= worldCenterX) { dx = hdMin(0.2f, (projCenterX - worldCenterX)); } else { dx = -0.2f; if ((projCenterX - worldCenterX) > dx) { dx = (projCenterX - worldCenterX); } } dx *= 10.0f; dy *= 100.0f; } else { hdVec3 box(0.05f * (m_projection->GetAABB().upper - m_projection->GetAABB().lower)); hdVec3 diff = (keyBlock->GetWorldCenter() - m_projection->GetWorldCenter()); hdVec3 mag(fabs(diff.x), fabs(diff.y), 0.0f); mag.x = (mag.x < box.x) ? 0.0f : mag.x - box.x; mag.y = (mag.y < box.y) ? 0.0f : mag.y - box.y; dx = (diff.x > 0.0f) ? -mag.x : mag.x; dy = (diff.y < 0.0f) ? -mag.y : mag.y; dx *= 5.0f; dy *= 5.0f; } PanProjection(0.0f, 0.0f, dx, dy); ZoomProjection(1.0f, 1.0f, 0.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f); }