From ab008b050fa7f56f1273b1b3dd3e16d4dcff5902 Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 23 Aug 2005 21:55:03 +0000 Subject: [PATCH] Pen circle drawing revisited --- CHANGELOG.txt | 4 ++- include/video/Pen.hpp | 5 ++- src/video/Pen.cpp | 78 ++++++++++++------------------------------- 3 files changed, 28 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 32659c8..320412a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,10 +1,12 @@ Changelog for Photon -$Id: CHANGELOG.txt,v 1.11 2005/08/18 07:05:34 cozman Exp $ +$Id: CHANGELOG.txt,v 1.12 2005/08/23 21:55:03 cozman Exp $ ! : Major Changes (potentially breaking existing code) + : New Features * : Minor Changes (bugfixes and behind-the-scenes changes) +0.1.0 + * Rewrote circle drawing code in Pen, major speed up. 0.0.2 - Released 2005-18-08 ! Removed InputListener, opting to move features into State class. diff --git a/include/video/Pen.hpp b/include/video/Pen.hpp index aee11a4..1707702 100644 --- a/include/video/Pen.hpp +++ b/include/video/Pen.hpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Pen.hpp,v 1.3 2005/07/20 03:58:54 cozman Exp $ +// $Id: Pen.hpp,v 1.4 2005/08/23 21:55:03 cozman Exp $ #ifndef PHOTON_VIDEO_PEN_HPP #define PHOTON_VIDEO_PEN_HPP @@ -134,6 +134,9 @@ public: // data members private: Color color_; + + // 30 seems to be an even tradeoff between speed and roundness + static const int CIRCLE_RESOLUTION = 30; }; } diff --git a/src/video/Pen.cpp b/src/video/Pen.cpp index ded5063..2a20ebb 100644 --- a/src/video/Pen.cpp +++ b/src/video/Pen.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Pen.cpp,v 1.5 2005/07/20 03:58:54 cozman Exp $ +// $Id: Pen.cpp,v 1.6 2005/08/23 21:55:03 cozman Exp $ #include "video/Pen.hpp" @@ -125,39 +125,21 @@ void Pen::fillRect(const math::Rect &rect) const void Pen::drawCircle(const math::Circle &circle) const { - //written from Bresenham's circle algorithm - double cx(circle.getCenter().x); - double cy(circle.getCenter().y); - double d(3-(2*circle.getRadius())); - double x(0); - double y(circle.getRadius()); - + scalar radius(circle.getRadius()); + scalar cx(circle.getCenter().x); + scalar cy(circle.getCenter().y); + scalar angle(0); + const scalar angleStep(2*math::PI/CIRCLE_RESOLUTION); + glBindTexture(GL_TEXTURE_2D,0); glPushAttrib(GL_CURRENT_BIT); color_.makeGLColor(); - glBegin(GL_POINTS); // draw points, creating a circle - while(y > x) + glBegin(GL_LINE_LOOP); + for(int i=0; i x) + + glBegin(GL_POLYGON); + for(int i=0; i