CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2013
    Posts
    32

    MFC's Coordinate System?

    Hello,

    I am drawing in a simple (square) MFC window. I realize that (0,0) starts in the upper left hand corner. I wanted to see how MFC handled drawing of angles, so I use this code:

    Code:
    double CompassDegreesToRadians(double compassDegrees)
    {
    	return((PI / 2.0f) - (compassDegrees * PI / 180.0f));
    }
    
    // Make pen
    CPen penRed;
    penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0));
    
    // Test Angles
    CRect rectClient;
    GetClientRect(rectClient);
    float angle1 = 0;
    int radius = rectClient.CenterPoint().x;
    int x1 = radius * cos(CompassDegreesToRadians(angle1));
    int y1 = radius * sin(CompassDegreesToRadians(angle1));
    dc.MoveTo(rectClient.CenterPoint());
    dc.LineTo(x1, y1);
    Using this code, and changing the value of angle1 to these values (0, 90, 180, 270) I think MFC uses the coordinate system:

    Code:
                 180 -y
                  |
                  |
      -x 270---------------- 90 +x
                  |
                  |
                  0 +y
    This seems like a strange coordinate system to use. Am I doing something wrong? If this is correct, how can I convert my calculations to this coordinate system? (compass degrees):

    Code:
                   0 +y
                   |
                   |
      -x 270---------------- 90 +x
                   |
                   |
                  180 -y
    Last edited by clow; October 11th, 2013 at 04:38 PM.

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: MFC's Coordinate System?

    If you do not like this coordinate system, change your mapping mode from MM_TEXT to something like MM_HIMETRIC (or MM_HIENGLISH).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    Jun 2013
    Posts
    32

    Re: MFC's Coordinate System?

    Hello,

    Yeah I saw those functions, and tried MM_LOENGLISH, but when I did that, nothing appeared on the screen. How would I calculate the coordinate system transform by normal C++ code between the two systems I listed above?

    Thanks!

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: MFC's Coordinate System?

    Or just have resultant y1 coordinate multiplied by -1.
    Best regards,
    Igor

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: MFC's Coordinate System?

    Quote Originally Posted by clow View Post
    ...tried MM_LOENGLISH, but when I did that, nothing appeared on the screen.
    With those mapping modes, your (0,0) point is in the LOWER-LEFT corner of the window, X grows to the right and Y - up.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured