Fix using scale mode Gizmo
This commit is contained in:
@@ -26,7 +26,7 @@ namespace FlaxEditor.Gizmo
|
||||
// Return arithmetic average or whatever it means
|
||||
return center / count;
|
||||
}
|
||||
|
||||
|
||||
private bool IntersectsRotateCircle(Vector3 normal, ref Ray ray, out float distance)
|
||||
{
|
||||
var plane = new Plane(Vector3.Zero, normal);
|
||||
@@ -51,7 +51,7 @@ namespace FlaxEditor.Gizmo
|
||||
Vector3.Transform(ref ray.Position, ref invGizmoWorld, out localRay.Position);
|
||||
|
||||
// Find gizmo collisions with mouse
|
||||
float closestintersection = float.MaxValue;
|
||||
float closestIntersection = float.MaxValue;
|
||||
float intersection;
|
||||
_activeAxis = Axis.None;
|
||||
switch (_activeMode)
|
||||
@@ -59,42 +59,42 @@ namespace FlaxEditor.Gizmo
|
||||
case Mode.Translate:
|
||||
{
|
||||
// Axis boxes collision
|
||||
if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (XAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.X;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (YAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Y;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (ZAxisBox.Intersects(ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Z;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
// Quad planes collision
|
||||
if (closestintersection >= float.MaxValue)
|
||||
closestintersection = float.MinValue;
|
||||
if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
|
||||
if (closestIntersection >= float.MaxValue)
|
||||
closestIntersection = float.MinValue;
|
||||
if (XYBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.XY;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
|
||||
if (XZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.ZX;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestintersection)
|
||||
if (YZBox.Intersects(ref localRay, out intersection) && intersection > closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.YZ;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -103,20 +103,20 @@ namespace FlaxEditor.Gizmo
|
||||
case Mode.Rotate:
|
||||
{
|
||||
// Circles
|
||||
if (IntersectsRotateCircle(Vector3.UnitX, ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (IntersectsRotateCircle(Vector3.UnitX, ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.X;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
if (IntersectsRotateCircle(Vector3.UnitY, ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (IntersectsRotateCircle(Vector3.UnitY, ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Y;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
if (IntersectsRotateCircle(Vector3.UnitZ, ref localRay, out intersection) && intersection < closestintersection)
|
||||
if (IntersectsRotateCircle(Vector3.UnitZ, ref localRay, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Z;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
// Center
|
||||
@@ -132,27 +132,27 @@ namespace FlaxEditor.Gizmo
|
||||
case Mode.Scale:
|
||||
{
|
||||
// Spheres collision
|
||||
if (ScaleXSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
|
||||
if (ScaleXSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.X;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
if (ScaleYSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
|
||||
if (ScaleYSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Y;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
if (ScaleZSphere.Intersects(ref ray, out intersection) && intersection < closestintersection)
|
||||
if (ScaleZSphere.Intersects(ref ray, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Z;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
// Center
|
||||
if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestintersection)
|
||||
if (CenterBox.Intersects(ref ray, out intersection) && intersection < closestIntersection)
|
||||
{
|
||||
_activeAxis = Axis.Center;
|
||||
closestintersection = intersection;
|
||||
closestIntersection = intersection;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace FlaxEditor.Gizmo
|
||||
_axisAlignedWorld = _screenScaleMatrix * Matrix.CreateWorld(Position, Vector3.Backward, Vector3.Up);
|
||||
|
||||
// Assign world
|
||||
if (_activeTransformSpace == TransformSpace.World)
|
||||
if (_activeTransformSpace == TransformSpace.World && _activeMode != Mode.Scale)
|
||||
{
|
||||
_gizmoWorld = _axisAlignedWorld;
|
||||
|
||||
@@ -297,29 +297,6 @@ namespace FlaxEditor.Gizmo
|
||||
else if (_activeMode == Mode.Scale)
|
||||
{
|
||||
// Scale
|
||||
if (_activeTransformSpace == TransformSpace.World && _activeAxis != Axis.Center)
|
||||
{
|
||||
var deltaLocal = delta;
|
||||
Quaternion orientation = GetSelectedObject(0).Orientation;
|
||||
delta = Vector3.Transform(delta, orientation);
|
||||
|
||||
// Fix axis sign of delta movement for rotated object in some cases (eg. rotated object by 90 deg on Y axis and scale in world space with Red/X axis)
|
||||
switch (_activeAxis)
|
||||
{
|
||||
case Axis.X:
|
||||
if (deltaLocal.X < 0)
|
||||
delta *= -1;
|
||||
break;
|
||||
case Axis.Y:
|
||||
if (deltaLocal.Y < 0)
|
||||
delta *= -1;
|
||||
break;
|
||||
case Axis.Z:
|
||||
if (deltaLocal.Z < 0)
|
||||
delta *= -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_scaleDelta = delta;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user