1
\$\begingroup\$

The page at https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html provides an example for rotating around the center of the image:

// make a matrix that will move the origin of the 'F' to its center. var moveOriginMatrix = m3.translation(-50, -75);

Similarly, the library I'm using (gl-matrix), provides an ability to rotate around an origin vector:

fromRotationTranslationScaleOrigin [...] Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin

However, I'd like to generically set a rotation vector based on the relative local transform - e.g. something like giving [0.5,0.5, 0] as the origin parameter to fromRotationTranslationScaleOrigin() and have it always rotate around the center.

Would this require handling it somewhere else in the pipeline? (e.g. after composing with the perspective matrix) - or are there some best-practices ways of handling this?

I'd also like a matrix to allow centering within another's world matrix but that's a different question I guess :)

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.