bool DetectRobot_Robot (RobotClass r1, RobotClass r2){ //used to avoid robot/robot overlap double xdiff = r1.getXPosition() - r2.getXPosition(); double ydiff = r1.getYPosition() - r2.getYPosition(); double distance = r1.getWidth()/2 + r2.getWidth()/2; if(xdiff*xdiff + ydiff*ydiff <= distance*distance){ return true; } else return false; }
//-------------------------helper functions-------------------------------------------------------- bool DetectLights_Robot (Light lig, RobotClass r1){ //used to avoid light/robot overlap double xdiff = lig.getXPosition() - r1.getXPosition(); double ydiff = lig.getYPosition() - r1.getYPosition(); double distance = lig.getWidth()/2 + r1.getWidth()/2; if(xdiff*xdiff + ydiff*ydiff <= distance*distance){ return true; } else return false; }
void Simulation::renderRobot(RobotClass robot, int count){ int i = 0; double r = robot.getWidth()/2.0; double ori = robot.getOrientation(); int k = count % 50; int k2 = (count + 20) % 50; int k3 = (count + 40) % 50; double s = (robot.getActionRange() - r)/50; glPushMatrix(); if (robot.getShapeType() == Circle){ glTranslatef(robot.getXPosition(), robot.getYPosition(), 0.0f); glColor3f(1.0, 0.0, 1.0); glBegin(GL_TRIANGLE_FAN); for (i = 0; i <= 50; i++){ glVertex2f( (r *cos (i * 2.0 * M_PI/50)), (r *sin (i * 2.0 * M_PI/50)) ); } glEnd(); glColor3f(0.5 + 0.5 * k/49.0, 0.0, 0.5 + 0.5 * k/49.0); glBegin(GL_LINE_LOOP); for (i = 0; i <= 50; i++){ glVertex2f( ((r + s * k3) *cos (i * 2.0 * M_PI/50)), ((r + s * k3) *sin (i * 2.0 * M_PI/50)) ); } glEnd(); glColor3f(0.3 + 0.5 * k/49.0, 0.0, 0.3 + 0.5 * k/49.0); glBegin(GL_LINE_LOOP); for (i = 0; i <= 50; i++){ glVertex2f( ((r + s * k2) *cos (i * 2.0 * M_PI/50)), ((r + s * k2) *sin (i * 2.0 * M_PI/50)) ); } glEnd(); glColor3f(0.0 + 0.5 * k/49.0, 0.0, 0.0 + 0.5 * k/49.0); glBegin(GL_LINE_LOOP); for (i = 0; i <= 50; i++){ glVertex2f( ((r + s * k) *cos (i * 2.0 * M_PI/50)), ((r + s * k) *sin (i * 2.0 * M_PI/50)) ); } glEnd(); glColor3f(1.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); for (i = 0; i <= 50; i++){ glVertex2f( (robot.getActionRange() *cos (i * 2.0 * M_PI/50)), (robot.getActionRange() *sin (i * 2.0 * M_PI/50)) ); } glEnd(); glColor3f(1.0, 1.0, 1.0); glBegin(GL_TRIANGLES); glVertex2f( 1.5* r * cos(ori), 1.5* r * sin(ori) ); glVertex2f( 2* r* cos(robot.regular_Ori(ori+2*M_PI/3.0)), 2* r* sin(robot.regular_Ori(ori+2*M_PI/3.0)) ); glVertex2f( 0.5* r* cos(-1 * ori), 0.5* r* sin(-1 * ori) ); glVertex2f( 1.5* r * cos(ori), 1.5* r * sin(ori) ); glVertex2f( 2* r* cos(robot.regular_Ori(ori-2*M_PI/3.0)), 2* r* sin(robot.regular_Ori(ori-2*M_PI/3.0)) ); glVertex2f( 0.5* r* cos(robot.regular_Ori(-1 * ori)), 0.5* r* sin(robot.regular_Ori(-1 * ori)) ); glEnd(); } glPopMatrix(); }