//main display loop, this function will be called again and again by OpenGL void display() { //Misc. glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); radialGradient(WIDTH/2, HEIGHT/2, sqrt(2)*WIDTH/2); setColor(0, 0, 1); flower(100, 100, 100, 10); setColor(0, 0, 0); for (int i = 0; i < 4; i++) { bresenhamLine(D[i * 2], D[i * 2 + 1], D[i * 2 + 2], D[i * 2 + 3]); } for (int i = 0; i < 5; i++) { bresenhamLine(F[i * 2], F[i * 2 + 1], F[i * 2 + 2], F[i * 2 + 3]); } //draws pixel on screen, width and height must match pixel buffer dimension glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_FLOAT, PixelBuffer); //window refresh glFlush(); }
void GLBox::paintGL() { // this method draws the scene into the OpenGL widget // usually you do not call this method directly, instead call updateGL(), which in turn calls paintGL() clearImage(Color(1.0, 1.0, 1.0)); //----- Clock bresenhamCircle(m_clock.getCenter(), m_clock.getRadius()); //draw Hour Pointer bresenhamLine(m_clock.getCenter(), Mat3d::getTranslationmatix(m_clock.getCenter()) * m_clock.getHours(), Color(1,0,0)); //draw Minute Pointer bresenhamLine(m_clock.getCenter(), Mat3d::getTranslationmatix(m_clock.getCenter()) * m_clock.getMinutes(), Color(0,0,1)); //draw Seconds Pointer bresenhamLine(m_clock.getCenter(), Mat3d::getTranslationmatix(m_clock.getCenter()) * m_clock.getSeconds(), Color(0,1,0)); //------------- manageTexture(); glClear( GL_COLOR_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, m_texID); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(-m_winWidth/2, -m_winHeight/2); glTexCoord2i(1, 0); glVertex2i( m_winWidth/2, -m_winHeight/2); glTexCoord2i(1, 1); glVertex2i( m_winWidth/2, m_winHeight/2); glTexCoord2i(0, 1); glVertex2i(-m_winWidth/2, m_winHeight/2); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); // perform all output operations glFlush(); }
void flower(int x0, int y0, int r, int step) { //Draws a flower to show our lines can be drawn at all angles int xf; int yf; for (int i = 0; i < 360; i += step) { xf = r*cosf(i * (3.141592653) / 180); yf = r*sinf(i * (3.141592653) / 180); bresenhamLine(x0, y0, xf + x0, yf + y0); } }
/* Draw a line with bresenham Algo from v1 to v2 with color */ void GLBox::bresenhamLine(Vec3d v1, Vec3d v2, Color color) { double d1[3]; double d2[3]; v1.getData(d1); v2.getData(d2); Point2D p1 (int(d1[0] + 0.5), int(d1[1] + 0.5)); Point2D p2 (int(d2[0] + 0.5), int(d2[1] + 0.5)); bresenhamLine(p1, p2, color); }
//------------------------------------------------------------------------------------- int NavTileHandle::raycast(int layer, const Vector3& start, const Vector3& end, std::vector<Vector3>& hitPointVec) { setMapLayer(layer); pCurrNavTileHandle = this; if(pCurrNavTileHandle->pTilemap->GetNumLayers() < layer + 1) { printf("NavTileHandle::raycast: not found layer(%d)\n", layer); return NAV_ERROR; } // Create a start state MapSearchNode nodeStart; nodeStart.x = int(start.x / pTilemap->GetTileWidth()); nodeStart.y = int(start.z / pTilemap->GetTileHeight()); // Define the goal state MapSearchNode nodeEnd; nodeEnd.x = int(end.x / pTilemap->GetTileWidth()); nodeEnd.y = int(end.z / pTilemap->GetTileHeight()); std::vector<MapSearchNode> vec; bresenhamLine(nodeStart, nodeEnd, vec); if(vec.size() > 0) { vec.erase(vec.begin()); } std::vector<MapSearchNode>::iterator iter = vec.begin(); int pos = 0; for(; iter != vec.end(); iter++) { if(getMap((*iter).x, (*iter).y) == TILE_STATE_CLOSED) break; hitPointVec.push_back(Vector3(float((*iter).x * pTilemap->GetTileWidth()), start.y, float((*iter).y * pTilemap->GetTileWidth()))); pos++; } return pos; }
//------------------------------------------------------------------------------------- void NavTileHandle::bresenhamLine(const MapSearchNode& p0, const MapSearchNode& p1, std::vector<MapSearchNode>& results) { bresenhamLine(p0.x, p0.y, p1.x, p1.y, results); }
//绘制宽线段 int DrawWideLine(HDC hdc, int iLineStyle, int iLineWidth, int x1, int y1, int x2, int y2, BYTE bType) { bresenhamLine(hdc, iLineStyle, iLineWidth, x1, y1, x2, y2,bType); return 0; }
void bresenhamLine(int x1, int y1, int x2, int y2) { bresenhamLine(x1, y1, x2, y2, 0.4f, 1.0f, 0.0f); }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw Axis bresenhamLine(0, -1000, 0, 1000, 1.0f, 1.0f, 1.0f); bresenhamLine(-1000, 0, 1000, 0, 1.0f, 1.0f, 1.0f); // THIS IS WHERE WE DO OUR DRAWING // From the Slide bresenhamLine(0, 0, 100, -100); bresenhamLine(50, -20, 80, -40); bresenhamLine(30, -60, 60, -40); bresenhamLine(10, -70, 85, 10); /* Sample lines from Won to test all directions */ // x-axis bresenhamLine(-316, 0, 316, 0, 1.0f, 1.0f, 0.0f); // y-axis bresenhamLine(0, -316, 0, 316, 1.0f, 1.0f, 0.0f); // 1st octant bresenhamLine(0, 0, 100, 300, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, 230, 230, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, 300, 100, 1.0f, 1.0f, 0.0f); // 2nd octant bresenhamLine(0, 0, -100, 300, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, -230, 230, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, -300, 100, 1.0f, 1.0f, 0.0f); // 3rd octant bresenhamLine(0, 0, -100, -300, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, -230, -230, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, -300, -100, 1.0f, 1.0f, 0.0f); // 4th octant bresenhamLine(0, 0, 100, -300, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, 230, -230, 1.0f, 1.0f, 0.0f); bresenhamLine(0, 0, 300, -100, 1.0f, 1.0f, 0.0f); glutSwapBuffers(); }