Results 1 to 8 of 8

Thread: Roundoff error in moving picture boxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    18

    Roundoff error in moving picture boxes

    When moving picture boxes in run time using either equations or discrete X,Y coordinates, my picture boxes are not going exactly where they should go, but are rather quite visually off (they look sloppy). And not just a little bit, but off by 20 to 30 in screen units.

    All variables are set to the "single" type. There couldn't be THAT much roundoff error! Does anyone know what gives here?

  2. #2
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    hi
    Ur picture boxes will be positioned at the nearest pixel calculated from the twipsperpixel[x or y] property. So, the easiest way to ensure that ur boxes line up is to calculate each value divided by the t-per-p property and round appropriately.

    The Single data type wont cos a prob with the X & Y positions but it can be inaccurate if u are using singles for dividing / multiplying in formulae before u position the controls - u can use doubles instead.
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  3. #3
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    You could also be having some problem with the ScaleMode... remember to always set it to 3 - Pixels
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    18

    Question

    Beachbum....thank you for your reply. How do you use TwipsPerPixelY and TwipsPerPixelX? None of any of the objects (the form, picture boxes, etc.) have such a property. MSDN help says to use the command "object.TwipsPerPixelX" (or Y) to determine "the number of twips per pixel" for any given object. However, use of such a command returns the runtime error, "Compile Error: Method or data member not found."

  5. #5
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    Hi again
    use the screen object ie screen.twipsperpixelX (Y)
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    18
    beachbum and Jotaf98,

    Thank you for your help so far. O.k., the commands

    screen.TwipsPerPixelY
    screen.TwipsPerPixelX

    return 15 each.

    So now I'm quite confused. Here's some math:

    My screen width is about 18 inches, at a screen resolution of 1280 x 1024. That's 1280/18 = 71 pixels per inch.

    And twips are about 1440 per 'logical' inch.

    1440/71 = 20 ...which is 'about' 15 (close enough)

    So.............if Twips are FINER than pixels, then what good does it do to change the scalemode to Pixels? And if there's a +/- one or two Twips round-off error, how could that cause picture boxes to be placed so poorly (they don't line up, look sloppy)? Am I just totally confused here?

    Thanks tons

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Well, I don't know why they use twips anyway - because a pixel is the smallest position you'll ever be able to use in your computer (unless you use anti-aliasing techniques, but the only place where you'd use them would be in a painting program)

    When using pixels you're using the same scale your screen uses. So if you move something 1 pixel to the left, you'll know it moves exactly the smallest possible unit on the screen. If you move like 4 twips to the left (less than a pixel), it won't move at all.

    Hope that clears everything
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    18

    It worked great!

    Thank you Jotaf98 and beachbum...your super advice and informed suggestestions worked perfectly! For whatever, bizarre reason, changing scalemode to 3 (pixel) instead of the much-finer unit of Twips fixed the problem!

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