Skip to main content
gamedev.net
🔒 Locked

Drawing Circle

Started by Graham 2 replies 300+ views
Original Post
Graham
Graham
Using DX8, what is an easy way to draw a circle with a given position and radius. Is there a function for this? Go on an Intense Rampage
Go on an Intense Rampage
YoshiN
YoshiN
Here is psuedo-code for drawing a circle using trigonometry:

for(theta=0; theta<2PI; theta++)
{
run = radius * cos(theta) + xCenter;
rise = radius * sin(theta) + yCenter;
PlotPixel(run, rise);
}

theta is the angle (in radians) of the current position on the circumference of the circle, run is the x coordinate of the current position and rise is the y coordinate. xCenter and yCenter are the coordinates of the center of the circle. The rest should be pretty self-explainatory.

Keep in mind however, that since this is using integers (theta++) unless you are drawing a really small circle the circumference is not going to be connected - it will be a dotted outline for the circle. A bad way of fixing this (as in slow, although I''ve tested it and lost around 1-3fps with it) is to using floating point numbers instead of integers, and have something like theta+=.01 (you''d have to play around with it a little to get a good addition factor), and you can also loop more (theta<4PI) although that will only work if you are using floating points as well (otherwise you''ll just draw pixels over previous pixels). I''m sure someone can come up with some good optimizing techniques (maybe fixed-point math and look-up tables or some version of brensenhams algorithm?) but that''s the basics of it.
-YoshiXGXCX ''99
Graham
Graham
I understand what you are saying, but i was wondering if there was a dx function that did this for you. I think it can be done in GDI, so i assumed you could in dx.
Go on an Intense Rampage

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.