Originally posted by: James P
Your code is quite ok.But can't you make it more powerful
ReplyOriginally posted by: Craig Moore
I think that it may have been useful to post the fact that you wish to draw n-sided <i>regular</i> polygons, as surely there are scanline rendering algorithsm for drawing polygons already. Also, it may have been useful to post an algorithm for scanlining solid polygons, as they are more useful imho.
ReplyOriginally posted by: John
void DrawPoly( double x, double y, double Radius, double Angle,
double Delta = (2*3.14159265) / Sides;
for ( int i = 0; i < Sides; i++ )
nx = x + ( Radius * cos( Angle + i * Delta ) );
if ( !i )
I left out the details of setting pen/brush colors, and I
-John
PS: Editing code in this browser window sucks. :-)
A better approach might be to have a general n-sided
polygon drawing function, such as:
int Sides, COLORREF Color )
{
// set the pen and fill colors as needed
// ...
// ...
{
double nx, ny;
ny = y + ( Radius * sin( Angle + i * Delta ) );
MoveTo( (int)(x + Radius), (int)y );
else
LineTo( (int)nx, (int)ny );
}
}
glossed over the actual drawing stuff, but the idea is to
create the function and call it from inside the OnMouseMove
code. That way, your code is much cleaner, and you can
create n sided poly's from anywhere without having to
copy/paste all over the place.
Remember, C and C++ allow us to create functions which
should be as reusable as possible. Less code means easier
debugging and usually more efficient operation.
Good luck!
Reply
Originally posted by: ambrish
thats a nice and interesting article.
give a lot of insight.
Originally posted by: rohil sahgal
i think mayank malik is one of the most talented programmers i've met and this is only a sample of what he can do....i've known him for the last 4 yrs and he's as good a person as he is a programmer!! if anybody out there is looking for a dedicated, talented and brilliant software programmer..look no further for he's ur man :)
ensoi and keep the faith
Originally posted by: Charles Vaz
Try changing the sides to 20 and see noticable effects due to integer rounding errors.
Anyways, not bad I'd say.