Ballistic curve

My program should draw rectangles shaping a ballistic curve without air resistance but the window staies black without any rectangle at any place.

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
 
case WM_PAINT:
          PAINTSTRUCT ps;
          float Reichweite=0;
          float velocity=1000;
          float g=9.81;
          float winkel=45;
          float posx=0;
          float posy=0;
          float t=1;
          int  x=0;
          int y=600;
          int x1;
          int y1;
          hDC=GetDC(hwnd);
          hDC = BeginPaint (hwnd,&ps);
            Reichweite=((velocity*velocity)/g)*sin(2*winkel);
             while (x<=Reichweite)
              {   
              t=t+1;
              posx=(velocity*t)*cos(winkel);
              posy=(velocity*t)*cos(winkel)-((g/2)*(t*t));
              x=(int)posx;
              y=(int)posy;
              x1=x+20;
              y1=y+20;
              SelectObject(hDC,PenRed);
              Rectangle(hDC,x,y,x1,y1);
             }
          
          EndPaint(hwnd,&ps);
          return 0;
          break;


Thank you for help
Are you erasing the background? What color are you using for background? Also the call to GetDC() is not needed AND incorrect.

What's the size of the client area? Have you made sure that the rectangles are visible. You seem to have hardcoded some values that may calculate rectangles that are outside of the client area. Did you check the values so you get rectangles in the visible portion of the window?

Also you are calling SelectObject() multiple times inside the while() loop. I don't know how bad is this, but at the very least is unnecessary. Move the SelectObject() call outside the loop so it is called only once. If you don't own the DC (which I suppose you don't), you should be saving the previous pen in order to restore it before the call to EndPaint().
Topic archived. No new replies allowed.