void IClickable3D.MouseUp(Ray pointer) { }
void IClickable3D.MouseDown(Ray pointer) { mouseDownPoint = mouseHoverPoint; mouseDownOffset = offset; Console.WriteLine("Mouse Down TriMeshGUI"); }
void IClickable3D.MouseMove(Ray pointer) { Ray adjustedPointer = new Ray(pointer.Start - mouseDownOffset, pointer.Direction); // Move the object in the XY plane Plane plane = new Plane(Vector3.UnitZ, mouseDownPoint); Vector3 point = plane.Distance(adjustedPointer) * adjustedPointer.Direction + adjustedPointer.Start; Offset = mouseDownOffset + point - mouseDownPoint; }
internal void Zoom(Ray pointer, int ticks) { Vector3 target = pointer.Start + (plane.Distance(pointer) * pointer.Direction); viewMatrix = Matrix4.Mult(Matrix4.CreateTranslation((target - CameraPosition) * .10f * ticks), viewMatrix); ClampMatrix(ref viewMatrix); }
//Edge closestEdge = null; float IClickable3D.DistanceToObject(Ray pointer) { Ray adjustedPointer = new Ray(pointer.Start - offset, pointer.Direction); hovered = false; float distance = float.PositiveInfinity; foreach (Triangle t in base.Triangles) { TriangleRayIntersect i = new TriangleRayIntersect(t, adjustedPointer); if (i.Intersects) { float d = (adjustedPointer.Start - i.Point).Length; if (d < distance) { distance = d; mouseHoverPoint = i.Point; } } } // Remember the closest edge - debugging //float x = 0; //closestEdge = null; //foreach (Edge edge in this.Edges) //{ // List<Vector3> vertices = new List<Vector3>(edge.Vertices); // LineSegment segment = new LineSegment(vertices[0], vertices[1]); // float d = segment.Distance(mouseHoverPoint); // if (d < x || closestEdge == null) // { // closestEdge = edge; // x = d; // } //} isPointedAt = distance < float.PositiveInfinity; return distance; }
void IClickable3D.MouseUp(Ray pointer) { isMouseDown = false; }
public void MouseMove(Ray pointer) { float distance = plane.Distance(pointer); Vector3 point = pointer.Start + pointer.Direction * distance; if (isMouseDown) { Vector3 downLocation = plane.Distance(mouseDownRay) * mouseDownRay.Direction + mouseDownRay.Start; viewMatrix = Matrix4.Mult(Matrix4.CreateTranslation(point.X - downLocation.X, point.Y - downLocation.Y, 0), mouseDownMatrix); ClampMatrix(ref viewMatrix); } }
float IClickable3D.DistanceToObject(Ray pointer) { return plane.Distance(pointer); }
void IClickable3D.MouseDown(Ray pointer) { mouseDownRay = pointer; mouseDownMatrix = viewMatrix; mouseDownCameraPosition = CameraPosition; isMouseDown = true; }
void IClickable3D.MouseMove(Ray pointer) { float distance = drawSlice.Plane.Distance(pointer); Vector3 mousePoint = pointer.Start + pointer.Direction * distance + mouseOffset - locationOffset; selectedTabDraggedOff = true; float closestPointDistance = tabRadius; Vector3 closestPoint = mousePoint; foreach (var segment in TabPath.Segments(LineStrip.Type.Closed)) { Vector3 test = segment.ClosestPoint(mousePoint); float d = (mousePoint - test).Length; if (d < closestPointDistance) { selectedTabDraggedOff = false; closestPoint = test; closestPointDistance = d; } } tabLocations[selectedTabIndex] = closestPoint; }
void IClickable3D.MouseUp(Ray pointer) { if (selectedTabDraggedOff && selectedTabIndex >= 0) { tabLocations.RemoveAt(selectedTabIndex); } selectedTabIndex = -1; }
void IClickable3D.MouseDown(Ray pointer) { float distance = drawSlice.Plane.Distance(pointer); Vector3 mousePoint = pointer.Start + pointer.Direction * distance - locationOffset; if (selectedTabIndex < 0) { this.tabLocations.Add(hoveredPoint); selectedTabIndex = tabLocations.Count - 1; } mouseOffset = tabLocations[selectedTabIndex] - mousePoint; mouseHovering = true; }
float IClickable3D.DistanceToObject(Ray pointer) { mouseHovering = false; float distance = drawSlice.Plane.Distance(pointer); Vector3 mousePoint = pointer.Start + pointer.Direction * distance - locationOffset; hovered = false; float closestPointDistance = float.PositiveInfinity; Vector3 closestPoint = Vector3.Zero; if (distance > 0) { selectedTabIndex = -1; float minDistanceToTab = tabRadius; for (int i = 0; i < tabLocations.Count; i++) { float d = (mousePoint - tabLocations[i]).Length; if (d < minDistanceToTab) { selectedTabIndex = i; minDistanceToTab = d; hovered = true; } } if (selectedTabIndex < 0) { foreach (var segment in TabPath.Segments(LineStrip.Type.Closed)) { Vector3 test = segment.ClosestPoint(mousePoint); float d = (mousePoint - test).Length; if (d < closestPointDistance) { closestPoint = test; closestPointDistance = d; } } if (closestPointDistance < toolRadius) { hovered = true; hoveredPoint = closestPoint; } } } if (!hovered) { return float.PositiveInfinity; } return distance; }
public TriangleRayIntersect(Triangle triangle, Ray ray) { point = Vector3.Zero; intersects = false; float distance = triangle.Plane.Distance(ray); if (distance <= 0 || float.IsNaN(distance)) { // Plane is behind the ray, no intersection return; } point = ray.Direction * distance + ray.Start; // Make sure the point is within the triangle foreach (Plane p in triangle.EdgePlanes) { if (p.Distance(point) < 0) { // Outside of triangle, no intersection return; } } intersects = true; }
private IClickable3D GetClosestObject(Ray pointer) { IClickable3D closestClickable = null; float closest = float.PositiveInfinity; foreach (var o in objects) { if (o is IClickable3D) { var clickable = o as IClickable3D; float distance = clickable.DistanceToObject(pointer); if (distance < closest) { closestClickable = clickable; closest = distance; } } } if (FilterSelectable(closestClickable)) { closestClickable.MouseHover(); // TODO: find a better way to handle hover indication... return closestClickable; } return viewport as IClickable3D; }
/// <summary> /// Compute the distance along the ray to this plane. /// </summary> /// <param name="ray"></param> /// <returns>Distance along the ray until the plane is reached. If the plane is behind the ray, the return value is negative.</returns> public float Distance(Ray ray) { float fromRayStart = Distance(ray.Start); float alongRay = Math.Abs(fromRayStart / Vector3.Dot(ray.Direction, normal)); Vector3 target = ray.Start + alongRay * ray.Direction; // This should be on the plane - if not, the distance has the wrong sign. Vector3 target2 = ray.Start - alongRay * ray.Direction; // Rather than compare with zero, which is not deterministic, compare with the possible result if the plane were behind the ray. if (Math.Abs(Distance(target)) > Math.Abs(Distance(target2))) { alongRay = -alongRay; } return alongRay; }