Handmade Hero»Forums»Code
Eric Thompson
4 posts
Meters To Pixels Conversion
Hello!

I was just reviewing the Handmade Hero code and came across something that has me confused. If you take a look at handmade_world_mode.cpp (line 682), you will notice a conversion multiplier for MetersToPixels based on the estimated width of the monitor in meters.

real32 WidthOfMonitor = 0.635f; // NOTE(casey): Horizontal measurement of monitor in meters
real32 MetersToPixels = (real32)DrawBuffer->Width*WidthOfMonitor;

It seems that the MetersToPixels calc should actually be the following (assuming we will ignore division by zero protection using SafeRatio):

real32 MetersToPixels = (real32)DrawBuffer->Width / WidthOfMonitor;

Example:
1 meter * ( 1920 pixels / .635 meters ) = 3,023.622 pixels

Whereas the current calculation results in:
1 meter * 1920 pixels * .635 meters = 1,219.2 meters-pixels (units are not cancelling)

I believe the perspective projection works in the current code base because we have the DistanceAboveGround at 9.0f. If you make the above correction, you will need to adjust this to between 20.0f and 25.0f in order to achieve the similar results to the current setup.

Regards
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Meters To Pixels Conversion
Yep, it's awaiting future work:

https://hero.handmadedev.org/foru...972-meters-to-pixels-day-110#5394

- Casey
Eric Thompson
4 posts
Meters To Pixels Conversion
Sorry about that. Should have searched the forums more thoroughly.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Meters To Pixels Conversion
No worries! Always better to have a bug found twice than to not have it found at all :)

- Casey