   [C#] [GUI] How can I sensibly limit object's movement with my movement method?
  I'm moving an object around my GUI in a similar fashion to the  Unity's GUI.  My method is to create a plane which has a normal opposite to the camera's forward vector and project the object onto that plane:   private void MoveSelectedObject()   {  // Set previous contact point to the contact point calculated last frame  points[1] = points[0];  // Holds contact information for ray and plane  Contact3D contact = new Contact3D();  // Create a plane facing the camera based on the position of the object  plane.Normal = -Game1.Instance.camera.Forward;  plane.D = Vector3.Dot(objectSelected.Position, plane.Normal);  // Test the mouse cursor's ray for intersection with the plane  if (!Detection3D.TestShapeShape(cursor.Ray, plane, ref contact))  { // If the ray somehow misses the plane, return and don't move the object return;  }  points[0] = contact.point;  if (points[1].Z == float.MaxValue)  { // Previous projected distance has not be found  // Therefore delta calculations can't be made return;  }  // Get the current position of the object  Vector3 v = objectSelected.Position;  // Find out which axis object movement is constrained to  switch (cross.AxisSelected)  { case AxisSelected.All:{    // Project the contact point onto the axis along which to move the object    float d = Vector3.Dot(points[0], Vector3.UnitX);    // Find the distance along that axis from the previous projected contact point    d -= Vector3.Dot(points[1], Vector3.UnitX);    // Move the object along the projected axis by the distance calculated    v.X += d;    // Y axis    d = Vector3.Dot(points[0], Vector3.UnitY);    d -= Vector3.Dot(points[1], Vector3.UnitY);    v.Y += d;    // Z axis    d = Vector3.Dot(points[0], Vector3.UnitZ);    d -= Vector3.Dot(points[1], Vector3.UnitZ);    v.Z += d;    break;} case AxisSelected.None:{    break;} case AxisSelected.X:{    float d = Vector3.Dot(points[0], Vector3.UnitX);    d -= Vector3.Dot(points[1], Vector3.UnitX);    v.X += d;    break;} case AxisSelected.Y:{    float d = Vector3.Dot(points[0], Vector3.UnitY);    d -= Vector3.Dot(points[1], Vector3.UnitY);    v.Y += d;    break;} case AxisSelected.Z:{    float d = Vector3.Dot(points[0], Vector3.UnitZ);    d -= Vector3.Dot(points[1], Vector3.UnitZ);    v.Z += d;    break;}  }  // Update the object's position based on the projected distance  objectSelected.Position = v;   }The problem is that if the camera forward is close to parallel with the current axis selected then the object will move too far into the distance if I move the mouse far enough left and right.How can I limit the object's movement to be similar to that of Unity's movement?   
  Not sure what you mean, can you link to an actual screenshot of their GUI?   ;  You need to move by an angle not by a distance.  You want to move a given arc each move, not a distance.  So you need to calculate the distance depending on the arc you want to move.  Pretty basic geometry.  If ya need some help with it, just ask.theTroll   ;  The unity GUI looks like the following:The rock is selected and can be moved in the direction of the hilighted arrow or anywhere if the rectangle is clicked.My GUI follows the same idea:Quote:You need to move by an angle not by a distance. You want to move a given arc each move, not a distance. So you need to calculate the distance depending on the arc you want to move. Pretty basic geometry. If ya need some help with it, just ask.I'm not following, some help would definitely be welcome at this point.Thanks guys.   ;  This will always give a constant move determined by the closest object.Okay, you take the distance to the closest object we will call it d.Then you have the angle you want to me we will call that t.So to determine the move you do move_distance = d * tan(t).Hope that makes sense, typing this with a screaming baby on my lap.theTroll;  One simple approach requires a project() function and an unproject() function, which take a point and transform it from world space into screen space, and vice-versa (in OpenGL this would be gluProject/gluUnproject).Given these functions, you can project the starting point of the object into screen space, add the dx,dy mouse movement to this point, and unproject the result back - this provides you with movement in a plane parallel to the screen.   ;Quote:Original post by swiftcoderOne simple approach requires a project() function and an unproject() function, which take a point and transform it from world space into screen space, and vice-versa (in OpenGL this would be gluProject/gluUnproject).Given these functions, you can project the starting point of the object into screen space, add the dx,dy mouse movement to this point, and unproject the result back - this provides you with movement in a plane parallel to the screen.I thought I was already doing this?I am using project/unproject for the mouse cursor position onto the plane facing the camera. // Test the mouse cursor's ray for intersection with the plane  if (!Detection3D.TestShapeShape(cursor.Ray, plane, ref contact))  { // If the ray somehow misses the plane, return and don't move the object return;  }Then adding the dx, dy mouse movement:    float d = Vector3.Dot(points[0], Vector3.UnitX);    d -= Vector3.Dot(points[1], Vector3.UnitX);    v.X += d;    break;etc.Quote:Original post by swiftcoderOkay, you take the distance to the closest object we will call it d.Is this the distance between the projected mouse ray's origin and the object selected?  Does the distance remain constant or vary by mouse movement each frame?Quote:Original post by swiftcoderThen you have the angle you want to me we will call that t.Is this the very small angle between mouse position last frame and the mouse position this frame?Sorry for all the questions, I'm still not grasping the idea yet.   