Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSimonForsman

Posted 15 April 2013 - 03:32 AM

 

edit: I'm not really sure what you mean by screen size in your post. I'm assuming the physical screen size and/or screen resolution in my reply
The big secret to keeping a constant size of stuff on the screen is adapting your code to current DPI (dots per inch). Unfortunately, if you're on Windows (a blind assumption here), you cannot rely on built-in DPI functionality to give you accurate DPI measurements (I found absolutely no correlation between the generic 96 dpi returned by Windows and reality). Therefore the only tuly reliable way is to query the physical dimensions of the screen, eg in millimeters (you can do that in any OS, but it's most involved in Windows*) and divide them by the current resolution to get PPI (points/pixels per inch). You can then use this to scale your object to a device-inpendent constant size on any display at any resolution.
 
* I know of exactly one instance of someone having come up with the code to get the physical display size in millimeters on Windows (link above) and that's more than a  hundred lines of code

 
I think he is just talking about resolution and that he is making objects larger and placing them further apart when the resolution is increased(so that things look roughly the same). Thus objects that are 100px from eachother at 640x480 becomes 200px from eachother at 1280x920 which causes his magnetism force to be weaker.
 
The solution, as always is to separate rendering and logic.
Always run the logic at a fixed resolution (He doesn't have to measure distances in pixels then either)

I am not sure how to do this....meaning separate the two, as box2d is where I get the objects positions from....

 

scale your positions etc to suit the current resolution after you get them from box2d, not before you give them to box2d.

 

If you use a 3D API and orthographic projection you can simply set the projection matrix based on the box2d resolution rather than the screen resolution.


#1SimonForsman

Posted 15 April 2013 - 03:26 AM

 

edit: I'm not really sure what you mean by screen size in your post. I'm assuming the physical screen size and/or screen resolution in my reply
The big secret to keeping a constant size of stuff on the screen is adapting your code to current DPI (dots per inch). Unfortunately, if you're on Windows (a blind assumption here), you cannot rely on built-in DPI functionality to give you accurate DPI measurements (I found absolutely no correlation between the generic 96 dpi returned by Windows and reality). Therefore the only tuly reliable way is to query the physical dimensions of the screen, eg in millimeters (you can do that in any OS, but it's most involved in Windows*) and divide them by the current resolution to get PPI (points/pixels per inch). You can then use this to scale your object to a device-inpendent constant size on any display at any resolution.
 
* I know of exactly one instance of someone having come up with the code to get the physical display size in millimeters on Windows (link above) and that's more than a  hundred lines of code

 
I think he is just talking about resolution and that he is making objects larger and placing them further apart when the resolution is increased(so that things look roughly the same). Thus objects that are 100px from eachother at 640x480 becomes 200px from eachother at 1280x920 which causes his magnetism force to be weaker.
 
The solution, as always is to separate rendering and logic.
Always run the logic at a fixed resolution (He doesn't have to measure distances in pixels then either)

I am not sure how to do this....meaning separate the two, as box2d is where I get the objects positions from....

 

scale your positions etc to suit the current resolution after you get them from box2d, not before you give them to box2d.


PARTNERS