I'm creating a transform class to make storing the transform of individual objects in a scene easier, but I'm unsure on how to do it.
I could create one like this:
class Transform
{
public:
//...
private:
Matrix4f matrix;
};
- Easy to concatenate
- Easy to perform operations on (since the matrix functions already exist)
- Can store certain information such as the camera projection
- Difficult to get the individual values such as the position of the object
- Performing operations in the wrong order can lead to unexpected results (rotate/translate/rotate results in a very different transform than rotate/rotate/translate)
- Lots of memory usage (64 bytes of data for a single-precision transform)
Or like this:
class Transform
{
public:
//...
private:
Vector3f position;
Quaternionf rotation;
Vector3f scale;
};
- Very easy to extract individual values
- Very easy to change individual values
- Because the position, rotation, and scale are independent from one-another, there is no "correct" order for rotate/translate/scale
- Smaller, being only 40 bytes for single-precision
- Cannot store anything beyond position/rotation/scale
- Performing operations which require information stores in more than one value (such as strafing, which changes the position but depends on the rotation) are much more difficult to implement
I'm not entirely sure how most game engines deal with this. Which implementation should I go with?