Skip to content

Commit

Permalink
X and Z axis handle dragging will now try to match the camera/arrow r…
Browse files Browse the repository at this point in the history
…elationship. It isn't perfect and it doesn't work for 2d movement, or if the item in question has been rotated on multiple axes.
  • Loading branch information
jcorvinus committed Mar 1, 2015
1 parent 63fcefd commit 9b6ea1c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 3 additions & 3 deletions SADXLVL2/MainForm.cs
Expand Up @@ -1738,9 +1738,9 @@ private void Panel1_MouseMove(object sender, MouseEventArgs e)
break;

case MouseButtons.Left:
cameraPointA.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed);
cameraPointB.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed);
transformGizmo.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed);
cameraPointA.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed, cam);
cameraPointB.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed, cam);
transformGizmo.TransformAffected(mouseDelta.X / 2 * cam.MoveSpeed, mouseDelta.Y / 2 * cam.MoveSpeed, cam);
DrawLevel();
break;

Expand Down
22 changes: 17 additions & 5 deletions SAEditorCommon/UI/PointHelper.cs
Expand Up @@ -177,27 +177,39 @@ private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
/// <param name="xChange">Input for x axis.</param>
/// <param name="yChange">Input for y axis.</param>
/// <returns>TRUE if an operation was performed, FALSE if nothing was done.</returns>
public bool TransformAffected(float xChange, float yChange)
public bool TransformAffected(float xChange, float yChange, EditorCamera cam)
{
// don't operate with an invalid axis seleciton, or invalid mode
if ((selectedAxes == GizmoSelectedAxes.NONE) || (!enabled))
return false;

float yFlip = -1; // I don't think we'll ever need to mess with this
float xFlip = 1; // TODO: this though, should get flipped depending on the camera's orientation to the object.
float xFlip = 1; // TODO: Depending on the orientation of the camera, this will need to be flipped.
// consider using the cross product of the camera's look vector and the handle's position to determine
// if the flip is needed.

float xOff = 0.0f, yOff = 0.0f, zOff = 0.0f;
float xOff = 0.0f, yOff = 0.0f, zOff = 0.0f, axisDot = 0.0f;

Vector3 axisDirection = new Vector3();

switch (selectedAxes)
{
case GizmoSelectedAxes.X_AXIS:
xOff = xChange;
axisDirection = new Vector3(1, 0, 0);
axisDot = Vector3.Dot(cam.Look, axisDirection);
xFlip = (axisDot > 0) ? 1 : -1;
xOff = xChange * xFlip;
break;
case GizmoSelectedAxes.Y_AXIS:
axisDirection = new Vector3(0, 1, 0);
axisDot = Vector3.Dot(cam.Look, axisDirection);
yOff = yChange * yFlip;
break;
case GizmoSelectedAxes.Z_AXIS:
zOff = xChange;
axisDirection = new Vector3(0, 0, 1);
axisDot = Vector3.Dot(cam.Look, axisDirection);
xFlip = (axisDot > 0) ? -1 : 1;
zOff = xChange * xFlip;
break;
case GizmoSelectedAxes.XY_AXIS:
xOff = xChange; yOff = yChange * yFlip;
Expand Down
27 changes: 20 additions & 7 deletions SAEditorCommon/UI/TransformGizmo.cs
Expand Up @@ -177,7 +177,6 @@ public void Draw(Device d3ddevice, EditorCamera cam)
RenderInfo.Draw(Render(d3ddevice, new MatrixStack(), cam), d3ddevice, cam);

d3ddevice.EndScene(); //all drawings before this line
//d3ddevice.Present();
}

// TODO: Consider returning IEnumerable<RenderInfo>
Expand Down Expand Up @@ -291,7 +290,7 @@ private void SetGizmo()
/// </summary>
/// <param name="xChange">Input for x axis.</param>
/// <param name="yChange">Input for y axis.</param>
public void TransformAffected(float xChange, float yChange)
public void TransformAffected(float xChange, float yChange, EditorCamera cam)
{
// don't operate with an invalid axis seleciton, or invalid mode
if (!enabled)
Expand All @@ -301,6 +300,7 @@ public void TransformAffected(float xChange, float yChange)

float yFlip = -1; // I don't think we'll ever need to mess with this
float xFlip = 1; // TODO: this though, should get flipped depending on the camera's orientation to the object.
float axisDot = 0;

for (int i = 0; i < affectedItems.Count; i++) // loop through operands
{
Expand All @@ -319,13 +319,17 @@ public void TransformAffected(float xChange, float yChange)
switch (selectedAxes)
{
case GizmoSelectedAxes.X_AXIS:
destination = (currentPosition + Right * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange));
axisDot = Vector3.Dot(cam.Look, Right);
xFlip = (axisDot > 0) ? 1 : -1;
destination = (currentPosition + Right * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
break;
case GizmoSelectedAxes.Y_AXIS:
destination = (currentPosition + Up * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange));
destination = (currentPosition + Up * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange * yFlip));
break;
case GizmoSelectedAxes.Z_AXIS:
destination = (currentPosition + Look * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange));
axisDot = Vector3.Dot(cam.Look, Right);
xFlip = (axisDot > 0) ? -1 : 1;
destination = (currentPosition + Look * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
break;
}

Expand All @@ -334,17 +338,26 @@ public void TransformAffected(float xChange, float yChange)
else
{
float xOff = 0.0f, yOff = 0.0f, zOff = 0.0f;
Vector3 axisDirection = new Vector3();

switch (selectedAxes)
{
case GizmoSelectedAxes.X_AXIS:
xOff = xChange;
axisDirection = new Vector3(1, 0, 0);
axisDot = Vector3.Dot(cam.Look, axisDirection);
xFlip = (axisDot > 0) ? 1 : -1;
xOff = xChange * xFlip;
break;
case GizmoSelectedAxes.Y_AXIS:
axisDirection = new Vector3(0, 1, 0);
axisDot = Vector3.Dot(cam.Look, axisDirection);
yOff = yChange * yFlip;
break;
case GizmoSelectedAxes.Z_AXIS:
zOff = xChange;
axisDirection = new Vector3(0, 0, 1);
axisDot = Vector3.Dot(cam.Look, axisDirection);
xFlip = (axisDot > 0) ? -1 : 1;
zOff = xChange * xFlip;
break;
case GizmoSelectedAxes.XY_AXIS:
xOff = xChange; yOff = yChange * yFlip;
Expand Down
2 changes: 1 addition & 1 deletion SALVL/MainForm.cs
Expand Up @@ -468,7 +468,7 @@ private void Panel1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs
}
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (transformGizmo != null) transformGizmo.TransformAffected(chg.X / 2, chg.Y / 2);
if (transformGizmo != null) transformGizmo.TransformAffected(chg.X / 2, chg.Y / 2, cam);
DrawLevel();

Rectangle scrbnds = Screen.GetBounds(Cursor.Position);
Expand Down

0 comments on commit 9b6ea1c

Please sign in to comment.