I have created object draging by mouse. I am using this code to calculate dx, dy in screen space
pos = object position in world space
float objDistCam = pos.Distance(this->camera->GetPosition());
MyMath::Vector4 P = MyMath::Vector4(0, 0, objDistCam, 1.0f);
MyMath::Vector4 S = MyMath::Vector4::Transform(P, this->camera->GetCameraMatrices()->projectionMatrix);
S *= 1.0f / S.W;
MyMath::Vector4 S2 = S;
S2.X = S2.X + (((float)-pointBasedControl->GetChangeX()) / (this->camera->GetViewport()->Width * 0.5f));
S2.Y = S2.Y + (((float)pointBasedControl->GetChangeY()) / (this->camera->GetViewport()->Height * 0.5f));
MyMath::Matrix4x4 inv = MyMath::Matrix4x4::Invert(this->camera->GetCameraMatrices()->projectionMatrix);
MyMath::Vector4 P2 = MyMath::Vector4::Transform(S2, inv);
P2 *= 1.0f / P2.W;
dx = P.X - P2.X;
dy = P.Y - P2.Y;
Final object position is calculated like this
pos += camera_right * dx + camera_up * dy;
Now, this works.
If I lock single axis, lets say X (pos.X += camera_right.X * dx + camera_up.X * dy), it wors as well. Problem is, if axis system is not aligned with world axis and object is rotated. Then this leads to object moving in "world" X axis, not in "object" one. How to correct this?