1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:53:50 +00:00

Change free axis rotation.

This commit is contained in:
Aesylwinn 2016-08-15 15:07:43 -04:00
parent 3e4ac0c662
commit 7125775648
2 changed files with 44 additions and 27 deletions

View file

@ -188,6 +188,7 @@ void CSMPrefs::State::declare()
"Shift-acceleration factor during drag operations", 4.0). "Shift-acceleration factor during drag operations", 4.0).
setTooltip ("Acceleration factor during drag operations while holding down shift"). setTooltip ("Acceleration factor during drag operations while holding down shift").
setRange (0.001, 100.0); setRange (0.001, 100.0);
declareDouble ("rotate-factor", "Free rotation factor", 0.007).setPrecision(4).setRange(0.0001, 0.1);
declareCategory ("Tooltips"); declareCategory ("Tooltips");
declareBool ("scene", "Show Tooltips in 3D scenes", true); declareBool ("scene", "Show Tooltips in 3D scenes", true);

View file

@ -323,8 +323,40 @@ void CSVRender::InstanceMode::drag (const QPoint& pos, int diffX, int diffY, dou
osg::Vec3f eye, centre, up; osg::Vec3f eye, centre, up;
getWorldspaceWidget().getCamera()->getViewMatrix().getLookAt (eye, centre, up); getWorldspaceWidget().getCamera()->getViewMatrix().getLookAt (eye, centre, up);
float angle;
osg::Vec3f axis;
if (mDragAxis == -1)
{
// Free rotate
float rotationFactor = CSMPrefs::get()["3D Scene Input"]["rotate-factor"].toDouble() * speedFactor;
osg::Quat cameraRotation = getWorldspaceWidget().getCamera()->getInverseViewMatrix().getRotate();
osg::Vec3f camForward = centre - eye;
osg::Vec3f screenDir = cameraRotation * osg::Vec3f(diffX, diffY, 0);
screenDir.normalize();
angle = std::sqrt(diffX*diffX + diffY*diffY) * rotationFactor;
axis = screenDir ^ camForward;
}
else
{
// Global axis rotation
osg::Vec3f camBack = eye - centre; osg::Vec3f camBack = eye - centre;
for (int i = 0; i < 3; ++i)
{
if (i == mDragAxis)
axis[i] = 1;
else
axis[i] = 0;
}
// Flip axis if facing opposite side
if (camBack * axis < 0)
axis *= -1;
// Convert coordinate system // Convert coordinate system
osg::Vec3f screenCenter = getScreenCoords(getSelectionCenter(selection)); osg::Vec3f screenCenter = getScreenCoords(getSelectionCenter(selection));
@ -343,27 +375,11 @@ void CSVRender::InstanceMode::drag (const QPoint& pos, int diffX, int diffY, dou
newVec.normalize(); newVec.normalize();
// Find angle and axis of rotation // Find angle and axis of rotation
float angle = std::acos(oldVec * newVec) * speedFactor; angle = std::acos(oldVec * newVec) * speedFactor;
if (((oldVec ^ newVec) * camBack < 0) ^ (camBack.z() < 0)) if (((oldVec ^ newVec) * camBack < 0) ^ (camBack.z() < 0))
angle *= -1; angle *= -1;
osg::Vec3f axis;
if (mDragAxis != -1)
{
for (int i = 0; i < 3; ++i)
{
if (i == mDragAxis)
axis[i] = 1;
else
axis[i] = 0;
} }
if (camBack * axis < 0)
axis *= -1;
}
else
axis = camBack;
rotation = osg::Quat(angle, axis); rotation = osg::Quat(angle, axis);
} }
else if (mDragMode == DragMode_Scale) else if (mDragMode == DragMode_Scale)