void Graphics::HandleEventOnDisplay(void) { char str[100]; if(m_motionPlannerDraw) m_motionPlanner->Draw(); //draw robot glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glColor3f(1, 0, 0); glBegin(GL_POLYGON); glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[0])); glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[2])); glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[4])); glVertex2dv(&(m_motionPlanner->m_simulator->m_robotCurr[6])); glEnd(); glColor3f(0, 0, 0); DrawPoint2D(m_motionPlanner->m_simulator->GetRobotCenterX(), m_motionPlanner->m_simulator->GetRobotCenterY()); if(m_bestPathAnimate && m_bestPath.size() > 0) { sprintf(str, "%d", m_bestPathCurrReward); glColor3f(0, 0, 0); DrawString2D(m_motionPlanner->m_simulator->GetRobotCenterX(), m_motionPlanner->m_simulator->GetRobotCenterY(), str); } //draw obstacles glColor3f(0.45, 0.34, 0.76); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBegin(GL_TRIANGLES); const int no = m_motionPlanner->m_simulator->GetNrObstacles(); for(int i = 0; i < no; ++i) { Simulator::Obstacle *obst = m_motionPlanner->m_simulator->m_obstacles[i]; const int ntri = obst->m_triangles.size(); for(int j = 0; j < ntri; j += 3) { glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 0]]); glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 1]]); glVertex2dv(&obst->m_vertices[2 * obst->m_triangles[j + 2]]); } } glEnd(); //draw reward regions if(m_bestPathAnimate && m_bestPath.size() > 0) { for(int i = 0; i < m_bestPathCurrRemainingRewards.size(); ++i) { const int id = m_bestPathCurrRemainingRewards[i]; glColor3f(0, 1, 0); DrawCircle2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id), m_motionPlanner->m_simulator->GetRewardRegionCenterY(id), m_motionPlanner->m_simulator->GetRewardRegionRadius(id)); sprintf(str, "%d", m_motionPlanner->m_simulator->GetRewardRegionValue(id)); glColor3f(0, 0, 0); DrawString2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id), m_motionPlanner->m_simulator->GetRewardRegionCenterY(id), str); } } else { for(int i = 0; i < m_motionPlanner->m_simulator->GetNrRewardRegions(); ++i) { const int id = i; glColor3f(0, 1, 0); DrawCircle2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id), m_motionPlanner->m_simulator->GetRewardRegionCenterY(id), m_motionPlanner->m_simulator->GetRewardRegionRadius(id)); sprintf(str, "%d", m_motionPlanner->m_simulator->GetRewardRegionValue(id)); glColor3f(0, 0, 0); DrawString2D(m_motionPlanner->m_simulator->GetRewardRegionCenterX(id), m_motionPlanner->m_simulator->GetRewardRegionCenterY(id), str); } } }
void iGraphics::draw_point (int x, int y) { DrawPoint2D (x, invert (y)); };