Help me with graphic functions! :(

This is a discussion on Help me with graphic functions! :( within the C Programming forums, part of the General Programming Boards category; Hello, i've created a simple program which uses setviewport to set the viewport in which we specify the top left ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    Help me with graphic functions! :(

    Hello,

    i've created a simple program which uses setviewport to set the viewport in which we specify the top left and bottom right corner and it considers top left corner as 0,0. The code for this is :-


    Code:
    #include <stdio.h>
    #include <graphics.h>
    #include <stdlib.h>
    
    int main(void)
    {
     int gd=DETECT,gm,errorcode;
     int xorigin,yorigin;
     initgraph(&gd,&gm,"c:\\tc\\bgi");
     errorcode=graphresult();
     if(errorcode!=grOk)
     {
           printf("%s",grapherrormsg(errorcode));
           exit(1);
     }
     xorigin=getmaxx()/2;
     yorigin=getmaxy()/2;
     line(xorigin,0,xorigin,getmaxy());
     line(0,yorigin,getmaxx(),yorigin);
     setviewport(xorigin,0,getmaxx(),yorigin,0);
     line(0,0,100,100);
    
     return 0;
    }

    Now my problem is that if i want to consider xorigin and yorigin as 0,0 and want to treat the screen as though i am drawing on graph paper i mean the co-ordinates increases as we go top right(X increases in right direction and Y increases in top direction). Then how shall i do it???

    Best Regards,
    Chotti.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    If Turbo Cad won't let you reassign the origin to the bottom left corner, then I suspect you'll just have to figure out how to draw with the origin at the top left.

    An alternative would be for you to create a wrapper function, so that in your program, you draw as if the origin was at the bottom left corner, but your wrapper function recalculates the coordinates to draw from the upper left.

    Todd
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    In VC++ i know that you can set the viewport origin! but with C i am not so aware . If anybody knows any standard function then please tell me

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It appears that changing the viewport in BGI is only changing the rectangle that you draw to, not the coordinate system.

    http://www.cs.colorado.edu/~main/cs1...tviewport.html

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    So you know any function on how to change the co-ordinate system?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by chottachatri View Post
    So you know any function on how to change the co-ordinate system?
    No, there doesn't seem to be anything to do that.

    You'd have to wrap all your functions with a wrapper that translates the coordinates.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  2. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  3. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM
  4. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 08:53 AM

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