// // Updates the time displayed on the 7-segment display. Will turn on one digit, and // turn off all others. The time is input in 24-hour mode, and then parsed before being // displayed. // void UpdateTime(int digit, int hours, int minutes) { ParseTime(hours, minutes); if( digit == 1 && digitNumber[0] == 0 ) return; if( digit == 5 ) DisplayTime(digit, 10); else DisplayTime(digit, digitNumber[digit - 1]); }
/* init Dlg */ void ExcDlgWelcome::InitDlg(void) { int i = 0; //unsigned char str[1] = { 'L' }; unsigned char buff[32] = {0}; ClearAll(); //logo //SetMemAera(144, 0, LOONGSON_LOGO16X16_8BIT, DISPLAY, false); SetMemAera(10, 40, LOONGSON_LOGO32X32_8BIT, DISPLAY, false); SetMemAera(16, 0, GPS_16X32_8BIT, DISPLAY, false); SetRectangle(0, 18, 160, 2, false); SetRectangle(0, 142, 160, 2, false); SetRectangle(138, 147, 16, 8, false); SetRectangle(136, 149, 2, 4, false); //DISPLAY_8x16_SR(64, 2, false); #if 0 // title m_AmrDisplay.ZKDisplayConvert((char *)"L" , ASCII12, buff); SetZIFUAera(50, 10, ASCII12, buff, DISPLAY, false); #else DISPLAY_16x16_BEIJINGSHENZHOULONGXIN(50, 40, false); DISPLAY_8x16_000000000210(0, 144, false); DISPLAY_16x16_DIANLIZHUANBIANXITONG(25, 76, false); DisplayTime(120, 2); #endif return; }
/* init Dlg */ void ExcDlgPowerTotal::InitDlg(void) { int i = 0; //unsigned char str[1] = { 'L' }; unsigned char buff[32] = {0}; ClearAll(); SetMemAera(16, 0, GPS_16X32_8BIT, DISPLAY, false); SetRectangle(0, 18, 160, 2, false); SetRectangle(0, 142, 160, 2, false); SetRectangle(138, 147, 16, 8, false); SetRectangle(136, 149, 2, 4, false); //DISPLAY_8x16_SR(64, 2, false); DISPLAY_16x16_DIANNENGLIANG(55, 25, false); DISPLAY_ZHENGXIANGYOUGONG(0, 45, false); DISPLAY_ZHENGXIANGWUGONG(0, 63, false); DISPLAY_FANXIANGYOUGONG(0, 81, false); DISPLAY_FANXIANGWUGONG(0, 99, false); DISPLAY_8x16_KWH(120, 45, false); DISPLAY_8x16_KVARH(120, 63, false); DISPLAY_8x16_KWH(120, 81, false); DISPLAY_8x16_KVARH(120, 99, false); DISPLAY_8x16_000000000210(0, 144, false); DisplayTime(120, 2); return; }
void TimeDisplay::StartT() { mTime = 0; mT0.start(); DisplayTime(); mPaused = false; mStopped = false; }
void TimeDisplay::PauseT() { if (!mStopped && !mPaused) { mTime += mT0.restart(); DisplayTime(); mPaused = true; } }
status_t AmTimeView::ConstructSignatureFromTime(const AmPhrase& signatures) { debugger("This code doesn't work at all -- if anyone actually uses it, it needs to be rewritten"); AmNode* node = signatures.FindNode( DisplayTime(), BACKWARDS_SEARCH ); if( !node ) return B_ERROR; AmSignature* sig = dynamic_cast<AmSignature*>( node->Event() ); if( !sig ) return B_ERROR; AmTime start = sig->StartTime(); AmTime ticks = sig->TicksPerBeat(); AmTime displayTime = DisplayTime(); int32 measure = sig->Measure(); while ( (start + ticks) <= displayTime ) { start += ticks; measure++; } mSignature->Set( start, measure, sig->Beats(), sig->BeatValue() ); return B_OK; }
extern void HandleTimeGattCharValInd(GATT_CHAR_VAL_IND_T *ind) { /* if the received handle is of the current time then the value received * could be sent to the UART application. */ if(ind->handle == g_time_serv_data.cur_time_handle) { DisplayTime(ind->value, ind->size_value); } }
status_t AmTimeView::ConstructSignatureFromTime() { if (!mSignature) return B_NO_MEMORY; status_t err = B_ERROR; if ( SongRef().IsValid() ) { // READ TRACK BLOCK #ifdef AM_TRACE_LOCKS printf("AmTimeView::ConstructSignatureFromTime() read lock\n"); #endif const AmSong* song = ReadLock(); const AmTrack* track = song ? song->Track(mTrackRef) : NULL; if (track) err = track->GetSignature(DisplayTime(), *mSignature); else if (song) err = song->GetSignature(DisplayTime(), *mSignature); ReadUnlock(song); // END READ TRACK BLOCK } else { err = ConstructSignatureFromTime( mSignatures ); } return err; }
void TimeDisplay::StopT() { if (!mStopped && !mPaused) { mTime += mT0.restart(); DisplayTime(); mStopped = true; mPaused = false; mTime = 0; } }
void ExcDlgWelcome::InitOperation(void) { if (SIGNAL4_16x16_8bit == m_AmrDisplay.SignalValue) SetMemAera(0, 0, SIGNAL4_16x16_8bit, DISPLAY, false); else SetMemAera(0, 0, SIGNAL3_16x16_8bit, DISPLAY, false); LightCount = 0; DisplayTime(120, 2); m_AmrDisplay.CurDlg->ShowDlg(); }
/* * UpdateParkTime * Description: write in entered parking time * * Arguments: curr_state - the current system state * Return: nextstate - the next system state * * Input: None * Output: None * * Operation: Only run if there is a changed number digit. * Display current entered sequence in hh:mm format * Update Exit/Undo button and clear flag indicating a changed * digit. * * Error Handling: None * * Algorithms: None * Data Strutures: None * * Shared Variables: None * * Revision History: * Apr. 27, 2013 Nnoduka Eruchalu Initial Revision */ state UpdateParkTime(state curr_state) { if (updated_number) { /* only do update if time number has changed */ UpdateExitOrUndo(); /* update it (in mins) */ DisplayTime(1,11,ConvertTimeToMin(number, num_digits), DISPLAYTIME_MINS); /* place cursor after last written character and skip colon */ LcdCursor(1,11+((num_digits <= 2) ? num_digits : (num_digits+1))); updated_number = FALSE; } return curr_state; /* current state doesn't change */ }
void ExcDlgPowerTotal::DoTimer(void) { m_AmrDisplay.IdleCounter = 0; /* if (y_random != 0) { SetMemAera(x_random, y_random, ROUND_LOGO16X16_8BIT, CLEAR); } x_random = random()%144; y_random = random()%70 + 45; SetMemAera(x_random, y_random, ROUND_LOGO16X16_8BIT, DISPLAY); */ if (0 == m_AmrDisplay.AmrTick%50) { if (SIGNAL4_16x16_8bit == m_AmrDisplay.SignalValue) { SetMemAera(0, 0, SIGNAL3_16x16_8bit, DISPLAY, false); m_AmrDisplay.SignalValue = SIGNAL3_16x16_8bit; } else { SetMemAera(0, 0, SIGNAL4_16x16_8bit, DISPLAY, false); m_AmrDisplay.SignalValue = SIGNAL4_16x16_8bit; } } if (LightCount >= 200) { ioctl(dev_fd, AMRDISPLAY_BACKCLEAR, NULL); } else LightCount++; if (0 == m_AmrDisplay.AmrTick%10) DispExcDate(); DisplayTime(120, 2); m_AmrDisplay.AmrTick++; m_AmrDisplay.CurDlg->ShowDlg(); }
/* * UpdatePark * Description: write in parking space and time left * * Arguments: curr_state - the current system state * Return: nextstate - the next system state * * Input: None * Output: None * * Operation: if there is an updated parking space, show it on the * parking page. * Then reset the updated_space flag to FALSE, since * the update has been handled. * display new parking time if time has elapsed * * Error Handling: None * * Algorithms: None * Data Strutures: None * * Shared Variables: None * * Revision History: * Apr. 26, 2013 Nnoduka Eruchalu Initial Revision */ state UpdatePark(state curr_state) { int32_t old_parking_time = parking_time; if (updated_space) { LcdCursor(0,12); LcdWriteInt(parking_space); /* write space number */ updated_space = FALSE; } /* always update the displayed time */ parking_time -= ElapsedTime(); /* get elapsed seconds */ if (parking_time < 0) /* but keep time */ parking_time = 0; /* non-negative */ /* if time has changed, update it in seconds */ if (parking_time/TIME_SCALE != old_parking_time/TIME_SCALE) DisplayTime(1,12,parking_time/TIME_SCALE, DISPLAYTIME_SECS); /* update it (in secs) */ return curr_state; }
void StatFormBase::LoadGeneralInfo() { //----------------------------加载菜单的通用信息-------------------------------- //加载总标题 attron(A_BOLD); char stitle[64] = {0}; sprintf(stitle,"%s状态监控",SYSNAME); mvaddstr(1,(COLS_LENS - strlen((char *)stitle))/2,(char *)stitle); attroff(A_BOLD); char sInterval[50] = {0}; sprintf(sInterval,"刷新间隔: %d",m_iInterval); mvaddstr(2,0,sInterval); /*加载时间*/ DisplayTime(); /*加载菜单界限*/ mvhline(3,0,'=',COLS_LENS); mvhline(5,0,'-',COLS_LENS); mvhline(5 + LINE_SIZE + 1,0,'=',COLS_LENS); }
status_t AmTimeView::InitializeDisplay() { if( ConstructSignatureFromTime() != B_OK ) return B_ERROR; // Set the measure value if( mMeasureCtrl ) mMeasureCtrl->SetValue( mSignature->Measure() ); // Calculate and set the beat value AmTime time = DisplayTime() - mSignature->StartTime(); AmTime start = 0; AmTime pulses = PPQN; int32 beat = 1; while ( (start + pulses) <= time) { start += pulses; beat++; } // Also need to set the range of values for the beat control here. if( mBeatCtrl ) { mBeatCtrl->SetLimits(1, mSignature->Beats() ); mBeatCtrl->SetValue( beat ); } // Calculate and set the clock value if( mClockCtrl ) mClockCtrl->SetValue( time - start ); return B_OK; }
void SHMInfoShow::Rebuild() { //此变量用于自上而下绘制菜单 int lv_iTotalRow = 0; int lv_iCurrentRow = 0; static char Buffer[COLS_LENS]; LoadEmptyMenu(); DisplayTime(); int iTaskNum = 0; int i = 0; //char sSHMInfoShow[10240]={0}; char sBuff[1000][128]; memset(Buffer,0,COLS_LENS); sprintf(Buffer,"当前用户下的共享内存信息 :共享ID:共享内存KEY:当前状态:连接共享内存进程数:大小:创建进程标识:最后连接进程标识:最后连接时间:最后撤离时间:创建时间"); mvaddstr(4,0,Buffer); char sCommand[256] = {0}; char sParam[16] = {0}; FILE *fp = 0; int ret = 0; string sTemp; string sTCommnd; sTemp+="\""; sTemp+=":"; sTemp+="\""; char * p; p=getenv ("LOGNAME"); sTCommnd+="ipcs -a|grep m|grep "; sTCommnd+=p; sTCommnd+="| awk '{print $2"; sTCommnd+=sTemp; sTCommnd+="$3"; sTCommnd+=sTemp; sTCommnd+="$4"; sTCommnd+=sTemp; sTCommnd+="$9"; sTCommnd+=sTemp; sTCommnd+="$10"; sTCommnd+=sTemp; sTCommnd+="$11"; sTCommnd+=sTemp; sTCommnd+="$12"; sTCommnd+=sTemp; sTCommnd+="$13"; sTCommnd+=sTemp; sTCommnd+="$14"; sTCommnd+=sTemp; sTCommnd+="$15"; sTCommnd+="}'"; sprintf (sCommand, sTCommnd.c_str()); fp = popen (sCommand, "r"); if (fp == NULL) { mvaddstr(8,(COLS_LENS - strlen((char *)"调用系统命令失败"))/2,(char *)"调用系统命令失败"); return ; } //--------------------------------------------------------- //sprintf(sBuff[0],"%s","登录用户:登录方式:IP:日期:开始时间:结束时间:持续时间"); int n = 0; while(!feof(fp)) { if( !fgets(sBuff[n],128,fp) ) break; n++; lv_iTotalRow ++; } fclose(fp); if(lv_iTotalRow==0){ mvaddstr(8,(COLS_LENS - strlen((char *)"无符合条件的选项"))/2,(char *)"无符合条件的选项"); return; } lv_iCurrentRow =1; //以下四个判断主要用于纠正一些非法的 //如果全局选中行数<=0,则回指到 行 if (m_iSelectedRow <= 0) { m_iSelectedRow = lv_iTotalRow ; } //如果全局选中行数> lv_iTotalRow ,则回指到第一行 if (m_iSelectedRow > lv_iTotalRow) { m_iSelectedRow = 1; } //如果g_iStartRow <= 0,人为置为第一行 if (m_iStartRow <= 0) { m_iStartRow = 1; } if (m_iStartRow > m_iSelectedRow ) { m_iStartRow = m_iSelectedRow ; } if (m_iSelectedRow - m_iStartRow >= LINE_SIZE) { m_iStartRow = m_iSelectedRow - LINE_SIZE + 1; } // --确定lv_iCurrentRow初始值 while(1) { if (lv_iCurrentRow >= m_iStartRow ) { break; } else { lv_iCurrentRow++; } } i = lv_iCurrentRow -1; for(; i<n ; i++) { if ((lv_iCurrentRow > lv_iTotalRow)||(lv_iCurrentRow >= m_iStartRow + LINE_SIZE)) { break; } if (lv_iCurrentRow == m_iSelectedRow) { standout(); } //输出序号 memset(Buffer,0,COLS_LENS); sprintf(Buffer,"%-10d",lv_iCurrentRow); mvaddstr(lv_iCurrentRow - m_iStartRow + 6,0,Buffer); memset(Buffer,0,COLS_LENS); sprintf(Buffer,"%s",sBuff[i]); mvaddstr(lv_iCurrentRow - m_iStartRow + 6,10,Buffer); if (lv_iCurrentRow == m_iSelectedRow) { standend(); } lv_iCurrentRow ++; } //未满的行填入空白 while (lv_iCurrentRow < m_iStartRow + LINE_SIZE) { mvhline(lv_iCurrentRow - m_iStartRow + 6,0,' ',COLS_LENS); lv_iCurrentRow ++; } wmove(stdscr,m_iSelectedRow - m_iStartRow + 6,0);//将指针移到选定行首 refresh(); }
void GPIOEIntHandler(void) { // Clear the GPIO interrupt GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3); // Disable Interrupts GPIOPinIntDisable(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3); GPIOPinIntDisable(GPIO_PORTF_BASE, GPIO_PIN_0); // If the clock has been set before, we need to disable SysTickInt if (start==1){ SysTickIntDisable(); } // Clear the OLED RIT128x96x4Clear(); // If the left button got us here, display that we are in set clock mode // If the right button got us here, display that we are in set alarm mode if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0){ RIT128x96x4StringDraw("Set Clock", 40, 0, 15); DisplayTime(); } else if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){ RIT128x96x4StringDraw("Set Alarm", 40, 0, 15); DisplayTimeA(); } // If the left button is held down enable the time to be set while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0){ // While the up button is being pressed, the clock will increment if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0){ // In order to slow the incrementing we count to 10000 first x++; if (x>9999){ // Show the increment DisplayIncrementedTime(); x = 0; } } // While the down button is being pressed, the clock will decrement if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){ // In order to slow the decrementing we count to 10000 first x++; if (x>9999){ // Show the decrement DisplayDecrementedTime(); x = 0; } } } // If the right button is held down enable the alarm to be set while (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){ // While the up button is being pressed, the clock will increment if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0){ // In order to slow the decrementing we count to 10000 first x++; if (x>9999){ // Show the increment DisplayIncrementedAlarm(); x = 0; } } // While the down button is being pressed, the clock will decrement if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){ // In order to slow the decrementing we count to 10000 first x++; if (x>9999){ // Show the decrement DisplayDecrementedAlarm(); x = 0; } } alarmSet = 1; } RIT128x96x4Clear(); // Enable the interrupts GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_0); // If the start variable is not set, we set it and start SysTick if (!start){ start++; t = 0; SysTickIntEnable(); SysTickEnable(); } else { SysTickIntEnable(); } }
//***************************************************************************** // // Main Program // //***************************************************************************** int main(void) { unsigned long ulPeriod; // Set the clocking to run directly from the crystal. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // Initialize the OLED display and write status. RIT128x96x4Init(1000000); // Enable the peripherals used by this application SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); // Set GPIO F0 and G1 as PWM pins. They are used to output the PWM0 and // PWM1 signals. GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1); // Compute the PWM period based on the system clock. ulPeriod = SysCtlClockGet() / 440; // Set the PWM period to 440 (A) Hz. PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod); // Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%. PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod * 3 / 4); // Enable the PWM0 and PWM1 output signals. PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true); // Configure the 'up' button as input and enable the pin to interrupt on // the falling edge (i.e. when the push button is pressed). GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Configure the 'down' button as input and enable the pin to interrupt on // the falling edge (i.e. when the push button is pressed). GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Configure the 'left' button as input and enable the pin to interrupt on // the falling edge (i.e. when the push button is pressed). GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_2); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Configure the 'right' button as input and enable the pin to interrupt on // the falling edge (i.e. when the push button is pressed). GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_3); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3, GPIO_FALLING_EDGE); GPIOPortIntRegister(GPIO_PORTE_BASE, GPIOEIntHandler); GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_2 | GPIO_PIN_3); IntEnable(INT_GPIOE); // Configure the LED GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Configure the select buttons as input and enable the pin to interrupt on // the falling edge (i.e. when the push button is pressed). GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPortIntRegister(GPIO_PORTF_BASE, GPIOFIntHandler); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1); IntEnable(INT_GPIOF); // Initial time to display static char pcInitTime[10]; usprintf(pcInitTime, "%d%d:%d%d AM", h2, h1, m2, m1); // Set the time between SysTick interrupts and register the interrupt handle SysTickPeriodSet(SysCtlClockGet()); SysTickIntRegister(SysTickIntHandler); // Begin a blinking display of the initial start message while (!start){ int a; for (a=0; a<300000; a++){ if (a%20000==0){ RIT128x96x4StringDraw(pcInitTime, 40, 40, a/20000); } } } // The clock has started so we can clear the message RIT128x96x4Clear(); // Loop forever while(1) { // Display the updated time DisplayTime(); // Check if we should sound the alarm TisA(); } }
extern void HandleTimeGattReadCharValCFM(GATT_READ_CHAR_VAL_CFM_T *cfm) { if(cfm->result != sys_status_success) { /* If we have received an error with error code. */ g_time_serv_data.conf_handle_ptr = NULL; return; } /* If this signal is for Time characteristic read, It will * get handled in handleTimeGattReadCharValCFM */ if(g_time_serv_data.conf_handle_ptr == &g_time_serv_data.cur_time_handle) { /* This read characteristic value confirmation is for current time read. * contains the year (u16), month(u8), day(u8), hour(u8), minutes(u8), * seconds(u8), day of week (u8), Fractions256 (u8), adjust reason (u8) */ g_time_serv_data.conf_handle_ptr = NULL; DisplayTime(cfm->value, cfm->size_value); } else if(g_time_serv_data.conf_handle_ptr == &g_time_serv_data.local_time_info_handle) { /* This read characteristic value confirmation is for current time * zone read. */ g_time_serv_data.conf_handle_ptr = NULL; DisplayTimeZone(cfm->value, cfm->size_value); } else if(g_time_serv_data.conf_handle_ptr == &g_time_serv_data.ref_time_info_handle) { /* This read characteristic value confirmation is for the reference * time source information. */ g_time_serv_data.conf_handle_ptr = NULL; DisplayRefSource(cfm->value, cfm->size_value); } else if(g_time_serv_data.conf_handle_ptr == &g_time_serv_data.time_with_dst_handle) { /* This read characteristic value confirmation is for the next * dst time information. */ g_time_serv_data.conf_handle_ptr = NULL; DisplayNextDST(cfm->value, cfm->size_value); } else if(g_time_serv_data.conf_handle_ptr == &g_time_serv_data.time_update_state_handle) { /* This read characteristic value confirmation is for the status * of the update reference time source. */ g_time_serv_data.conf_handle_ptr = NULL; DisplayUpdate(cfm->value, cfm->size_value); } }
// // 函数: WndProc(HWND, UINT, WPARAM, LPARAM) // // 目的: 处理主窗口的消息。 // // WM_COMMAND - 处理应用程序菜单 // WM_PAINT - 绘制主窗口 // WM_DESTROY - 发送退出消息并返回 // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static BOOL f24Hour, fSuppress ; static HBRUSH hBrushRed ; static int cxClient, cyClient ; TCHAR szBuffer [2] ; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 分析菜单选择: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: hBrushRed = CreateSolidBrush (RGB (255, 0, 0)) ; SetTimer (hWnd, ID_TIMER, 1000, NULL) ;// fall through case WM_SETTINGCHANGE: GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME, szBuffer, 2) ; f24Hour = (szBuffer[0] == '1') ; GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITLZERO, szBuffer, 2) ; fSuppress = (szBuffer[0] == '0') ; InvalidateRect (hWnd, NULL, TRUE) ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_TIMER: InvalidateRect (hWnd, NULL, TRUE) ; return 0 ; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... SetMapMode (hdc, MM_ISOTROPIC) ; SetWindowExtEx (hdc, 276, 72, NULL) ; SetViewportExtEx (hdc, cxClient, cyClient, NULL) ; SetWindowOrgEx (hdc, 138, 36, NULL) ; SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ; SelectObject (hdc, GetStockObject (NULL_PEN)) ; SelectObject (hdc, hBrushRed) ; DisplayTime (hdc, f24Hour, fSuppress) ; EndPaint(hWnd, &ps); break; case WM_DESTROY: KillTimer (hWnd, ID_TIMER) ; DeleteObject (hBrushRed) ; PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
/* ******************************************************************************* * * * Interrupt() is used to read in a move when the operator types something * * while a search is in progress (during pondering as one example.) This * * routine reads in a command (move) and then makes two attempts to use this * * input: (1) call Option() to see if the command can be executed; (2) try * * InputMove() to see if this input is a legal move; If so, and we are * * pondering see if it matches the move we are pondering. * * * ******************************************************************************* */ void Interrupt(int ply) { int temp, i, left = 0, readstat, result, time_used; int save_move_number; TREE *const tree = block[0]; /* ************************************************************ * * * If trying to find a move to ponder, and the operator * * types a command, exit a.s.a.p. * * * ************************************************************ */ if (puzzling) abort_search = 1; /* ************************************************************ * * * First check to see if this is a command by calling * * Option(). Option() will return a 0 if it didn't * * recognize the command; otherwise it returns a 1 if * * the command was executed, or a 2 if we need to abort * * the search to execute the command. * * * ************************************************************ */ else do { readstat = Read(0, buffer); if (readstat <= 0) break; nargs = ReadParse(buffer, args, " ;"); if (nargs == 0) { Print(128, "ok.\n"); break; } if (strcmp(args[0], ".")) { save_move_number = move_number; if (!wtm) move_number--; if (root_wtm) Print(128, "Black(%d): %s\n", move_number, buffer); else Print(128, "White(%d): %s\n", move_number, buffer); move_number = save_move_number; } /* ************************************************************ * * * "." command displays status of current search. * * * ************************************************************ */ if (!strcmp(args[0], ".")) { if (xboard) { end_time = ReadClock(); time_used = (end_time - start_time); printf("stat01: %d ", time_used); printf(BMF " ", tree->nodes_searched); printf("%d ", iteration_depth); for (i = 0; i < n_root_moves; i++) if (!(root_moves[i].status & 128)) left++; printf("%d %d\n", left, n_root_moves); fflush(stdout); break; } else { end_time = ReadClock(); time_used = (end_time - start_time); printf("time:%s ", DisplayTime(time_used)); printf("nodes:" BMF "\n", tree->nodes_searched); DisplayTreeState(block[0], 1, 0, ply); } } /* ************************************************************ * * * "mn" command is used to set the move number to a * * specific value... * * * ************************************************************ */ else if (!strcmp("mn", args[0])) { if (nargs == 2) { move_number = atoi(args[1]); Print(128, "move number set to %d\n", move_number); } } /* ************************************************************ * * * "?" command says "move now!" * * * ************************************************************ */ else if (!strcmp(args[0], "?")) { if (thinking) { time_abort = 1; abort_search = 1; } } /* ************************************************************ * * * Next see if Option() recognizes this as a command. * * * ************************************************************ */ else { save_move_number = move_number; if (!analyze_mode && !wtm) move_number--; result = Option(tree); move_number = save_move_number; if (result >= 2) { if (thinking && result != 3) Print(128, "command not legal now.\n"); else { abort_search = 1; input_status = 2; break; } } else if ((result != 1) && analyze_mode) { abort_search = 1; input_status = 2; break; } /* ************************************************************ * * * Now, check to see if the operator typed a move. If * * so, and it matched the predicted move, switch from * * pondering to thinking to start the timer. If this * * is a move, but not the predicted move, abort the * * search, and start over with the right move. * * * ************************************************************ */ else if (!result) { if (pondering) { nargs = ReadParse(buffer, args, " ;"); temp = InputMove(tree, args[0], 0, Flip(root_wtm), 1, 1); if (temp) { if ((From(temp) == From(ponder_move)) && (To(temp) == To(ponder_move)) && (Piece(temp) == Piece(ponder_move)) && (Captured(temp) == Captured(ponder_move)) && (Promote(temp) == Promote(ponder_move))) { predicted++; input_status = 1; pondering = 0; thinking = 1; opponent_end_time = ReadClock(); program_start_time = ReadClock(); Print(128, "predicted move made.\n"); } else { input_status = 2; abort_search = 1; break; } } else if (!strcmp(args[0], "go") || !strcmp(args[0], "move") || !strcmp(args[0], "SP")) { abort_search = 1; break; } else Print(4095, "Illegal move: %s\n", args[0]); } else Print(4095, "unrecognized/illegal command: %s\n", args[0]); } } } while (1); if (log_file) fflush(log_file); }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam) { static BOOL f24Hour, fSuppress ; static HBRUSH hBrushRed ; static int cxClient, cyClient ; HDC hdc ; PAINTSTRUCT ps ; TCHAR szBuffer [2] ; switch (message) { case WM_CREATE: hBrushRed = CreateSolidBrush (RGB (255, 0, 0)) ; SetTimer (hwnd, ID_TIMER, 1000, NULL) ;// fall through case WM_SETTINGCHANGE: GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME, szBuffer, 2) ; f24Hour = (szBuffer[0] == '1') ; GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITLZERO, szBuffer, 2) ; fSuppress = (szBuffer[0] == '0') ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_SIZE: cxClient = LOWORD (lParam) ; cyClient = HIWORD (lParam) ; return 0 ; case WM_TIMER: InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SetMapMode (hdc, MM_ISOTROPIC) ; SetWindowExtEx (hdc, 276, 72, NULL) ; SetViewportExtEx (hdc, cxClient, cyClient, NULL) ; SetWindowOrgEx (hdc, 138, 36, NULL) ; SetViewportOrgEx (hdc, cxClient / 2, cyClient / 2, NULL) ; SelectObject (hdc, GetStockObject (NULL_PEN)) ; SelectObject (hdc, hBrushRed) ; DisplayTime (hdc, f24Hour, fSuppress) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: KillTimer (hwnd, ID_TIMER) ; DeleteObject (hBrushRed) ; PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
bool Display(float timeDelta) { if( Device ) { //update audio AudioUpdate(); //keyboard if( ::GetAsyncKeyState('W') & 0x8000f) { TheCamera.walk(40.0f * timeDelta); //D3DXMATRIX forwardMovement; //D3DXMatrixRotationY(&forwardMovement, avatarYaw); //D3DXVECTOR3 v(0,0,forwardSpeed); //D3DXVECTOR4 vec4; //D3DXVec3Transform(&vec4, &v, &forwardMovement); //avatarDirection.x = v.x = vec4.x; //avatarDirection.y = v.y = vec4.y; //avatarDirection.z = v.z = vec4.z; //AvatarPosition.z += v.z; //AvatarPosition.x += v.x; } if( ::GetAsyncKeyState('S') & 0x8000f) { TheCamera.walk(-40.0f * timeDelta); //D3DXMATRIX forwardMovement; //D3DXMatrixRotationY(&forwardMovement, avatarYaw); //D3DXVECTOR3 v(0,0,-forwardSpeed); //D3DXVECTOR4 vec4; //D3DXVec3Transform(&vec4, &v, &forwardMovement); //avatarDirection.x = v.x = vec4.x; //avatarDirection.y = v.y = vec4.y; //avatarDirection.z = v.z = vec4.z; //AvatarPosition.z += v.z; //AvatarPosition.x += v.x; } if( ::GetAsyncKeyState('A') & 0x8000f) { TheCamera.yaw(-4.0f * timeDelta); //avatarYaw -= rotationSpeed; } if( ::GetAsyncKeyState('D') & 0x8000f) { TheCamera.yaw(4.0f * timeDelta); //avatarYaw -= rotationSpeed; } if( ::GetAsyncKeyState('I') & 0x8000f) { TheCamera.pitch(-4.0f * timeDelta); } if( ::GetAsyncKeyState('K') & 0x8000f) { TheCamera.pitch(4.0f * timeDelta); } D3DXVECTOR3 f = TheCamera.GetPosition(); if(f.x > 190) f.x = 190; if(f.x < -190) f.x = -190; if(f.z > 190) f.z = 190; if(f.z < -190) f.z = -190; //if(f.y > 390) // f.y = 390; //if(f.y < 10) // f.y = 10; float height = TheTerrain->getHeight(f.x, f.z); f.y = height + 5.0f; TheCamera.setPosition(&f); //camera stuff D3DXMATRIX V, o; TheCamera.getViewMatrix(&V); Device->SetTransform(D3DTS_VIEW, &V); //UpdateCameraThirdPerson(); // // Draw the scene: // Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L); Device->BeginScene(); D3DXMATRIX I; D3DXMatrixIdentity(&I); if(TheTerrain) TheTerrain->draw(&I, false); //Device->SetTexture(0, Armor) D3DXMATRIX i, tripler, grow; Collides(); DisplayTime(); DisplayRemaining(); // //Barrels1 // if(BoolTrash[0]) { D3DXMatrixTranslation(&tripler, TrashPositions[0].x + 0,TrashPositions[0].y, TrashPositions[0].z-10); D3DXMatrixScaling(&grow, .05,.05,.05); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Barrels.Draw(NULL); } // //Barrels2 // if(BoolTrash[1]) { D3DXMatrixTranslation(&tripler, TrashPositions[1].x +0,TrashPositions[1].y,TrashPositions[1].z-10); D3DXMatrixScaling(&grow, .05,.05,.05); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Barrels.Draw(NULL); } // //Dalek1 // if(BoolTrash[2]) { D3DXMatrixTranslation(&tripler, TrashPositions[2].x +0,TrashPositions[2].y+8,TrashPositions[2].z-10); D3DXMatrixScaling(&grow, .05,.05,.05); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Dalek.Draw(NULL); } // //Dalek2 // if(BoolTrash[3]) { D3DXMatrixTranslation(&tripler,TrashPositions[3].x +0,TrashPositions[3].y+8,TrashPositions[3].z-10); D3DXMatrixScaling(&grow, .05,.05,.05); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Dalek.Draw(NULL); } // //Tank1 // if(BoolTrash[4]) { D3DXMatrixTranslation(&tripler, TrashPositions[4].x +40,TrashPositions[4].y+14,TrashPositions[4].z+0); D3DXMatrixScaling(&grow, .1,.1,.1); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); tank.Draw(NULL); } // //Tank2 // if(BoolTrash[5]) { D3DXMatrixTranslation(&tripler, TrashPositions[5].x +40,TrashPositions[5].y+14,TrashPositions[5].z+0); D3DXMatrixScaling(&grow, .1,.1,.1); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); tank.Draw(NULL); } // //Table1 // if(BoolTrash[6]) { D3DXMatrixTranslation(&tripler, TrashPositions[6].x +0,TrashPositions[6].y,TrashPositions[6].z-10); D3DXMatrixScaling(&grow, 10,10,10); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Table.Draw(NULL); } // //Table2 // if(BoolTrash[7]) { D3DXMatrixTranslation(&tripler, TrashPositions[7].x +0,TrashPositions[7].y,TrashPositions[7].z-10); D3DXMatrixScaling(&grow,10,10,10); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Table.Draw(NULL); } // //Ton1 // if(BoolTrash[8]) { D3DXMatrixTranslation(&tripler, TrashPositions[8].x +0,TrashPositions[8].y,TrashPositions[8].z-10); D3DXMatrixScaling(&grow,10,10,10); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Ton.Draw(NULL); } // //Ton2 // if(BoolTrash[9]) { D3DXMatrixTranslation(&tripler, TrashPositions[9].x +0,TrashPositions[8].y,TrashPositions[9].z-10); D3DXMatrixScaling(&grow,10,10,10); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Ton.Draw(NULL); } for(int i = 0; i < numbertrees; i++) { D3DXMatrixTranslation(&tripler, TreePositions[i].x +0,TreePositions[i].y,TreePositions[i].z-10); D3DXMatrixScaling(&grow,5,5,5); D3DXMatrixMultiply(&tripler, &grow, &tripler); Device->SetTransform(D3DTS_WORLD, &tripler); Tree.Draw(NULL); } if(messageDone) { if(allfound) { sprintf(buffers, "Seconds taken to find all objects: %i", seconds); ::MessageBoxA(0, buffers, "Congratulations", 0); //::PostQuitMessage(0); messageDone = false; } } renderSkybox(Device, TheCamera); DrawMinimap(); Device->EndScene(); Device->Present(0, 0, 0, 0); } if(GetTickCount() - dwFinalTick > 1000) { seconds = seconds + 1; dwInitialTick = dwFinalTick; dwFinalTick = GetTickCount(); countDown = countDown+ 1; } return true; }
/** * @brief RTC Application runs in while loop * @param None * @retval : None */ void RTC_Application(void) { uint8_t ReturnValue; CalculateTime(); if(TimeDateDisplay==0) { DisplayTime(); } if(DisplayDateFlag==1 && TimeDateDisplay==0) { DisplayDate(); DisplayDateFlag=0; } if(AlarmStatus==1) { DisplayAlarm(); GPIO_SetBits(GPIOC, GPIO_Pin_6); Dummy=RTC_GetCounter(); AlarmStatus=2; } if(((RTC_GetCounter()-Dummy) == 4) && (AlarmStatus==2)) { GPIO_ResetBits(GPIOC, GPIO_Pin_6); SelIntExtOnOffConfig(ENABLE); RightLeftIntExtOnOffConfig(ENABLE); UpDownIntOnOffConfig(ENABLE); MenuInit(); Dummy=0; AlarmStatus = 0; } if(TamperEvent == 1) /* Tamper event is detected */ { TamperNumber = TamperNumber + 1; BKP_WriteBackupRegister(BKP_DR5,TamperNumber); BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE); BKP_WriteBackupRegister(BKP_DR2,s_DateStructVar.Month); BKP_WriteBackupRegister(BKP_DR3,s_DateStructVar.Day); BKP_WriteBackupRegister(BKP_DR4,s_DateStructVar.Year); BKP_WriteBackupRegister(BKP_DR9,s_AlarmDateStructVar.Day); BKP_WriteBackupRegister(BKP_DR8,s_AlarmDateStructVar.Month); BKP_WriteBackupRegister(BKP_DR10,s_AlarmDateStructVar.Year); BKP_WriteBackupRegister(BKP_DR6,ClockSource); BKP_WriteBackupRegister(BKP_DR7,SummerTimeCorrect); ReturnValue=EE_WriteVariable(TamperNumber); if(ReturnValue==PAGE_FULL) { ReturnValue=EE_WriteVariable(TamperNumber); } ReturnValue=EE_WriteVariable(s_DateStructVar.Day); ReturnValue=EE_WriteVariable(s_DateStructVar.Month); ReturnValue=EE_WriteVariable((s_DateStructVar.Year)/100); ReturnValue=EE_WriteVariable((s_DateStructVar.Year)%100); ReturnValue=EE_WriteVariable((s_TimeStructVar.HourHigh*10)+\ s_TimeStructVar.HourLow); ReturnValue=EE_WriteVariable((s_TimeStructVar.MinHigh*10)+\ s_TimeStructVar.MinLow); ReturnValue=EE_WriteVariable((s_TimeStructVar.SecHigh*10)+\ s_TimeStructVar.SecLow); while(!(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13))) { } TamperEvent=0; BKP_TamperPinCmd(ENABLE); } if(BatteryRemoved != 0) /* Battery tamper is detected */ { TamperNumber = TamperNumber + 1; BKP_WriteBackupRegister(BKP_DR5,TamperNumber); ReturnValue=EE_WriteVariable(TamperNumber); if(ReturnValue==PAGE_FULL) { ReturnValue=EE_WriteVariable(TamperNumber); } ReturnValue=EE_WriteVariable(s_DateStructVar.Day); ReturnValue=EE_WriteVariable(s_DateStructVar.Month); ReturnValue=EE_WriteVariable((s_DateStructVar.Year)/100); ReturnValue=EE_WriteVariable((s_DateStructVar.Year)%100); ReturnValue=EE_WriteVariable((s_TimeStructVar.HourHigh*10)\ +s_TimeStructVar.HourLow); ReturnValue=EE_WriteVariable((s_TimeStructVar.MinHigh*10)\ +s_TimeStructVar.MinLow); if(BatteryRemoved==1) { ReturnValue=EE_WriteVariable(BATTERY_REMOVED); BatteryRemoved=0; } else if(BatteryRemoved==2) { ReturnValue=EE_WriteVariable(BATTERY_RESTORED); BatteryRemoved=0; } BKP_TamperPinCmd(ENABLE); } }
static void DisplayDecrementedTime(void){ // Method for decrementing the time by 1 minute and then displaying it DecrementTime(); DisplayTime(); }
//overall display function void DisplayFunc() { window.FPS++; float current_time = (glutGet(GLUT_ELAPSED_TIME)) / 1000.0f; current_time = current_time - window.total_time_paused; ostringstream convert; convert << (int)current_time; string display_current_time = convert.str(); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); if (!window.paused) { glDisable(GL_CULL_FACE); glClearColor(0.9f, 0.9f, 0.9f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, window.size.x, window.size.y); mat4 projection; if (debug_mode != 3) projection = perspective(20.0f, window.aspect, 1.0f, 600.0f); else projection = perspective(30.0f, window.aspect, 1.0f, 600.0f); radius = 20.1f; float tempX = xpos; float tempZ = zpos; float tempLookatX = lookatX; float tempLookatZ = lookatZ; mat4 modelview; //movement (with a buffer zone in center) in first person view if ((debug_mode != 2 && debug_mode != 0) && (xDiffFromCenter > 0.5f || xDiffFromCenter < -0.5f || yDiffFromCenter > 0.5f || yDiffFromCenter < -0.5f)) { if ((xpos <= -105.0f + window.ball_radius || xpos >= 105 - window.ball_radius)) //bounce off walls { lookatX = xpos - (lookatX - xpos); angleV = -angleV; window.hit_something = true; } if ((zpos <= -105.0f + window.ball_radius || zpos >= 105.0f - window.ball_radius)) //bounce off walls { lookatZ = zpos - (lookatZ - zpos); while (angleV < 0.0f) angleV = 360.0f + angleV; angleV = 180 - angleV; window.hit_something = true; } // turn right or left angleV = angleV - xDiffFromCenter * 0.1f; lookatX = xpos - sin(angleV * (PI / 180)) * radius ; lookatZ = zpos - cos(angleV * (PI / 180)) * radius; //move forward and backwards xpos = xpos + ((lookatX - xpos) * yDiffFromCenter * 0.02f ); //multiply by level to compensate adding more balls and //slowing down of processing them zpos = zpos + ((lookatZ - zpos) * yDiffFromCenter * 0.02f); ypos = ypos + ((0 - ypos) * 0.003f); zpos = clamp(zpos, -104.5f, 104.5f); xpos = clamp(xpos, -104.5f, 104.5f); } //movement in third person view if ((debug_mode == 2 || debug_mode == 0) && (xDiffFromCenter > 0.5f || xDiffFromCenter < -0.5f)) { angleH = angleH - xDiffFromCenter * 0.05f; cameraX = sin(angleH * (PI / 180)) * 110.0f; cameraZ = cos(angleH * (PI / 180)) * 110.0f; } if (debug_mode == 0 && (yDiffFromCenter > 0.5f || yDiffFromCenter < -0.5f)) { angleh = angleh + yDiffFromCenter * 0.05f; cameraY = sin(angleh * (PI / 180)) * 110.0f; } //check to see if going to hit a box and calculate position for (int i = 0; i < (int)boxes.size(); i++) { if (xpos >= (boxes.at(i).getPostion().x - window.obstacle_width/2.0f - window.ball_radius) && xpos <= (boxes.at(i).getPostion().x + window.obstacle_width/2.0f + window.ball_radius)) { if (zpos >= (boxes.at(i).getPostion().z - window.obstacle_width/2.0f - window.ball_radius) && (zpos) <= (boxes.at(i).getPostion().z + window.obstacle_width/2.0f + window.ball_radius)) { boxes.at(i).setForce(yDiffFromCenter); float direction_X; direction_X = boxes.at(i).getPostion().x - xpos; float direction_Z; direction_X = boxes.at(i).getPostion().z - zpos; boxes.at(i).setDirection(vec3(direction_X, ypos, direction_Z)); window.hit_something = true; /*cout << boxes.at(i).getPostion().x << ", " << boxes.at(i).getPostion().z << ", " << i << endl; cout << "Force: " << boxes.at(i).getForce() << endl; cout << "direction: " << boxes.at(i).getDirection().x << ", " << boxes.at(i).getDirection().z << endl;*/ if (zpos < boxes.at(i).getPostion().z - window.obstacle_width/2.0f || zpos > boxes.at(i).getPostion().z + window.obstacle_width/2.0f) { //lookatX = tempLookX; lookatZ = zpos - (lookatZ - zpos); while (angleV < 0.0f) angleV = 360.0f + angleV; angleV = 180 - angleV; //cout << "hit z side " << endl; } else if (xpos < boxes.at(i).getPostion().x - window.obstacle_width/2.0f || xpos > boxes.at(i).getPostion().x + window.obstacle_width/2.0f) { lookatX = xpos - (lookatX - xpos); angleV = -angleV; //cout << "hit x side " << endl; } } } //boxes.at(i) = Object_movement(boxes.at(i), boxes.at(i).getPostion(), boxes.at(i).getForce(), boxes.at(i).getDirection()); } //check to see if hitting ball for(int i = 0; i < window.num_balls; i++) { if (xpos >= (balls.at(i).getPostion().x - window.ball_radius - window.ball_radius) && (xpos) <= (balls.at(i).getPostion().x + window.ball_radius + window.ball_radius)) { if (zpos >= (balls.at(i).getPostion().z - window.ball_radius - window.ball_radius) && (zpos) <= (balls.at(i).getPostion().z + window.ball_radius + window.ball_radius)) { if (i == 10) { window.gameOver = true; xpos = tempX; zpos = tempZ; debug_mode = 2; } balls.at(i).hit(current_time + 30.0f + (float)window.num_balls * 2.0f, current_time); // set the timer for the ball glClearColor(0.0f, 0.0f, 0.0f, 1.0f); lookatZ = zpos - (lookatZ - zpos); lookatX = xpos - (lookatX - xpos); //use pythagorean theorem and law of cosines to find angle float distanceA = sqrt(pow((balls.at(i).getPostion().x - xpos), 2) + pow((balls.at(i).getPostion().z - zpos), 2)); float distanceB = sqrt(pow((lookatX - balls.at(i).getPostion().x), 2) + pow((lookatZ - balls.at(i).getPostion().z), 2)); float distanceC = sqrt(pow((xpos - lookatX), 2) + pow((zpos - lookatZ), 2)); float angleTemp = acos((pow(distanceB, 2) - pow(distanceA, 2) - pow(distanceC, 2)) / (2 * distanceA * distanceC)); //cout << "original: " << angleV << endl; //cout << "angleTemp: " << angleTemp << endl; if (yDiffFromCenter >= 0.0f) angleV = angleV + 90 - angleTemp * 5.0f; else angleV = angleV - 90 - angleTemp * 5.0f; //cout << "new angle: " << angleV << endl; window.hit_something = true; } } } if (debug_mode == 1) { modelview = lookAt(vec3(xpos, ypos, zpos), vec3(lookatX, ypos, lookatZ), vec3(0.0f, 1.0f, 0.0f)); } else if (debug_mode == 2) { modelview = lookAt(vec3(cameraX, 30.0f, cameraZ), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); } else if (debug_mode == 3) { modelview = lookAt(vec3(0.1f, 400.0f, 0.0f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 1.0f, 0.0f)); } else { modelview = lookAt(vec3(0.0f, 0.0f, 0.0f), vec3(cameraX, cameraY, cameraZ), vec3(0.0f, 1.0f, 0.0f)); } //FrameBuffering RenderIntoFrameBuffer(modelview, projection); glViewport(0, 0, window.size.x, window.size.y); RenderIntoFrameBuffer2(modelview, projection); glViewport(0, 0, window.size.x, window.size.y); DisplayFuncClock(); glViewport(0, 0, window.size.x, window.size.y); glPolygonMode(GL_FRONT_AND_BACK, window.wireframe ? GL_LINE : GL_FILL); //Draw skybox if (debug_mode != 3) sky.Draw(projection, modelview, window.size, window.stage, window.shader); if (debug_mode != 0) { //Draw map elements (ground and walls) modelview = translate(modelview, vec3(0.0f, -1.0f, 0.0f)); trueGround.Draw_floors(projection, modelview, window.size, fbo2, current_time); walls.Draw_walls(projection, modelview, window.size); modelview = translate(modelview, vec3(0.0f, 1.0f, 0.0f)); //Draw jumbotrons and scoreboards modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f)); tron.Draw(projection, modelview, window.size, window.stage, window.shader); screen.DrawScreen(projection, modelview, window.size, fbo, 0); modelview = translate(modelview, vec3(0.0f, 4.5f, -0.2f)); screen.DrawScreen(projection, modelview, window.size, fbo, 5); //Draw one jumbotron with the field name modelview = translate(modelview, vec3(0.0f, -4.5f, 0.2f)); modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f)); modelview = rotate(modelview, 180.0f, vec3(0.0f, 1.0f, 0.0f)); modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f)); tron.Draw(projection, modelview, window.size, window.stage, window.shader); screen.DrawScreen(projection, modelview, window.size, fbo, 0); modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f)); modelview = rotate(modelview, 90.0f, vec3(0.0f, 1.0f, 0.0f)); modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f)); /*score.Draw(projection, modelview, window.size, window.stage, window.shader); scoreScreen.DrawScreen(projection, modelview, window.size, window.stage, fbo2); */ tron.Draw(projection, modelview, window.size, window.stage, window.shader); screen.DrawScreen(projection, modelview, window.size, fbo, 0); modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f)); modelview = rotate(modelview, 180.0f, vec3(0.0f, 1.0f, 0.0f)); modelview = translate(modelview, vec3(0.0f, 0.0f, -107.0f)); //score.Draw(projection, modelview, window.size, window.stage, window.shader); tron.Draw(projection, modelview, window.size, window.stage, window.shader); screen.DrawScreen(projection, modelview, window.size, fbo, 0); modelview = translate(modelview, vec3(0.0f, 0.0f, 107.0f)); modelview = rotate(modelview, -90.0f, vec3(0.0f, 1.0f, 0.0f)); //Draw player (and other objects) modelview = translate(modelview, vec3(0.0f, -1.0f, 0.0f)); modelview = translate(modelview, vec3(0.0f, window.ball_radius, 0.0f)); //make sure balls are on ground modelview = translate(modelview, vec3(xpos, ypos, zpos)); if (debug_mode != 1) player.Draw(projection, modelview, window.size, window.stage, window.shader); modelview = translate(modelview, vec3(-xpos, -ypos, -zpos)); window.num_hit = 0; for (int i = 0; i < window.num_balls; i++) //places the desired number of balls on field { modelview = translate(modelview, balls.at(i).getPostion()); //places in random location if (i == 10) { bomb.Draw(projection, modelview, window.size, window.stage, window.shader, current_time); //Place a bomb (not in lower levels) } else if (balls.at(i).is_sphere_hit()) { ball2.Draw(projection, modelview, window.size, window.stage, window.shader, current_time); balls.at(i).setTime(current_time); //set time and display remaining time above ball DisplayTime(modelview, projection, balls.at(i).getEndTime() - balls.at(i).getTime(), balls.at(i).getPostion()); window.num_hit++; } else { ball.Draw(projection, modelview, window.size, window.stage, window.shader, current_time); } modelview = translate(modelview, -balls.at(i).getPostion()); } if (window.num_balls - window.num_hit != window.num_remaining) { window.num_remaining = window.num_balls - window.num_hit; if (window.num_balls >= 10) window.num_remaining--; ostringstream convert3; ostringstream convert2; convert3 << window.num_remaining; if (window.num_balls >= 10) convert2 << window.num_balls - 1 << " + (1!)"; else convert2 << window.num_balls; displayNumRemaining = convert3.str(); displayNumBalls = convert2.str(); window.instructions.pop_back(); window.instructions.pop_back(); window.instructions.push_back("Targets remaining: " + displayNumRemaining + "/" + displayNumBalls); window.instructions.push_back("Time played: " + display_current_time); if (window.num_remaining == 0 ) { ostringstream convert4; window.stage++; debug_mode = 2; window.betweenLevels = true; setLevel(); convert4.clear(); convert4 << window.stage; displayLevel = convert4.str(); window.instructions.pop_back(); window.instructions.pop_back(); window.instructions.pop_back(); window.instructions.push_back("Level: " + displayLevel); window.instructions.push_back("Targets remaining: " + displayNumRemaining + " / " + displayNumBalls); window.instructions.push_back("Time played: " + display_current_time); } } modelview = translate(modelview, vec3(0.0f, -window.ball_radius, 0.0f)); for (int i = 0; i < (int)boxes.size(); i++) //places the desired number of obstacles on field { modelview = translate(modelview, boxes.at(i).getPostion()); //places in random location box.Draw(projection, modelview, window.size, window.stage, window.shader); modelview = translate(modelview, -boxes.at(i).getPostion()); } if (!window.gameStart) //Display start screen { modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f)); modelview = scale(modelview, vec3(3.0f, 2.0f, 3.0f)); screen.DrawScreen(projection, modelview, window.size, fbo, 1); //Display intro screen } if (window.betweenLevels) //Display next level screen { modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f)); screen.DrawScreen(projection, modelview, window.size, fbo, 2); } if (window.gameOver) //Display losing screen { modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f)); screen.DrawScreen(projection, modelview, window.size, fbo, 3); } if (window.gameWon) //Display winning screen { modelview = rotate(modelview, angleH, vec3(0.0f, 1.0f, 0.0f)); screen.DrawScreen(projection, modelview, window.size, fbo, 4); } } window.instructions.pop_back(); window.instructions.push_back("Time played: " + display_current_time); //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); DisplayInstructions(); DisplayCursor(); //display the minimap if (window.minimap) DisplayFunc2(); //Display the clock if (window.clock_on) DisplayFuncClock2(); if (window.hit_something) // display a cracked screen if hit something { DisplayFuncCrack(); } window.hit_something = false; //reset to not show cracked screen } //glFlush(); glutSwapBuffers(); glutPostRedisplay(); // FPS }