Open 3D Engine AzCore API Reference
24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
|
Functions which return a new copy of the object are prefixed with 'Get', functions which operate on the object in-place will omit the prefix. For example, Matrix3x3::GetTranspose() will return a new Matrix3x3 and leaves the original unchanged, whereas Matrix3x3::Transpose will transpose the matrix in-place.
We use the named constructor idiom instead of a regular constructor wherever possible. These are the static 'Create' methods found in all math types. Using named constructors avoids ambiguity, and makes the code more explicit by preventing the compiler from performing conversions 'behind your back'. (Declaring constructors as explicit goes some of the way towards this goal, but it still is not clear what the code 'Transform x = Transform(y)' is actually doing).
The standard way to transform a vector is to post-multiply the matrix by the column vector, i.e. column_vector = matrix * column_vector. This choice affects other math functions too, e.g. matrix-matrix multiplication order and the quaternion-vector multiplication formula. Matrices should be multiplied as follows:
Positive rotation direction is defined using the right-hand-rule. Nearly all functions will work with either left-handed or right-handed coordinates, but the few functions which don't (e.g. perspective matrix generation) use right-handed coordinates.
A little note about pre-multiplying vs. post-multiplying by vectors. There are two ways we can multiply a vector and a matrix:
Many architectures support estimate instructions, which can provide a low-cost low precision result for the requested operation. We use the suffix 'Estimate' to indicate when a raw estimate instruction is used.
A function without a suffix may use an approximation, but will have refine the estimate to provide decent accuracy.
Use the provided functions to convert math types to and from floats. E.g. Vector3::CreateFromFloat3, Matrix4x4::CreateFromRowMajorFloat16. There are several reasons casting directly is a bad idea:
A corollary to this is that the math types should not be stored in data directly. Store floats in the data and convert on load.