Thread: drawing using relative coordinates

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    596

    drawing using relative coordinates

    Are there functions to draw using relative coordinates (relative to some starting point), as opposed to drawing to absolute coordinates?

    Specifically, I need to draw an unfilled rectangle (frame) of fixed size at various positions.

    I know how to draw them with absolute coordinates, just seems like there ought to be relative
    versions.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I believe the solution is called a "variable".
    Code:
    new_origin_x = 50;
    new_origin_y = 25;
    Function_That_Draws(new_origin_x+10, new_origin_y+20);
    Perhaps more seriously, since this is the Windows board, there are the coordinate systems Windows knows about: Types of Coordinate Systems (Windows)

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Thanks for the coordinate system link.

    I realize that I can add the relative values to an absolute origin; that is what I am doing now.

    I am wondering if there are functions where the origin is specified as absolutes, and the other
    coordinates are relative to that origin.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Normally that's handled using transformations. I have no idea what you are actually using, but a search on transformations at MSDN got me Global and Local Transformations (Windows)

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Thanks again, but what I am wondering is something simpler. Also I am using only C, not C++.

    For example, if I need a 20x20 square at location 500, 600, I would like to use:

    x = 500, y = 600, rectangle(x, y, 20, 20),

    not x = 500, y = 600, rectangle(x, y, x+20, y+20)

    Of course, either I have to do the math or the function has to do the math, but the code is neater
    if a function already handles the math.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Look at SetViewportOrgEx and SetWindowOrgEx

    The GDI Mapping Mode
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Thanks, all, for the info.

    I can definitely use it, although it's not quite related to my question.

    The msdn reference can be overwhelming and I can never be sure I've seen everything. It looks
    like there are no relative drawing functions of the type I was wondering about.

    No problem though. Can do things as I have been, it just would have been convenient.

  8. #8
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Quote Originally Posted by megafiddle View Post
    Can do things as I have been, it just would have been convenient.
    Or you could just write your own functions...

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by megafiddle View Post
    I can definitely use it, although it's not quite related to my question.
    Prahaps you could rephrase your question then.

    >> I need to draw an unfilled rectangle (frame) of fixed size at various positions.
    Call SetViewportOrgEx() with the top left of the rectangle and then call FillRect() or Rectangle() with a rect 0, 0, width, height
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Well yes, but my current method is still simpler:

    rectangle(x, y, x+20, y+20);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Force relative paths
    By aydinh in forum C Programming
    Replies: 3
    Last Post: 01-13-2011, 11:43 AM
  2. Prompt \w gives relative path
    By vkaushal21 in forum Linux Programming
    Replies: 2
    Last Post: 09-25-2009, 01:09 PM
  3. How to get relative mouse coordinates when GLUT return absolute
    By joeprogrammer in forum Game Programming
    Replies: 14
    Last Post: 02-10-2009, 06:35 PM
  4. using relative file paths..?
    By anomaly in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2003, 03:36 PM
  5. Relative positioning
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 05-14-2002, 12:00 AM