I'm writing a C++ graphic program. I need to translate, scale and rotate this rhombus shape (as well as other shapes). I want to write a function to do that but I've not figured out how to pass x1, y1, x2, y2 from the mouse inputs(or keyboard inputs) to the new transformation function I want to write.
I want to draw a shape on BGI screen, then click the 'translate' button, then enter some variables and the shape transforms.
FYI, I use BGI to do the graphics. Some shapes I draw with mouse inputs, some with keyboard inputs.
Here is my code:
void drawRhombus (int x1, int y1, int x2, int y2)
{
int x3 = x2 + (x2 - x1);
int y3 = y1;
int x4 = x2;
int y4 = y1 + (y1 - y2);
lineBresenham(x1, y1, x2, y2);
lineBresenham(x2, y2, x3, y3);
lineBresenham(x3, y3, x4, y4);
lineBresenham(x4, y4, x1, y1);
}
if (LOWORD(wParam) == 9) {
cout<<"Draw Rhombus"<<endl;
int x1, y1, x2, y2 = 0;
int count = 0;
coordinateLines();
while(1)
{
delay (0.0001);
if (ismouseclick(WM_LBUTTONDOWN))
{
getmouseclick(WM_LBUTTONDOWN, x1, y1);
cout<<"A("<<setXMachine2User(x1)<<","<<setYMachine2User(y1)<<")\n";
putpixel(x1,y1,color);
count++;
}
if (count == 1)
{
if (ismouseclick(WM_LBUTTONUP))
{
getmouseclick(WM_LBUTTONUP, x2, y2);
cout<<"B("<<setXMachine2User(x2)<<","<<setYMachine2User(y2)<<")\n";
drawRhombus(x1, y1, x2, y2);
cout<<"-------------------------------"<<endl;
count++;
}
}
if (count == 2)
{
count = 0;
}
}
}