// Here is the function that gets called each time the window needs to be redrawn. // It is the "paint" method for our program, and is set up from the glutDisplayFunc in main void render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); if(start){ depth += speed/2.0; puckFB -= speed; checkGoal(); } AdjustVertexData(puckLR, puckFB); glUseProgram(shaderProgramID); // Fill the matrices with valid data MathHelper::makeScale(scaleMatrix, scaleAmount, scaleAmount, scaleAmount); MathHelper::makeRotateY(rotYMatrix, thetaY); MathHelper::makeRotateX(rotXMatrix, thetaX); MathHelper::makeTranslate(transMatrix, horizontal, vertical, depth); /*multiply the matricies*/ MathHelper::matrixMult4x4(tempMatrix1, rotXMatrix, scaleMatrix); MathHelper::matrixMult4x4(tempMatrix2, rotYMatrix, tempMatrix1); MathHelper::matrixMult4x4(M, transMatrix, tempMatrix2); glUniformMatrix4fv(modelMatrixID, 1, GL_TRUE, M); glUniformMatrix4fv(viewMatrixID, 1, GL_TRUE, V); glUniformMatrix4fv(perspectiveMatrixID, 1, GL_TRUE, P); glPolygonMode(GL_FRONT_AND_BACK, GL_QUADS); glDrawElements (GL_TRIANGLES, ARRAY_COUNT( indices ), GL_UNSIGNED_INT, NULL); glutSwapBuffers(); glutPostRedisplay(); }
IContextReturnData InGameContext::frameFunc() { try { float dt = _hge->Timer_GetDelta(); auto data = std::dynamic_pointer_cast<InGameContextData>(_data); Player& currentPlayer = _players[data->currentPlayerId]; Player& enemyPlayer = _players[!data->currentPlayerId]; if (_hge->Input_IsMouseOver() && _hge->Input_GetKeyState(HGEK_LBUTTON)) { timeoutTimer.stop(); float mouse_x = 0; float mouse_y = 0; _hge->Input_GetMousePos(&mouse_x, &mouse_y); checkAllowedBounds(mouse_x, mouse_y); mover.moveTo(mouse_x, mouse_y); timeoutTimer.start(); } mover.update(dt); Client::getInstance().getEnemyPaddlePos(enemyPlayer.paddle()->x, enemyPlayer.paddle()->y); Client::getInstance().getPuckPos(_puck->x, _puck->y); checkCollisions(); checkGoal(); timers.update(dt); timeoutTimer.update(dt); if(Client::getInstance().isGameOver()) { bool win = Client::getInstance().getWinnerId() == data->currentPlayerId; return IContextReturnData(Context::GameOverContext, std::make_shared<GameOverContextData>( _data->screenWidth, _data->screenHeight, win, &_players[0], &_players[1])); } if(Client::getInstance().shouldStop()) return IContextReturnData(Context::GameErrorContext, nullptr); return IContextReturnData(Context::InGameContext, data); } catch (std::exception& e) { return IContextReturnData(Context::GameErrorContext, nullptr); } }
void PositionCommand::actionRecive() { feedback_.pose.pose.position.x = current_pose_(0,0); feedback_.pose.pose.position.y = current_pose_(1,0); feedback_.pose.pose.position.z = current_pose_(2,0); feedback_.pose.pose.orientation.x = current_pose_(3,0); feedback_.pose.pose.orientation.y = current_pose_(4,0); feedback_.pose.pose.orientation.z = current_pose_(5,0); as_.publishFeedback(feedback_); if(checkGoal(current_error_)) { res_.pose = feedback_.pose; ROS_INFO("%s: Succeeded", action_name_.c_str()); as_.setSucceeded(res_); action_recived_ = false; } }
void idle(void) { /* * Increment time to render puck at various times in its trajectory. Puck's trajectory is rendered until puck reaches bounds * of clipping volume, until time = 20, or if a goal is scored. */ if (time < 20.0 && puckShot == 1 && puckAtTime[0] <= 500.0 && puckAtTime[0] >= 0.0 && puckAtTime[1] >= 10 && puckAtTime[1] <= 500 && puckAtTime[2] >= 1.0 && puckAtTime[2] <= 900.0){ time += 0.02; checkGoal(); } else if (puckShot == 1){ textNum = 2; resetPuck(); } /* * Move power bar back and forth between x= 230 and * x = 280 (the min and max x values of power meter) */ if (power < 50 && reachedRight == 0 && stopPowerBar == 0){ power += 1; if (power == 50) { reachedRight = 1; } } else if (power <= 50 && reachedRight == 1 && stopPowerBar == 0){ power += -1; if (power == 0){ reachedRight = 0; } } /* Change camera view * puckCam = 0 -> Stick cam * puckCam = 1 -> Puck cam * puckCam = 2 -> Goal cam * */ if (puckCam == 1){ viewer[0] = puckAtTime[0]; viewer[1] = puckAtTime[1]; viewer[2] = puckAtTime[2] - 25; } else if (puckCam == 2){ viewer[0] = 250.0; viewer[1] = 100.0; viewer[2] = 210.0; reference[0] = puckAtTime [0]; reference[1] = puckAtTime [1]; reference[2] = puckAtTime [2]; } else if (puckCam == 0){ viewer[0] = 250.0; viewer[1] = 50.0; viewer[2] = 1000.0; reference[0] = 250.0; reference[1] = 50.0; reference[2] = 1.0; } /* * Flash 'Goals Scored' yellow if goal scored */ if (textNum == 1){ scoreColor[2] = 0.0+flash; if (flash == 0){ flash++; } else if (flash == 1) { flash--; } } else{ scoreColor[2] = 1.0; } display(); }