OxMath Module
This module provides common constants and global objects that can be accessed throughout a project. The kReleaseBuildErrorChecking constant and ErrorLogger property can be used to modify how and when error checking occurs and where error messages are logged. Error logging is minimal, but can help track down otherwise difficult to find bugs such as divide-by-zero situations and degenerate bounding volumes.
Note: All constants, properties, and methods listed below have public scope and must be prefixed with the OxMath namespace and dot notation.
Constants
Expand All | Collapse All
-
kDegToRad = 0.01745329251994
A multiplier to convert degree units into radians. Example:
' Convert 90 Degrees to radians radians = 90.0*OxMath.kDegToRad
-
kEpsilon = 0.000001
A small numerical value commonly used to account for floating point errors. OxMath.kEpsilonCoarse may be more appropriate depending on the magnitude of the numbers being compared. -
kEpsilonCoarse = 0.001
A small numerical value commonly used to account for floating point errors. OxMath.kEpsilon may be more appropriate depending on the magnitude of the numbers being compared. -
kMicrosecondsToMilliseconds = 0.001
A multiplier to convert microseconds to milliseconds. This would commonly be used in combination with values obtained with REALbasic's built-in Microseconds function. Example:
' Convert uptime to milliseconds ms = Microseconds*OxMath.kMicrosecondsToMilliseconds
-
kMicrosecondsToSeconds = 0.000001
A multiplier to convert microseconds to seconds. This would commonly be used in combination with values obtained with REALbasic's built-in Microseconds function. Example:
' Convert uptime to seconds sec = Microseconds*OxMath.kMicrosecondsToSeconds
-
kOneMinusEpsilon = 0.999999
Inlined shortcut for:1.0-OxMath.kEpsilon
-
kOneMinusEpsilonCoarse = 0.999
Inlined shortcut for:1.0-OxMath.kEpsilonCoarse
-
kOneOverPi = 0.31830988618
Inlined shortcut for:1.0/OxMath.kPi
-
kOnePlusEpsilon = 1.000001
Inlined shortcut for:1.0+OxMath.kEpsilon
-
kOnePlusEpsilonCoarse = 1.001
Inlined shortcut for:1.0+OxMath.kEpsilonCoarse
-
kPi = 3.14159265358979
The value of π (Pi) to fourteen decimal places. -
kPiByTwo = 6.28318530717958
Inlined shortcut for:OxMath.kPi*2.0
-
kPiOverTwo = 1.5707963267949
Inlined shortcut for:OxMath.kPi/2.0
-
kRadToDeg = 57.2957795130824
A multiplier to convert radian units into degrees. Example:
' Convert Pi radians to degrees degrees = OxMath.kPi*OxMath.kRadToDeg
-
kReleaseBuildErrorChecking = False
This constant can be set to True to enable error checking in release builds. This should only be done for special debugging-release builds as it can add significant overhead. Note that error checking is always enabled when running debug builds from the REALbasic IDE.
Properties
Expand All | Collapse All
-
ErrorLogger As OxMathErrorLogger
Assign a class that implements the OxMathErrorLogger interface to this property to have error messages routed to that instance. If this property is Nil (default) errors messages will be sent to System.Debuglog. Note that errors are only logged in debug builds or when the OxMath.kReleaseBuildErrorChecking constant is set to True. -
RandomGenerator As Random
Implements a singleton-style Random object. This instance can (and should) be assigned to a local variable for more efficient usage.
Important: Do not access this property if you are already using your own Random implementation. The REALbasic documentation discourages the creation of multiple Random objects. -
Vector3Forward As OxMVector3
The normalized forward-direction vector used for 3D transformations. The default value uses natural left-handed orientation, and defines +Z as the forward direction (0,0,1). Note that this vector object is read-only but remains mutable. The XYZ values can be modified directly for use with rotated or inverted systems. -
Vector3Origin As OxMVector3
The origin position vector used for 3D transformations. The default value is (0,0,0). Note that this vector object is read-only but remains mutable. The XYZ values can be modified directly when a transformed origin is required. -
Vector3Right As OxMVector3
The normalized right-direction vector used for 3D transformations. The default value uses natural left-handed orientation, and defines +X as the right direction (1,0,0). Note that this vector object is read-only but remains mutable. The XYZ values can be modified directly for use with rotated or inverted systems. -
Vector3Up As OxMVector3
The normalized up-direction vector used for 3D transformations. The default value uses natural left-handed orientation, and defines +Y as the up direction (0,1,0). Note that this vector object is read-only but remains mutable. The XYZ values can be modified directly for use with rotated or inverted systems.
Methods
Expand All | Collapse All
-
LogError ( error As String )
Mostly for internal use. Forwards error messages to OxMath.ErrorLogger or System.Debuglog as appropriate.