Currently I have an orbiting camera that fixates on a single point. In the node-based structure, _cameraNode
is a child of _cameraTargetNode
. I am able to orbit around the target node via the following code snippet:
Urho3D::Quaternion rotY = Urho3D::Quaternion(1.f, Urho3D::Vector3(dy, 0.f, 0.f));
Urho3D::Quaternion rotX = Urho3D::Quaternion(1.f, Urho3D::Vector3(0.f, dx, 0.f));
Urho3D::Vector3 curPos = _cameraNode->GetTransform().Inverse().Translation();
_cameraNode->RotateAround(curPos, rotY, Urho3D::TS_LOCAL);
_cameraNode->RotateAround(Urho3D::Vector3::ZERO, rotX, Urho3D::TS_PARENT);
cameraNode->LookAt(Urho3D::Vector3::ZERO, Urho3D::Vector3::UP, Urho3D::TS_PARENT);
Now what I want to do is clamp this movement. I want to be able to orbit within a set area between the two following values:
const Urho3D::Vector3 rotClampMin = Urho3D::Vector3(0.f, -45.f, 0.f);
const Urho3D::Vector3 rotClampMax = Urho3D::Vector3(90.f, 45.f, 0.f);
RotateAround
sets both the angle and position of _cameraNode
, so I must pre-compute the values with the clamping in mind. I would like to avoid working with Euler angles as much as possible. How can I clamp my rotation prior to calling _cameraNode->RotateAround
?
ratClampMin
), converting your quaternion to Euler angles remains a valid solution. Else you need to do the conversion the other way round, converting the obvious inequalities with Euler angles into inequalities of quaternions, with an adequate change of variables (en.wikipedia.org/wiki/…). That may lead up to more than four inequalities due to the use of sine and cosine function. Also I didn't get what "values" you want to pre-compute. \$\endgroup\$