Download

Quick speedometer calculation code review please!

Can someone verify my maths are correct for computing mph & kmph? I’m having a slow brain day :rolleyes:

// 1 uu = 1 cm
float SpeedPerSecondInUU = currentVelocity.Size2D(); // unreal units traveled per second
float SpeedPerHourInUU = SpeedPerSecondInUU * 3600;  // unreal units traveled per hour
float SpeedPerHourInKM = SpeedPerHourInUU / 100000; // 100000 cm = 1 km
float SpeedPerHourInMI = SpeedPerHourInUU / 160934; // 160934 cm = 1 mi

~Need more coffee~

Looks correct at 1st glance however you can probably get rid of 2 floats by just doing:

float SpeedPerHourInKM = currentVelocity.Size2D() * 3600 / 100000; // 100000 cm = kph
float SpeedPerHourInMI = currentVelocity.Size2D() * 3600 / 160934; // 160934 cm = mph

Thanks! Now I just need to work on the visual perspective and scenery to give the accurate notion of motion…

In regards to the probability of your recommendation, of course I could but to the compiler it’s all the same right? :rolleyes: