public MouseMove3DEventArgs(object source, HitTestResult hitTestResult, Point position, Viewport3DX viewport = null) : base(GeometryModel3D.MouseMove3DEvent, source, hitTestResult, position, viewport) { }
/// <summary> /// Checks if the ray hits the geometry of the model. /// If there a more than one hit, result returns the hit which is nearest to the ray origin. /// </summary> /// <param name="rayWS">Hitring ray from the camera.</param> /// <param name="result">results of the hit.</param> /// <returns>True if the ray hits one or more times.</returns> public virtual bool HitTest(Ray rayWS, ref List<HitTestResult> hits) { if (this.Visibility == Visibility.Collapsed) { return false; } if (this.IsHitTestVisible == false) { return false; } var g = this.Geometry as MeshGeometry3D; var h = false; var result = new HitTestResult(); result.Distance = double.MaxValue; if (g != null) { var m = this.modelMatrix; // put bounds to world space var b = BoundingBox.FromPoints(this.Geometry.Positions.Select(x => Vector3.TransformCoordinate(x, m)).ToArray()); //var b = this.Bounds; // this all happens now in world space now: if (rayWS.Intersects(ref b)) { foreach (var t in g.Triangles) { float d; var p0 = Vector3.TransformCoordinate(t.P0, m); var p1 = Vector3.TransformCoordinate(t.P1, m); var p2 = Vector3.TransformCoordinate(t.P2, m); if (Collision.RayIntersectsTriangle(ref rayWS, ref p0, ref p1, ref p2, out d)) { if (d < result.Distance) { result.IsValid = true; result.ModelHit = this; // transform hit-info to world space now: result.PointHit = (rayWS.Position + (rayWS.Direction * d)).ToPoint3D(); result.Distance = d; var n = Vector3.Cross(p1 - p0, p2 - p0); n.Normalize(); // transform hit-info to world space now: result.NormalAtHit = n.ToVector3D();// Vector3.TransformNormal(n, m).ToVector3D(); } h = true; } } } } if (h) { result.IsValid = h; hits.Add(result); } return h; }
public Mouse3DEventArgs(RoutedEvent routedEvent, object source, HitTestResult hitTestResult, Point position, Viewport3DX viewport = null) : base(routedEvent, source) { this.HitTestResult = hitTestResult; this.Position = position; this.Viewport = viewport; }