void EnviroCanvas::OnAfterUpdate() { #ifndef __WXMAC__ if (m_bFirstPaint) VTLOG1("EnviroCanvas: update status bar\n"); #endif EnviroFrame *frame = (EnviroFrame*) GetParent(); // update the status bar every 1/10 of a second static float last_stat = 0.0f; static vtString last_msg; vtString current_msg = g_App.GetMessage1() + g_App.GetMessage2(); float cur = vtGetTime(); if (cur - last_stat > 0.1f || current_msg != last_msg) { last_msg = current_msg; last_stat = cur; frame->UpdateStatus(); } frame->UpdateLODInfo(); g_App.UpdateCompass(); }
void vtJoystickEngine::Eval() { if (!m_pStick) return; float fTime = vtGetTime(), fElapsed = fTime - m_fLastTime; vtTransform *pTarget = (vtTransform*) GetTarget(); if (pTarget) { wxPoint p = m_pStick->GetPosition(); int buttons = m_pStick->GetButtonState(); float dx = ((float)p.x / 32768) - 1.0f; float dy = ((float)p.y / 32768) - 1.0f; // use a small dead zone to avoid drift const float dead_zone = 0.04f; if (buttons & wxJOY_BUTTON2) { // move up down left right if (fabs(dx) > dead_zone) pTarget->TranslateLocal(FPoint3(dx * m_fSpeed * fElapsed, 0.0f, 0.0f)); if (fabs(dy) > dead_zone) pTarget->Translate(FPoint3(0.0f, dy * m_fSpeed * fElapsed, 0.0f)); } else if (buttons & wxJOY_BUTTON3) { // pitch up down, yaw left right if (fabs(dx) > dead_zone) pTarget->RotateParent(FPoint3(0,1,0), -dx * fElapsed); if (fabs(dy) > dead_zone) pTarget->RotateLocal(FPoint3(1,0,0), dy * fElapsed); } else { // move forward-backward, turn left-right if (fabs(dy) > dead_zone) pTarget->TranslateLocal(FPoint3(0.0f, 0.0f, dy * m_fSpeed * fElapsed)); if (fabs(dx) > dead_zone) pTarget->RotateParent(FPoint3(0,1,0), -dx * fElapsed); } } m_fLastTime = fTime; }
void vtTimeEngine::Eval() { float time = vtGetTime(); if (m_last_time == -1.0f) m_last_time = time; if (m_fSpeed != 0.0f) { float elapsed = (time - m_last_time); m_fSeconds += (elapsed * m_fSpeed); if (m_fSeconds > 1.0f) { int full = (int) m_fSeconds; m_time.Increment(full); _InformTarget(); m_fSeconds -= full; } } m_last_time = time; }
//changes the light colors at a node. void vtIntersectionEngine::Eval() { float t = vtGetTime(); if (!m_bFirstTime) { if (t > m_fNextChange) { m_iCurState++; m_iCurState = m_iCurState % m_iTotalStates; //assign new light states. for (int i = 0; i < m_pNode->m_iLinks; i++) { LightStatus l = m_Lights[i+m_pNode->m_iLinks*m_iCurState]; m_pNode->SetLightStatus(i, l); } if (m_iCurState & 0x1) { //if curret state is odd: //there is a yellow light. use shorter time m_fNextChange = t + LT_SWITCH_TIME2; } else { //lights are green and red. using longer time m_fNextChange = t + LT_SWITCH_TIME; } } } else { m_bFirstTime = false; //generate current status randomly. m_iCurState = (rand() % m_iTotalStates); //generate offset time randomly. int offset; if (m_iCurState & 0x1) { offset = rand() % LT_SWITCH_TIME2; } else { offset = rand() % LT_SWITCH_TIME; } //assign new light states. for (int i = 0; i < m_pNode->m_iLinks; i++) { m_pNode->SetLightStatus(i, m_Lights[i+m_pNode->m_iLinks*m_iCurState]); } m_fNextChange = t + offset; } }