I am new to C++ and attempting to put together my first Windows App.
I am using Visual Studio 2008 C++ Edition with Windows 7.
I have written a procedure which is called by WndProc using this statement:-
void DrawArc(HDC hdc, double x,double y,double r,double s,double e, COLORREF colour);
As the procedure is a modified procedure for drawing circles:-
hdc is the active window
x and y are the co-ordinates of the circle centre
r is the circle radius
s and e are the start and end of the arc
colour is the arc colour
The actual calling command is
DrawArc(hdc,700.0,85.0,50.0,0.0,90.0,Yellow); which
gives :-
x a value of 700.00
y a value of 85.00
s a value of 0 degrees
e a value of 90 degrees
colour the COLORREF value for yellow
The procedure first of all calculates the x and y co-ordinates for all the points on the circle and stores them in an array.
It then cycles through all the degrees but when it reaches the degrees bounded by the start and end of the arc it draws a line from each point to the centre forming the arc using the details in the array.
At present it is set up to draw an arc between 0 degrees at the top of the circle to 90 degrees in the 3 o'clock position but it actually draws the arc between 90 degrees and 180 degrees from the 3 o'clock position to the 6 o'clock position.I do not understand why this is.Here is the code I am using:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
void DrawArc(HDC hdc, double x, double y,double r,double s, double e, COLORREF colour)
{
// Initialise variables
HPEN hPenOld;
// declare hLinePen pen name
HPEN hLinePen;
// declare qLineColor as pen ink
COLORREF qLineColor;
// set qLineColor to desired parameter colour
qLineColor=colour;
// create pen with desired colour
hLinePen = CreatePen(PS_SOLID, 2, qLineColor);
// select desired pen
hPenOld = (HPEN)SelectObject(hdc, hLinePen);
// declare circle points array variables
double xcoords[360];
double ycoords[360];
// declare circle centre co-ordinates variables
double d_centre_x;
double d_centre_y;
// declare radius
double radius;
// declare start of arc
double start_arc;
// declare end of arc
double end_arc;
// declare degree
double degree;
// declare degrees to radians
double deg_to_rads;
// initialise deg_to_rad
deg_to_rads=0.0174532925;
// declare radians to degrees
double rads_to_deg;
//initialise rads_to_deg
rads_to_deg=57.2957795;
// declare int version of circle point co-ordinates
int px;
int py;
// declare int version of circle centre co-ordinates
int cx;
int cy;
//declare int version of arc start point and end point
int start;
int end;
// import parameters into variables
d_centre_x=x;
d_centre_y=y;
radius=r;
start_arc=s;
end_arc=e;
// declare int version of circle centre x & y co-ordinates
cx=(int)d_centre_x;
cy=(int)d_centre_y;
// declare int version of arc start and end
start=(int)start_arc;
end=(int)end_arc;
// declare ctr counter variables
int ctr;
int ctr1;
// set up loop to calculate circle points
for(ctr=1;ctr<360;ctr++)
{
degree=ctr*deg_to_rads;
xcoords[ctr]=d_centre_x+(radius*cos(degree));
ycoords[ctr]=d_centre_y+(radius*sin(degree));
px=(int)xcoords[ctr];
py=(int)ycoords[ctr];
}
// set up loop to draw arc
for(ctr1 = 1;ctr1<360;ctr1++)
{
if(ctr1>=start && ctr1<=end)
{
cx=(int)d_centre_x;
cy=(int)d_centre_y;
px=(int)xcoords[ctr1];
py=(int)ycoords[ctr1];
MoveToEx(hdc,px,py,NULL);
LineTo(hdc,cx,cy);
}
}
// delete pen after use
DeleteObject(hLinePen);
}
|
Perhaps someone can spot what I am doing wrong. Any information would be greatly appreciated please.TIA.