I want to create a plane 2d sprite plane that looks at a 3d object and then rotates by its z axis.
So I have created a LookAt Function in my game which will make the object look automatically at the sphere, but it is executed every frame, I believe this is because it makes the rotations every frame, now if I want to rotate it again by its local axis, the LookAt() overwrites this because its matrix is being set the same each time and so cannot rotate.
I believe I will have to rotate manually, now I know this problem is easy on one axis of rotation.
My maths is rusty. So I don't think I could just do this for a 3D rotation but I'm not sure. If so do I require quaternions?
Step by step desired action
- Rotation on the z axis to make the plane face on the right x angle of sphere ignoring its y position.
- Rotate on its x ais to make the plane face the y angle between sphere and 2d plane.
- Rotate around the z axis each second, while remaining faced at the object.
@Jay
Here is the code related to the first answer which makes my model dissapear.
selec->SetPosition(a->unit_x, a->unit_y, a->unit_z);
selec->GetMatrix(&rotmatrix[0][0]);
CMatrix4x4 crotmatrix{ &rotmatrix[0][0] };
crotmatrix.RotateLocalZ(0.025);
selec->GetMatrix(&lookatm[0][0]);
CMatrix4x4 clookat{ &lookatm[0][0] };
clookat.FaceTarget(CVector3{ 0,0,0 });
clookat.MultiplyAffine(crotmatrix);
convertmatrix(clookat);
selec->SetMatrix(&lookatm[0][0]);
This does multiply the matrices, but it keeps multiplying and creating a crazy motion, then causes a crash, maybe from gimbal lock?
crotmatrix
should only hold the z-rotation for that time. Is that correct? \$\endgroup\$