void ViewEngineering::onRender( RenderContext & context, const RectInt & window ) { GameDocument * pDoc = (GameDocument *)document(); if ( pDoc == NULL ) return; UniverseContext * pContext = pDoc->context(); ASSERT( pContext ); NounShip * pShip = pDoc->ship(); ASSERT( pShip ); // get the time elapsed float t = context.elapsed(); // calculate the distance from the ship based upon it's radius float cameraDistance = pShip->radius() * 2.5f; // calculate the camera frame and position Matrix33 cameraFrame( pShip->frame() ); cameraFrame.rotate( PI / 4, ViewGame::s_CameraTime * (PI / 4), 0 ); Vector3 cameraPosition( pShip->worldPosition() - (cameraFrame.k * cameraDistance) ); if ( ViewGame::s_CameraTime < CAMERA_SNAP_TIME ) { // if ship is moving, keep it from jumping around while the camera is animating if ( m_Adjust ) { Vector3 position( pShip->worldPosition() ); Vector3 adjust( position - m_AdjustPosition ); m_AdjustPosition = position; ViewGame::s_CameraPosition += adjust; } else { m_AdjustPosition = pShip->worldPosition(); m_Adjust = true; } float d = ViewGame::s_CameraTime / CAMERA_SNAP_TIME; // move the camera Vector3 deltaPosition( cameraPosition - ViewGame::s_CameraPosition ); ViewGame::s_CameraPosition += deltaPosition * d; // update the camera frame ViewGame::s_CameraFrame.i += (cameraFrame.i - ViewGame::s_CameraFrame.i) * d; ViewGame::s_CameraFrame.j += (cameraFrame.j - ViewGame::s_CameraFrame.j) * d; ViewGame::s_CameraFrame.k += (cameraFrame.k - ViewGame::s_CameraFrame.k) * d; ViewGame::s_CameraFrame.orthoNormalizeXY(); } else { // animation is over, snap directly to the desired frame/position ViewGame::s_CameraFrame = cameraFrame; ViewGame::s_CameraPosition = cameraPosition; m_Adjust = false; } m_UpdateStatus += t; if ( m_UpdateStatus > 1.0f ) { m_UpdateStatus = 0.0f; // update the ship status String shipStatus; shipStatus += String().format("Hull:<X;75;Color;ff00ffff>%d%%</Color>\n", int(pShip->damageRatioInv() * 100) ); shipStatus += String().format("Energy:<X;75;Color;ff00ffff>%d / %d</Color>\n", pShip->energy(), pShip->maxEnergy() ); shipStatus += String().format("Velocity:<X;75;Color;ff00ffff>%.1f / %.1f</Color>\n", pShip->velocity(), pShip->maxVelocity() ); shipStatus += String().format("Signature:<X;75;Color;ff00ffff>%.1f</Color>\n", pShip->signature() ); shipStatus += "\nSYSTEMS:\n"; // display armor status for(int i=0;i<pShip->childCount();i++) if ( WidgetCast<GadgetArmor>( pShip->child(i) ) ) { GadgetArmor * pArmor = (GadgetArmor *)pShip->child(i); shipStatus += String().format("%s<X;100>%d%%\n", pArmor->nounContext()->name(), (pArmor->armor() * 100 ) / pArmor->strength() ); } // display shield status for(i=0;i<pShip->childCount();i++) if ( WidgetCast<GadgetShield>( pShip->child(i) ) ) { GadgetShield * pShield = (GadgetShield *)pShip->child(i); shipStatus += String().format("%s<X;100>%d%%\n", pShield->nounContext()->name(), (pShield->charge() * 100 ) / pShield->maxCharge() ); } for(i=0;i<pShip->childCount();i++) if ( WidgetCast<NounGadget>( pShip->child(i) ) ) { NounGadget * pGadget = (NounGadget *)pShip->child(i); if ( WidgetCast<GadgetArmor>( pGadget ) ) continue; if ( WidgetCast<GadgetShield>( pGadget ) ) continue; shipStatus += String().format("%s<X;100>%d%%\n", pGadget->nounContext()->name(), int( pGadget->damageRatioInv() * 100 ) ); } m_pShipStatus->setText( shipStatus ); } if ( m_pLayoutRepair->visible() ) { for(int i=0;i<pShip->repairCount();i++) GetButton<ButtonGadget>( m_pRepairQueue, i )->setGadget( pShip->repair( i ) ); // remove excess buttons m_pRepairQueue->cullChildren( pShip->repairCount() ); } //---------------------------------------------------------------------------- // update the active zone pContext->setActiveZone( ViewGame::s_CameraPosition ); // create our render context RenderContext engineeringContext( context ); engineeringContext.setPosition( ViewGame::s_CameraPosition ); engineeringContext.setFrame( ViewGame::s_CameraFrame ); engineeringContext.setTime( pContext->tick() * TICK_DURATION_S ); //---------------------------------------------------------------------------- // render the universe pContext->render( engineeringContext, ~ViewGame::s_CameraFrame, ViewGame::s_CameraFrame * (-ViewGame::s_CameraPosition) ); }