skeet flight angle problem

This is a discussion on skeet flight angle problem within the Game Programming forums, part of the General Programming Boards category; Hi, I'm still new at programming but can anyone help sort out an angle problem I'm having. I'm trying to ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Location
    Slovakia
    Posts
    21

    skeet flight angle problem

    Hi, I'm still new at programming but can anyone help sort out an angle problem I'm having. I'm trying to vary the launch angle of a skeet (ellipse) but the class is calculating the angle from coordinates (0,0) rather than from (520,350).

    I'm using codeblocks to program in.

    Code:
    #include <windows.h>
    #include <math.h>
    #define PI 3.14159265
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    int c;
    int d;
    int e;
    
    class position {
          int y;
         int a;
          public:
                 void set_values(int,int);
                double x() {return (y*tan(a*PI/180));}
                 };
    
    void position :: set_values(int b, int c){
         y=b;
         a= c;
         }
    // Windows build parameters
    
    RESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
            position pos1;
            position pos2;
            position pos3;
            HDC hdc;
            PAINTSTRUCT Ps;
    
        switch (message)                  /* handle the messages */
        {
               case WM_PAINT:
                hdc = BeginPaint(hwnd, &Ps);
                MoveToEx(hdc, 500, 350, NULL);
                  for (c=350; c>0; c--){
                  pos1.set_values(c,45);
                  d = (int)pos1.x();
                  LineTo(hdc,c,d);
                  }
                  for (c=350; c>0; c--){
                  pos2.set_values(c,50);
                  d = (int)pos2.x();
                  LineTo(hdc,c,d);
                    }
                  for (c=350; c>100; c--){
                  pos3.set_values(c,10);
                  d = (int)pos3.x();
                  LineTo(hdc,c,d);
                  EndPaint(hwnd, &Ps);
                  }
                  break;
    Can please someone help point me in the right direction?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Are you talking about your x() function? The formula you are using is the formula for the angle from (0,0), therefore you should be completely unsurprised that that's the result you're getting. If you want (520,350) to be the "origin", you need to do a translation by subtracting 520 from x and 350 from y to move that point to the origin.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Location
    Slovakia
    Posts
    21
    Sorry my mistake, wrong formula.

    Changed the formula to v*cos(angle)/time. a few adjustments here and there and it is working a treat now.

    Thanks for the tip about resetting the x point of origin though it helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  3. Steering Algorithm Problem
    By Warlax in forum Game Programming
    Replies: 2
    Last Post: 10-17-2006, 01:00 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21