Fix gizmo in top down view on Z-axis movement (and other combination of perpendicular views)
Fix gizmo stability when using single axis #530
This commit is contained in:
@@ -204,24 +204,43 @@ namespace FlaxEditor.Gizmo
|
|||||||
|
|
||||||
switch (_activeAxis)
|
switch (_activeAxis)
|
||||||
{
|
{
|
||||||
case Axis.XY:
|
|
||||||
case Axis.X:
|
case Axis.X:
|
||||||
{
|
{
|
||||||
var plane = new Plane(Vector3.Backward, Vector3.Transform(Position, invRotationMatrix).Z);
|
var plane = new Plane(Position, Vector3.Normalize(ray.Position - Position));
|
||||||
if (ray.Intersects(ref plane, out float intersection))
|
if (ray.Intersects(ref plane, out float intersection))
|
||||||
{
|
{
|
||||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||||
if (_lastIntersectionPosition != Vector3.Zero)
|
if (_lastIntersectionPosition != Vector3.Zero)
|
||||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||||
delta = _activeAxis == Axis.X
|
delta = new Vector3(_tDelta.X, 0, 0);
|
||||||
? new Vector3(_tDelta.X, 0, 0)
|
}
|
||||||
: new Vector3(_tDelta.X, _tDelta.Y, 0);
|
break;
|
||||||
|
}
|
||||||
|
case Axis.Y:
|
||||||
|
{
|
||||||
|
var plane = new Plane(Position, Vector3.Normalize(ray.Position - Position));
|
||||||
|
if (ray.Intersects(ref plane, out float intersection))
|
||||||
|
{
|
||||||
|
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||||
|
if (_lastIntersectionPosition != Vector3.Zero)
|
||||||
|
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||||
|
delta = new Vector3(0, _tDelta.Y, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Axis.Z:
|
case Axis.Z:
|
||||||
|
{
|
||||||
|
var plane = new Plane(Position, Vector3.Normalize(ray.Position - Position));
|
||||||
|
if (ray.Intersects(ref plane, out float intersection))
|
||||||
|
{
|
||||||
|
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||||
|
if (_lastIntersectionPosition != Vector3.Zero)
|
||||||
|
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||||
|
delta = new Vector3(0, 0, _tDelta.Z);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case Axis.YZ:
|
case Axis.YZ:
|
||||||
case Axis.Y:
|
|
||||||
{
|
{
|
||||||
var plane = new Plane(Vector3.Left, Vector3.Transform(Position, invRotationMatrix).X);
|
var plane = new Plane(Vector3.Left, Vector3.Transform(Position, invRotationMatrix).X);
|
||||||
if (ray.Intersects(ref plane, out float intersection))
|
if (ray.Intersects(ref plane, out float intersection))
|
||||||
@@ -229,18 +248,19 @@ namespace FlaxEditor.Gizmo
|
|||||||
_intersectPosition = ray.Position + ray.Direction * intersection;
|
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||||
if (_lastIntersectionPosition != Vector3.Zero)
|
if (_lastIntersectionPosition != Vector3.Zero)
|
||||||
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||||
switch (_activeAxis)
|
delta = new Vector3(0, _tDelta.Y, _tDelta.Z);
|
||||||
{
|
}
|
||||||
case Axis.Y:
|
break;
|
||||||
delta = new Vector3(0, _tDelta.Y, 0);
|
}
|
||||||
break;
|
case Axis.XY:
|
||||||
case Axis.Z:
|
{
|
||||||
delta = new Vector3(0, 0, _tDelta.Z);
|
var plane = new Plane(Vector3.Backward, Vector3.Transform(Position, invRotationMatrix).Z);
|
||||||
break;
|
if (ray.Intersects(ref plane, out float intersection))
|
||||||
default:
|
{
|
||||||
delta = new Vector3(0, _tDelta.Y, _tDelta.Z);
|
_intersectPosition = ray.Position + ray.Direction * intersection;
|
||||||
break;
|
if (_lastIntersectionPosition != Vector3.Zero)
|
||||||
}
|
_tDelta = _intersectPosition - _lastIntersectionPosition;
|
||||||
|
delta = new Vector3(_tDelta.X, _tDelta.Y, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -271,12 +291,11 @@ namespace FlaxEditor.Gizmo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modifiers
|
||||||
if (isScaling)
|
if (isScaling)
|
||||||
delta *= 0.01f;
|
delta *= 0.01f;
|
||||||
|
|
||||||
if (Owner.IsAltKeyDown)
|
if (Owner.IsAltKeyDown)
|
||||||
delta *= 0.5f;
|
delta *= 0.5f;
|
||||||
|
|
||||||
if ((isScaling ? ScaleSnapEnabled : TranslationSnapEnable) || Owner.UseSnapping)
|
if ((isScaling ? ScaleSnapEnabled : TranslationSnapEnable) || Owner.UseSnapping)
|
||||||
{
|
{
|
||||||
float snapValue = isScaling ? ScaleSnapValue : TranslationSnapValue;
|
float snapValue = isScaling ? ScaleSnapValue : TranslationSnapValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user