I’ve recently started becoming a bit more familiar with Cinders timeline feature given that I need to render some 3D text moving about.
The text will both be translated and rotated, so I’ve used a Mat4 to represent this, but I’ve noticed that when rotating the text it appears to also change in shape/size, see video:
My guess is that this is the natural cause of the Anim object applying a partial change via the +operator to the Matrix. But how to avoid it?
Perhaps separating the position and rotation into separate matrices, or a matrix and a quaternion?
It’d complicate the code, but I’m not sure it can be avoided?
when either updates. Be sure to use the call operator () on your ci::Anim objects when passing them to glm because i ran across a major performance degradation caused by some templated constructor magic in glm when omitting it.
Are you adding matrices? It seems so, since you’re mentioning operator+. But to apply multiple transformations, you’ll have to multiply them. The order in which you do that in OpenGL is the reverse of what you might expect. If you first want to rotate, then scale, then translate, you should do this:
gl::ScopedModelMatrix scpModel;
gl::translate( x, y, z ); // 3rd: translate the scaled and rotated model.
gl::rotate( glm::radians( 45.0f ) ); // 2nd: rotate the model 45 degrees.
gl::scale( vec2( 5.0f ) ); // 1st: scale the model by 5.
mBatch->draw();
@paul.houx - I am indeed multiplying the matrices when rendering the text.
I’m using an Anim<Mat4> to animate the object, and different Mat4 objects describing the new position and rotation. As far as I know Anim interpolates between the Mat4’s using the operator+ which I’m guessing causes the odd warp.
So as far as I know currently it’s a matter of how this Mat4 is being updated via the Anim object.
Yes, a matrix can not be interpolated like that. The underlying calculation of an Anim is: a + t * ( b - a )
, but that’s not how matrices should be concatenated and they also do not support interpolation.
To animate your text, you need to animate its position (vec3), rotation (quat) and scale (vec3) separately, then construct the matrix from their values. Just like @lithium pointed out in his reply.