void World_draw(void) { Draw* map = Draw_new("mapa",0,500,500); int i,j; for (i=0; i<=8; i++) { Draw_line(map,0,i*500/8,500,i*500/8); Draw_line(map,i*500/8,0,i*500/8,500); for (j=0;j<8&&i<8;j++) { if (World_get_cell(j,i) == 1) Draw_circle(map,j*500/8+500/16,i*500/8+500/16,500/16); } } Draw_destroy(map); }
// Ⱦ void Channel2D::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTranslatef(0.0, 0.0, translate);// translate is included in <QKeyEvent> glTranslatef(0.0, -0.5, 0.3);// translate is included in <QKeyEvent> glRotatef(xRot, 1.0, 0.0, 0.0); glRotatef(yRot, 0.0, 1.0, 0.0); glRotatef(zRot, 0.0, 0.0, 1.0); glBegin(GL_QUADS); glEnable (GL_LINE_SMOOTH ); glHint (GL_POLYGON_SMOOTH , GL_NICEST); //histoPlot1(); //histoPlot2(); //histoPlot3(); //histoPlot4(); //floor wallplot(); glEnd(); //Draw_point(); Draw_line(); }
void Navigate_test_sensor_data_parse_1() { Polygon* obstacle = NULL; float distance = 200.0f, angle = 0, x, y; char test_name[100], label[20], i; // using binary for combinatorics with k = 2 unsigned char sensor_switch; for (sensor_switch = 0; sensor_switch < 32; sensor_switch++) { sprintf(label, "[ %s, %s, %s, %s, %s ]", (sensor_switch & 0b0000001) ? "1" : "0", (sensor_switch & 0b0000010) ? "1" : "0", (sensor_switch & 0b0000100) ? "1" : "0", (sensor_switch & 0b0001000) ? "1" : "0", (sensor_switch & 0b0010000) ? "1" : "0"); sprintf(test_name, "Navigate_test_sensor_data_parse_%s", label); Draw* TEST_CANVAS = Draw_new(test_name, NULL, WORLD_MAX_X, WORLD_MAX_Y); TEST_CANVAS->style = "stroke:red;fill:red;stroke-width:2"; for (i = 0; i < SENSOR_ORIENTATION->n; i++) { if (sensor_switch & (1 << i)) { angle = Vector_get(SENSOR_ORIENTATION, i); x = distance * cosf((90 - angle) * M_PI / 180.0f); y = distance * sinf((90 - angle) * M_PI / 180.0f); Draw_line(TEST_CANVAS, 0, 0, x, y); Draw_circle(TEST_CANVAS, x, y , 3); } } int sensor_data[5] = { (sensor_switch & 0b0000001) ? distance : NAVIGATION_DISTANCE_SAFE, (sensor_switch & 0b0000010) ? distance : NAVIGATION_DISTANCE_SAFE, (sensor_switch & 0b0000100) ? distance : NAVIGATION_DISTANCE_SAFE, (sensor_switch & 0b0001000) ? distance : NAVIGATION_DISTANCE_SAFE, (sensor_switch & 0b0010000) ? distance : NAVIGATION_DISTANCE_SAFE }; char sensor_data_raw[32]; sprintf(sensor_data_raw, "[%d,%d,%d,%d,%d]", sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4]); obstacle = Navigate_parse_sensor_data(sensor_data_raw); if (obstacle != NULL) { TEST_CANVAS->style = "stroke:blue;fill:none;stroke-width:2"; Polygon_draw(obstacle); Polygon_destroy(obstacle); } TEST_CANVAS->style = "stroke:black;fill:black;stroke-width:2"; Draw_text(TEST_CANVAS, -125, 450, 40, label); Draw_destroy(TEST_CANVAS); } }
// Ⱦ void Ch2_1::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glTranslatef(0.0, 0.0, translate);// translate is included in <QKeyEvent> glTranslatef(0.0, -0.5, 0.3);// translate is included in <QKeyEvent> glRotatef(xRot, 1.0, 0.0, 0.0); glRotatef(yRot, 0.0, 1.0, 0.0); glRotatef(zRot, 0.0, 0.0, 1.0); glBegin(GL_QUADS); glEnable (GL_LINE_SMOOTH ); glHint (GL_POLYGON_SMOOTH , GL_NICEST); //histoPlot1(); //histoPlot2(); //histoPlot3(); //histoPlot4(); //floor wallplot(); glEnd(); //Draw_point(); Draw_line(); glBegin(GL_LINE_STRIP); // 用折线绘 double point2[8][3] = {{2,2,2},{-2,2,2},{-2,2,-2},{2,2,-2},{2,-1,6},{-2,-1,6},{-2,-1,-4},{2,-1,-4}}; for(int i = 0 ; i < 4 ; i++){ L_Adjust(&point2[i+4][2]); D_Adjust(&point2[i+4][0]); } glColor4f(0,0,0,0.2); int crr = 6; int num_p = 50; double step = 10.0/num_p; for(int i = 0 ; i < num_p ; i++){ glVertex3f(point2[crr][0]+2.3, point2[crr][1]+0.2 , point2[crr][2]); //point2[crr][0] = 0.3*sin(point2[crr][2])+(qrand() % 10)/100.0; point2[crr][2] += step; } glEnd(); }