Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media3D / RayHitTestParameters.cs / 1305600 / RayHitTestParameters.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // History: // 03/16/2004 : [....] - Created // //--------------------------------------------------------------------------- using System; using System.IO; using System.Diagnostics; using System.Collections.Generic; using MS.Internal.Media3D; using CultureInfo = System.Globalization.CultureInfo; namespace System.Windows.Media.Media3D { ////// Encapsulates a set parameters for performing a 3D hit test agaist /// a ray. /// public sealed class RayHitTestParameters : HitTestParameters3D { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructors ////// Creates a RayHitTestParameters where the ray is described /// by an origin and a direction. /// public RayHitTestParameters(Point3D origin, Vector3D direction) { _origin = origin; _direction = direction; _isRay = true; } #endregion Constructors //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- //------------------------------------------------------ // // Public Properties // //------------------------------------------------------ #region Public Properties ////// The origin of the ray to be used for hit testing. /// public Point3D Origin { get { return _origin; } } ////// The direction of the ray to be used for hit testing. /// public Vector3D Direction { get { return _direction; } } #endregion Public Properties //----------------------------------------------------- // // Public Events // //------------------------------------------------------ //----------------------------------------------------- // // Internal Methods // //----------------------------------------------------- #region Internal Methods internal void ReportResult( MeshGeometry3D meshHit, Point3D pointHit, double distanceToRayOrigin, int vertexIndex1, int vertexIndex2, int vertexIndex3, Point barycentric) { results.Add(new RayMeshGeometry3DHitTestResult( CurrentVisual, CurrentModel, meshHit, pointHit, distanceToRayOrigin, vertexIndex1, vertexIndex2, vertexIndex3, barycentric)); } internal HitTestResultBehavior RaiseCallback(HitTestResultCallback resultCallback, HitTestFilterCallback filterCallback, HitTestResultBehavior lastResult) { return RaiseCallback(resultCallback, filterCallback, lastResult, 0.0 /* distance adjustment */); } internal HitTestResultBehavior RaiseCallback(HitTestResultCallback resultCallback, HitTestFilterCallback filterCallback, HitTestResultBehavior lastResult, double distanceAdjustment) { results.Sort(RayHitTestResult.CompareByDistanceToRayOrigin); for(int i = 0, count = results.Count; i < count; i++) { RayHitTestResult result = results[i]; result.SetDistanceToRayOrigin(result.DistanceToRayOrigin + distanceAdjustment); Viewport2DVisual3D viewport2DVisual3D = result.VisualHit as Viewport2DVisual3D; if (viewport2DVisual3D != null) { Point intersectionPoint; Visual viewport2DVisual3DChild = viewport2DVisual3D.Visual; if (viewport2DVisual3DChild != null) { if (Viewport2DVisual3D.GetIntersectionInfo(result, out intersectionPoint)) { // convert the resulting point to visual coordinates Point visualPoint = Viewport2DVisual3D.TextureCoordsToVisualCoords(intersectionPoint, viewport2DVisual3DChild); GeneralTransform gt = viewport2DVisual3DChild.TransformToOuterSpace().Inverse; Point pointOnChild; if (gt != null && gt.TryTransform(visualPoint, out pointOnChild)) { HitTestResultBehavior behavior2D = viewport2DVisual3DChild.HitTestPoint(filterCallback, resultCallback, new PointHitTestParameters(pointOnChild)); if (behavior2D == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } } } } HitTestResultBehavior behavior = resultCallback(results[i]); if (behavior == HitTestResultBehavior.Stop) { return HitTestResultBehavior.Stop; } } return lastResult; } // Gets the hit testing line/ray specified as an origin and direction in // the current local space. internal void GetLocalLine(out Point3D origin, out Vector3D direction) { origin = _origin; direction = _direction; bool isRay = true; if (HasWorldTransformMatrix) { LineUtil.Transform(WorldTransformMatrix, ref origin, ref direction, out isRay); } // At any point along the tree walk we may encounter a transform that turns the ray into // a line and if so we must stay a line _isRay &= isRay; } internal void ClearResults() { if (results != null) { results.Clear(); } } #endregion Internal Methods internal bool IsRay { get { return _isRay; } } //----------------------------------------------------- // // Private Fields // //------------------------------------------------------ #region Private Fields private readonly Point3D _origin; private readonly Vector3D _direction; private readonly Listresults = new List (); // 'true' if this is a ray hit test, 'false' if the ray has become a line private bool _isRay; #endregion Private Fields } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ExceptionValidationRule.cs
- FormsAuthenticationTicket.cs
- OleDbDataReader.cs
- DrawingContext.cs
- AssemblyEvidenceFactory.cs
- XmlArrayItemAttributes.cs
- WinEventTracker.cs
- MenuItemStyle.cs
- LazyLoadBehavior.cs
- ImplicitInputBrush.cs
- OledbConnectionStringbuilder.cs
- SecurityChannel.cs
- Attributes.cs
- ValidatorCompatibilityHelper.cs
- PropertyChangingEventArgs.cs
- Timer.cs
- BlurBitmapEffect.cs
- Rect.cs
- GridViewSelectEventArgs.cs
- ComponentResourceKey.cs
- EdmEntityTypeAttribute.cs
- Debug.cs
- ProfileSettings.cs
- remotingproxy.cs
- XmlTextReader.cs
- SecuritySessionSecurityTokenProvider.cs
- Button.cs
- ConfigsHelper.cs
- SymbolEqualComparer.cs
- InputMethodStateTypeInfo.cs
- ReadOnlyCollectionBase.cs
- SqlFileStream.cs
- XmlReader.cs
- XmlHierarchicalDataSourceView.cs
- EventDescriptorCollection.cs
- SystemThemeKey.cs
- Model3DGroup.cs
- PeerEndPoint.cs
- CharAnimationBase.cs
- SiteMap.cs
- CodeDomExtensionMethods.cs
- ConfigurationValues.cs
- LocationUpdates.cs
- MetadataSerializer.cs
- FlowNode.cs
- IxmlLineInfo.cs
- DodSequenceMerge.cs
- MarginCollapsingState.cs
- EnumerableWrapperWeakToStrong.cs
- QueryConverter.cs
- AsyncStreamReader.cs
- SchemaTableColumn.cs
- FlowDocumentPaginator.cs
- SqlHelper.cs
- OptimalBreakSession.cs
- ListControlDesigner.cs
- DataSetFieldSchema.cs
- XPathItem.cs
- CanonicalizationDriver.cs
- DesignerMetadata.cs
- HttpWriter.cs
- IsolatedStorageFile.cs
- PlaceHolder.cs
- PersonalizablePropertyEntry.cs
- ReadingWritingEntityEventArgs.cs
- PowerStatus.cs
- SecurityKeyIdentifierClause.cs
- OracleRowUpdatingEventArgs.cs
- WhiteSpaceTrimStringConverter.cs
- State.cs
- ReflectEventDescriptor.cs
- Dictionary.cs
- StylusButtonCollection.cs
- ListViewGroup.cs
- MetadataProperty.cs
- HeaderElement.cs
- MachineKeyValidationConverter.cs
- Stream.cs
- DataMisalignedException.cs
- SymbolEqualComparer.cs
- SmtpNtlmAuthenticationModule.cs
- IgnoreSectionHandler.cs
- TimeoutException.cs
- LinearKeyFrames.cs
- mda.cs
- ReflectEventDescriptor.cs
- HostedBindingBehavior.cs
- ListParagraph.cs
- DbFunctionCommandTree.cs
- SystemIPInterfaceStatistics.cs
- CreateUserWizardDesigner.cs
- X509SubjectKeyIdentifierClause.cs
- OrderingQueryOperator.cs
- DBSchemaRow.cs
- shaperfactory.cs
- XPathDescendantIterator.cs
- FunctionNode.cs
- HorizontalAlignConverter.cs
- GridEntry.cs
- Internal.cs