Transforming points and vectors
The Transform
structure can be used to move points and vectors in space. Imagine a ball bouncing up and down. The bounce of the ball is derived from the Transform
structure, but how do you know where to move each vertex of the ball? You need to transform all the vertices using the Transform
structure (or a matrix) to properly display the ball.
Using a transform to modify points and vectors is like combining two transforms. To transform a point, first, apply the scale, then rotation, and finally, the translation of the transform. To transform a vector, follow the same steps, but don't add the position:
- Implement the
transformPoint
function inTransform.cpp
. Don't forget to add the function declaration toTransform.h
:vec3 transformPoint(const Transform& a, const vec3& b) { Â Â Â Â vec3 out; Â Â Â Â out = a.rotation * (a.scale * b); Â Â Â Â out = a.position + out; Â Â ...