On 12/12/2017 at 07:01, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform:
Language(s) : C++ ;
---------
How can I rotate the object visible from the camera's position in the same direction as the camera's axis?
BaseDraw * rbd = doc-> GetRenderBaseDraw ();
BaseObject * camera = rbd -> GetSceneCamera (doc);
Matrix mCamera = camera -> GetMg ();
Vector vCameraHPB = MatrixToHPB (mCamera, ROTATIONORDER_HPB);
Matrix mCameraProjection = HPBToMatrix (vCameraHPB, ROTATIONORDER_HPB);
BaseObject * obj = doc-> GetActiveObject ();
Matrix mObj = obj -> GetMg ();
Vector vXaxis = Vector (1, 0, 0);
vXaxis = mCameraProjection * vXaxis;
Matrix mRotateObj = RotAxisToMatrix (vXaxis, Rad (0.1));
mObj = mObj * mRotateObj;
obj -> SetMg (mObj);
EventAdd ();
Wherever the position of the camera is, the object will rotate vertically.
This code is successful.
However, after moving the camera, the axis of rotation is shifted for some reason.
When examined by debugging, vXaxis correctly creates the X axis from the position of the camera, but the actual result is rotated by using the X axis of the camera position which existed at the time of first creating the object I will excuse you. Why is this?