public override bool HitTest(HitLine hit) { if (Anchor2 == null) return false; for (int i = 0; i < solidPoints.Length - 1; i++) { HitLine line = new HitLine() { Front = solidPoints[i], Back = solidPoints[i + 1], Camera = hit.Camera }; if (line.ShortestDistance(hit) < HitTol * hit.Camera.SceneToWorldScaling) { lastHit = hit.GetIntersection((ParentEntity as Sketch).Plane); return true; } } return false; }
/// <summary> /// Computes the shortest distance between two lines. /// </summary> /// <remarks>Uses the forumlae from /// http://pacificcoast.net/~cazelais/261/distance.pdf</remarks> public double ShortestDistance(HitLine other) { Vector n = Direction.Cross(other.Direction); if (n.Magnitude == 0) return 0; return Math.Abs((Front - other.Front).Dot(n) / n.Magnitude); }
public override bool HitTest(HitLine hit) { if (Points.Count == 0) return false; for (int i = 0; i < Points.Count - 1; i++) { HitLine line = new HitLine() { Front = Points[i].ToVector(), Back = Points[i+1].ToVector(), Camera = hit.Camera }; if (line.ShortestDistance(hit) < HitTol * hit.Camera.SceneToWorldScaling) { lastHit = hit.GetIntersection((ParentEntity as Sketch).Plane); return true; } } return false; }
/// <summary> /// Performs a hit test with two vectors lying on a 3D line. /// </summary> /// <returns> True if the renderable was hit. </returns> public virtual bool HitTest(HitLine hitLine) { return _bounds.HitTest(hitLine, out lastHit); }
/// <summary> /// Performs a hit test with two vectors lying on a 3D line. /// </summary> /// <param name="hitLine"> A <see cref="HitLine"/> defining the hit. </param> /// <param name="hit">The point of the hit, if any.</param> /// <returns> True if the entity was hit. </returns> public virtual bool HitTest(HitLine hitLine, out Vector hit) { hit = null; if (!isSet) return false; // check if the line lies entirely outside the box if (hitLine.Back[0] < minima[0] && hitLine.Front[0] < minima[0]) return false; if (hitLine.Back[0] > maxima[0] && hitLine.Front[0] > maxima[0]) return false; if (hitLine.Back[1] < minima[1] && hitLine.Front[1] < minima[1]) return false; if (hitLine.Back[1] > maxima[1] && hitLine.Front[1] > maxima[1]) return false; if (hitLine.Back[2] < minima[2] && hitLine.Front[2] < minima[2]) return false; if (hitLine.Back[2] > maxima[2] && hitLine.Front[2] > maxima[2]) return false; // check if the line lies entirely inside the box if (hitLine.Front[0] > minima[0] && hitLine.Front[0] < maxima[0] && hitLine.Front[1] > minima[1] && hitLine.Front[1] < maxima[1] && hitLine.Front[2] > minima[2] && hitLine.Front[2] < maxima[2]) { hit = hitLine.Front; return true; } // check if the line intersects any of the individual sides if ((GetIntersection(hitLine.Front[0] - minima[0], hitLine.Back[0] - minima[0], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 1)) || (GetIntersection(hitLine.Front[1] - minima[1], hitLine.Back[1] - minima[1], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 2)) || (GetIntersection(hitLine.Front[2] - minima[2], hitLine.Back[2] - minima[2], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 3)) || (GetIntersection(hitLine.Front[0] - maxima[0], hitLine.Back[0] - maxima[0], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 1)) || (GetIntersection(hitLine.Front[1] - maxima[1], hitLine.Back[1] - maxima[1], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 2)) || (GetIntersection(hitLine.Front[2] - maxima[2], hitLine.Back[2] - maxima[2], hitLine.Front, hitLine.Back, out hit) && InBox(hit, minima, maxima, 3))) { return true; } return false; }
public override bool HitTest(HitLine hitLine) { if (start == null || stop == null) return false; HitLine line = new HitLine(); line.Front = start; line.Back = stop; double dist = line.ShortestDistance(hitLine); lastHit = (start + stop) / 2; // HACK: need actual hit position return dist < Reference.HitTol * hitLine.Camera.SceneToWorldScaling; }
public override bool HitTest(HitLine hit) { if (Center == null) return false; // set the last hit, even if we didn't hit anything lastHit = hit.GetIntersection((ParentEntity as Sketch).Plane); // test for hitting the center Coord center = hit.Camera.WorldToScreen(Center.ToVector()); double distance = (hit.Screen - center).Magnitude; if (distance < Arc.HitTol) return true; if (Start == null) return false; // test for hitting the circle Coord start = hit.Camera.WorldToScreen(Start.ToVector()); double radius = (start - center).Magnitude; if (Math.Abs(distance - radius) < Arc.HitTol) return true; return false; }
/// <summary> /// Performs a hit test with two vectors lying on a 3D line. /// </summary> /// <param name="hitLine"> A <see cref="HitLine"/> defining the hit. </param> /// <returns> True if the entity was hit. </returns> public virtual bool HitTest(HitLine hitLine) { Vector hit; return HitTest(hitLine, out hit); }
/// <summary> /// Unprojects the screen coordinate into a world space hit line. /// </summary> public HitLine ScreenToWorld(Coord screen) { HitLine hitLine = new HitLine(); hitLine.Front = ScreenToWorld(screen, false); hitLine.Back = ScreenToWorld(screen, true); hitLine.Camera = this; hitLine.Screen = new Coord(screen.X, screen.Y); //Console.WriteLine("hit screen {0}, {1}", screen, hitLine); return hitLine; }
public override bool HitTest(HitLine hitLine) { if (!base.HitTest(hitLine)) return false; // project each point on to the screen and find the shortest distance int closestIndex = -1; double shortestDistance = -1; foreach (int r in dataSet.DisplayIndex) { double x = dataSet[r, columns[0]]; double y = dataSet[r, columns[1]]; double z = dataSet[r, columns[2]]; ParentAxes.PlotToWorldSpace.Apply(ref x, ref y, ref z); Coord coord = hitLine.Camera.WorldToScreen(x, y, z); // compute the distance double dist = (coord - hitLine.Screen).MagnitudeSquared; if (closestIndex < 0 || dist < shortestDistance) { closestIndex = r; shortestDistance = dist; } } // determine if one was selected double tolSquared = 64; //Console.WriteLine("shorted distance {0} at index {1}", Math.Sqrt(shortestDistance), closestIndex); if (shortestDistance < tolSquared) { selectedIndex[closestIndex] = true; IsSelected = true; return true; } return false; }
/// <summary> /// Finds the intersection of the hit line and the plane. /// </summary> /// <remarks>The vector will be snapped if ModelingOptions.Global.SnapToGrid.</remarks> public Vector GetIntersection(HitLine hit) { Vector vec = hit.GetIntersection(this); if (ModelingOptions.Global.SnapToGrid) vec = SnapToGrid(vec); return vec; }
public override bool HitTest(HitLine hit) { return base.HitTest(hit); }
/// <summary> /// Gets a point in control-space corresponding to the hit line in 3D space. /// </summary> private Coord GetControlPoint(HitLine hitLine) { if (RenderSize == null) return new Coord(); var intersection = hitLine.GetIntersection(this); var point = this.Project(intersection) / _scaling; point.Y = RenderHeight - point.Y; return point; }
public override bool HitTest(HitLine hit) { if (Anchor2 == null) return false; // get the major and minor axes Vector x = Sketch.Plane.LocalX; Vector y = Sketch.Plane.LocalY; Vector center = Center.ToVector(); double a = x.Dot(Anchor2.ToVector() - center); double b = y.Dot(Anchor2.ToVector() - center); // rotate the coordinate system to the tilt if (Tilt.Value != 0) { x = x.Rotate((ParentEntity as Sketch).Plane.Normal, Tilt); y = y.Rotate((ParentEntity as Sketch).Plane.Normal, Tilt); } // project the hit onto the plane's coordinate system lastHit = hit.GetIntersection((ParentEntity as Sketch).Plane); double hitX = (lastHit - center).Dot(x); double hitY = (lastHit - center).Dot(y); // test for the hit double hitTol = 0.1; if (Math.Abs(1 - hitX * hitX / (a * a) - hitY * hitY / (b * b)) < hitTol) return true; return false; }
public override bool HitTest(HitLine hitLine) { return false; }