The following snippet establishes units as an abstract measurement of how large a singular instance of space is, inside of your game world. These units can then be converted to or from imperial measurements such as miles or feet; or metric measurements such as meters and centimeters. (spelled metres and centimetres respectively in UK English, abbreviated as 'm' and 'cm')
You must establish how large your game units are in correlation to the scale of surroundings in your world; to do so you must call the SetWorldScale function with how many meters your units represent; for example; 10 would mean that for every unit in your game, each unit represents 10m. If you specify 0.01, for each unit in your game, each unit would represent 1cm.
Use the functions prefixed with the preposition; 'To'; in order to convert FROM a metric or imperial measurement INTO your gaming units.
Use the functions prefixed with the preposition; 'In'; so that you may return a conversion FROM gaming units INTO metric or imperial measurements.
Sorry it this system does not support lightyears or nanometers; my apologise for any inconvenience this may cause!
// Chris Tate : chris.tate@binarymodular.com
//==================================================
Function SetWorldScale(fWorldUnitsPerMetre#)
If fWorldUnitsPerMetre# < 0.000001 Then fWorldUnitsPerMetre# = 0.000001
Global WorldScaleMultiplier# : WorldScaleMultiplier# = 1.0 / fWorldUnitsPerMetre#
Global WorldScale# : WorldScale# = fWorldUnitsPerMetre# * 100.0
Global WorldScaleRatio# : WorldScaleRatio# = fWorldUnitsPerMetre#
Global WorldMetresPerUnit# : WorldMetresPerUnit# = fWorldUnitsPerMetre#
Global WorldKMPerUnit# : WorldKMPerUnit# = fWorldUnitsPerMetre# / 0.001
Global WorldCMPerUnit# : WorldCMPerUnit# = fWorldUnitsPerMetre# / 100.0
Global WorldMMPerUnit# : WorldMMPerUnit# = fWorldUnitsPerMetre# / 1000.0
// Would it not have been lovely to assign and initialise in the same command!
EndFunction
//==================================================
Function ToCM(fNumberOfCentimetres#)
Local f#
f# = fNumberOfCentimetres# * WorldCMPerUnit#
EndFunction f#
//==================================================
Function InCM(fUnits#)
Local f#
f# = fUnits# / WorldCMPerUnit#
EndFunction f#
//==================================================
Function ToMM(fNumberOfMM#)
Local f#
f# = fNumberOfMM# * WorldMMPerUnit#
EndFunction f#
//==================================================
Function InMM(fUnits#)
Local f#
f# = fUnits# / WorldMMPerUnit#
EndFunction f#
//==================================================
Function ToMetres(fNumberOfMeters#)
Local f#
f# = fNumberOfMeters# * WorldMetresPerUnit#
EndFunction f#
//==================================================
Function ToMeters(fNumberOfMeters#)
Local f#
f# = fNumberOfMeters# * WorldMetresPerUnit#
EndFunction f#
//==================================================
Function InMeters(fUnits#)
Local f#
f# = Div#(fUnits#, WorldMetresPerUnit#)
EndFunction f#
//==================================================
Function InMetres(fUnits#)
Local f#
f# = fUnits# / WorldMetresPerUnit#
EndFunction f#
//==================================================
Function ToFeet(fNumberOfFeet#)
Local f#
f# = 0.3048 * fNumberOfFeet#
f# = f# * WorldMetresPerUnit#
EndFunction f#
//==================================================
Function InFeet(fUnits#)
Local f#
f# = 0.3048 * fUnits#
f# = f# / WorldMetresPerUnit#
EndFunction f#
//==================================================
Function ToYards(fNumberOfYards#)
Local f#
f# = 0.9144 * fNumberOfYards#
f# = f# * WorldMetresPerUnit#
EndFunction f#
//==================================================
Function InYards(fUnits#)
Local f#
f# = 0.9144 * fUnits#
f# = f# / WorldMetresPerUnit#
EndFunction f#
//==================================================
Function ToInches(fNumberOfInches#)
Local f#
f# = 0.0254 * fNumberOfInches#
f# = f# * WorldMetresPerUnit#
EndFunction f#
//==================================================
Function InInches(fUnits#)
f# = 0.0254 * fUnits#
f# = f# / WorldMetresPerUnit#
EndFunction f#
//==================================================
Function ToKM(fNumberOfKM#)
Local f#
f# = fNumberOfKM# * WorldKMPerUnit#
EndFunction f#
//==================================================
Function InKM(fUnits#)
Local f#
f# = fUnits# / WorldKMPerUnit#
EndFunction f#