Pen circle drawing revisited

This commit is contained in:
James Turk 2005-08-23 21:55:03 +00:00
parent 2d8ba79bf0
commit ab008b050f
3 changed files with 28 additions and 59 deletions

View File

@ -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.

View File

@ -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;
};
}

View File

@ -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<CIRCLE_RESOLUTION; ++i)
{
glVertex2d(cx+x,cy+y);
glVertex2d(cx+x,cy-y);
glVertex2d(cx-x,cy+y);
glVertex2d(cx-x,cy-y);
glVertex2d(cx+y,cy+x);
glVertex2d(cx+y,cy-x);
glVertex2d(cx-y,cy+x);
glVertex2d(cx-y,cy-x);
if(d < 0)
{
d += x*4 + 6;
}
else
{
d += (x-y)*4 + 10;
--y;
}
++x;
glVertex2f(cx+radius*std::cos(angle), cy+radius*std::sin(angle));
angle += angleStep;
}
glEnd();
glPopAttrib();
@ -165,39 +147,21 @@ void Pen::drawCircle(const math::Circle &circle) const
void Pen::fillCircle(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_LINES); // draw lines instead of points, filling the circle
while(y > x)
glBegin(GL_POLYGON);
for(int i=0; i<CIRCLE_RESOLUTION; ++i)
{
glVertex2d(cx+x,cy+y);
glVertex2d(cx+x,cy-y);
glVertex2d(cx-x,cy-y);
glVertex2d(cx-x,cy+y);
glVertex2d(cx+y,cy+x);
glVertex2d(cx-y,cy+x);
glVertex2d(cx-y,cy-x);
glVertex2d(cx+y,cy-x);
if(d < 0)
{
d += x*4 + 6;
}
else
{
d += (x-y)*4 + 10;
--y;
}
++x;
glVertex2f(cx+radius*std::cos(angle), cy+radius*std::sin(angle));
angle += angleStep;
}
glEnd();
glPopAttrib();