2

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

            }
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • 1
    I do not see any `cin>>` nor `scanf` so where are you inputing the values ? This is MS-DOS or Windows or linux (just to make clear if you are in emulation or not and what capabilities you got at disposal)? also you use BGI or WinBGI or different BGI lib ? Also the if looks out of place as you got function end before it so it is not its part ...assuming it is in `main()` ... – Spektre Apr 26 '17 at 08:04
  • I did find out another way to deal with my problem. Thanks for your answer. Much appreciated – Nhân Phạm May 24 '17 at 15:42

0 Answers0