Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Media3D / GeneralTransform2DTo3D.cs / 1305600 / GeneralTransform2DTo3D.cs
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Declaration of the GeneralTransform2DTo3D class.
//
//---------------------------------------------------------------------------
using System.Diagnostics;
using System.Windows.Media;
using System.Windows.Media.Animation;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.Media3D
{
///
/// TransformTo3D class provides services to transform points from 2D in to 3D
///
public class GeneralTransform2DTo3D : Freezable
{
internal GeneralTransform2DTo3D()
{
}
internal GeneralTransform2DTo3D(GeneralTransform transform2D,
Viewport2DVisual3D containingVisual3D,
GeneralTransform3D transform3D)
{
Visual child = containingVisual3D.Visual;
Debug.Assert(child != null, "Going from 2D to 3D containingVisual3D.Visual should not be null");
_transform3D = (GeneralTransform3D)transform3D.GetCurrentValueAsFrozen();
// we also need to go one more level up to handle a transform being placed
// on the Viewport2DVisual3D's child
GeneralTransformGroup transformGroup = new GeneralTransformGroup();
transformGroup.Children.Add((GeneralTransform)transform2D.GetCurrentValueAsFrozen());
transformGroup.Children.Add((GeneralTransform)child.TransformToOuterSpace().GetCurrentValueAsFrozen());
transformGroup.Freeze();
_transform2D = transformGroup;
_positions = containingVisual3D.InternalPositionsCache;
_textureCoords = containingVisual3D.InternalTextureCoordinatesCache;
_triIndices = containingVisual3D.InternalTriangleIndicesCache;
_childBounds = child.CalculateSubgraphRenderBoundsOuterSpace();
}
///
/// Transform a point
///
/// Input point
/// Output point
/// True if the point was transformed successfuly, false otherwise
public bool TryTransform(Point inPoint, out Point3D result)
{
Point final2DPoint;
// assign this now so that we can return false if needed
result = new Point3D();
if (!_transform2D.TryTransform(inPoint, out final2DPoint))
{
return false;
}
Point texCoord = Viewport2DVisual3D.VisualCoordsToTextureCoords(final2DPoint, _childBounds);
// need to walk the texture coordinates on the Viewport2DVisual3D
// and look for where this point intersects one of them
Point3D coordPoint;
if (!Viewport2DVisual3D.Get3DPointFor2DCoordinate(texCoord,
out coordPoint,
_positions,
_textureCoords,
_triIndices))
{
return false;
}
if (!_transform3D.TryTransform(coordPoint, out result))
{
return false;
}
return true;
}
///
/// Transform a point from 2D in to 3D
///
/// If the transformation does not succeed, this will throw an InvalidOperationException.
/// If you don't want to try/catch, call TryTransform instead and check the boolean it
/// returns.
///
///
/// Input point
/// The transformed point
public Point3D Transform(Point point)
{
Point3D transformedPoint;
if (!TryTransform(point, out transformedPoint))
{
throw new InvalidOperationException(SR.Get(SRID.GeneralTransform_TransformFailed, null));
}
return transformedPoint;
}
///
/// Implementation of Freezable.CreateInstanceCore .
///
/// The new Freezable.
protected override Freezable CreateInstanceCore()
{
return new GeneralTransform2DTo3D();
}
///
/// Implementation of Freezable.CloneCore .
///
///
protected override void CloneCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.CloneCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.CloneCurrentValueCore .
///
///
protected override void CloneCurrentValueCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.CloneCurrentValueCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.GetAsFrozenCore .
///
///
protected override void GetAsFrozenCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.GetAsFrozenCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.GetCurrentValueAsFrozenCore .
///
///
protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.GetCurrentValueAsFrozenCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Clones values that do not have corresponding DPs
///
///
private void CopyCommon(GeneralTransform2DTo3D transform)
{
_transform2D = transform._transform2D;
_transform3D = transform._transform3D;
_positions = transform._positions;
_textureCoords = transform._textureCoords;
_triIndices = transform._triIndices;
_childBounds = transform._childBounds;
}
private GeneralTransform _transform2D;
private GeneralTransform3D _transform3D;
private Point3DCollection _positions;
private PointCollection _textureCoords;
private Int32Collection _triIndices;
private Rect _childBounds;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
//
// Description: Declaration of the GeneralTransform2DTo3D class.
//
//---------------------------------------------------------------------------
using System.Diagnostics;
using System.Windows.Media;
using System.Windows.Media.Animation;
using SR = MS.Internal.PresentationCore.SR;
using SRID = MS.Internal.PresentationCore.SRID;
namespace System.Windows.Media.Media3D
{
///
/// TransformTo3D class provides services to transform points from 2D in to 3D
///
public class GeneralTransform2DTo3D : Freezable
{
internal GeneralTransform2DTo3D()
{
}
internal GeneralTransform2DTo3D(GeneralTransform transform2D,
Viewport2DVisual3D containingVisual3D,
GeneralTransform3D transform3D)
{
Visual child = containingVisual3D.Visual;
Debug.Assert(child != null, "Going from 2D to 3D containingVisual3D.Visual should not be null");
_transform3D = (GeneralTransform3D)transform3D.GetCurrentValueAsFrozen();
// we also need to go one more level up to handle a transform being placed
// on the Viewport2DVisual3D's child
GeneralTransformGroup transformGroup = new GeneralTransformGroup();
transformGroup.Children.Add((GeneralTransform)transform2D.GetCurrentValueAsFrozen());
transformGroup.Children.Add((GeneralTransform)child.TransformToOuterSpace().GetCurrentValueAsFrozen());
transformGroup.Freeze();
_transform2D = transformGroup;
_positions = containingVisual3D.InternalPositionsCache;
_textureCoords = containingVisual3D.InternalTextureCoordinatesCache;
_triIndices = containingVisual3D.InternalTriangleIndicesCache;
_childBounds = child.CalculateSubgraphRenderBoundsOuterSpace();
}
///
/// Transform a point
///
/// Input point
/// Output point
/// True if the point was transformed successfuly, false otherwise
public bool TryTransform(Point inPoint, out Point3D result)
{
Point final2DPoint;
// assign this now so that we can return false if needed
result = new Point3D();
if (!_transform2D.TryTransform(inPoint, out final2DPoint))
{
return false;
}
Point texCoord = Viewport2DVisual3D.VisualCoordsToTextureCoords(final2DPoint, _childBounds);
// need to walk the texture coordinates on the Viewport2DVisual3D
// and look for where this point intersects one of them
Point3D coordPoint;
if (!Viewport2DVisual3D.Get3DPointFor2DCoordinate(texCoord,
out coordPoint,
_positions,
_textureCoords,
_triIndices))
{
return false;
}
if (!_transform3D.TryTransform(coordPoint, out result))
{
return false;
}
return true;
}
///
/// Transform a point from 2D in to 3D
///
/// If the transformation does not succeed, this will throw an InvalidOperationException.
/// If you don't want to try/catch, call TryTransform instead and check the boolean it
/// returns.
///
///
/// Input point
/// The transformed point
public Point3D Transform(Point point)
{
Point3D transformedPoint;
if (!TryTransform(point, out transformedPoint))
{
throw new InvalidOperationException(SR.Get(SRID.GeneralTransform_TransformFailed, null));
}
return transformedPoint;
}
///
/// Implementation of Freezable.CreateInstanceCore .
///
/// The new Freezable.
protected override Freezable CreateInstanceCore()
{
return new GeneralTransform2DTo3D();
}
///
/// Implementation of Freezable.CloneCore .
///
///
protected override void CloneCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.CloneCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.CloneCurrentValueCore .
///
///
protected override void CloneCurrentValueCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.CloneCurrentValueCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.GetAsFrozenCore .
///
///
protected override void GetAsFrozenCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.GetAsFrozenCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Implementation of Freezable.GetCurrentValueAsFrozenCore .
///
///
protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
{
GeneralTransform2DTo3D transform = (GeneralTransform2DTo3D)sourceFreezable;
base.GetCurrentValueAsFrozenCore(sourceFreezable);
CopyCommon(transform);
}
///
/// Clones values that do not have corresponding DPs
///
///
private void CopyCommon(GeneralTransform2DTo3D transform)
{
_transform2D = transform._transform2D;
_transform3D = transform._transform3D;
_positions = transform._positions;
_textureCoords = transform._textureCoords;
_triIndices = transform._triIndices;
_childBounds = transform._childBounds;
}
private GeneralTransform _transform2D;
private GeneralTransform3D _transform3D;
private Point3DCollection _positions;
private PointCollection _textureCoords;
private Int32Collection _triIndices;
private Rect _childBounds;
}
}
// 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
- activationcontext.cs
- HashCodeCombiner.cs
- ByteAnimationBase.cs
- BooleanFunctions.cs
- BindingMAnagerBase.cs
- DataGridViewComboBoxEditingControl.cs
- TextBoxAutoCompleteSourceConverter.cs
- ManageRequest.cs
- Tokenizer.cs
- ClientSettingsProvider.cs
- ExceptionHelpers.cs
- BaseParser.cs
- FileLevelControlBuilderAttribute.cs
- SqlHelper.cs
- SqlExpander.cs
- SecurityCriticalDataForSet.cs
- HttpCacheParams.cs
- Cell.cs
- StoreItemCollection.cs
- ViewCellRelation.cs
- CallContext.cs
- DataGridCellsPanel.cs
- KeyedCollection.cs
- RefType.cs
- TextBox.cs
- RegexFCD.cs
- InProcStateClientManager.cs
- StaticFileHandler.cs
- PrintDocument.cs
- StrokeCollection2.cs
- DesignerLoader.cs
- Fx.cs
- Directory.cs
- SuppressMergeCheckAttribute.cs
- XhtmlMobileTextWriter.cs
- StaticExtension.cs
- CodeNamespace.cs
- AssemblyAssociatedContentFileAttribute.cs
- DigitShape.cs
- CalendarTable.cs
- _SslStream.cs
- TextTabProperties.cs
- ObjectHandle.cs
- LinkUtilities.cs
- SchemaMerger.cs
- XomlCompilerError.cs
- NamedServiceModelExtensionCollectionElement.cs
- WebServiceTypeData.cs
- _ShellExpression.cs
- Span.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- CanonicalFontFamilyReference.cs
- AuthenticationSection.cs
- WebChannelFactory.cs
- IsolatedStorageException.cs
- SetStateDesigner.cs
- SamlAuthenticationClaimResource.cs
- _AutoWebProxyScriptHelper.cs
- XmlReflectionImporter.cs
- Soap12ProtocolImporter.cs
- RelationshipDetailsCollection.cs
- EntityDataSourceReferenceGroup.cs
- Missing.cs
- WhileDesigner.cs
- QueryOpeningEnumerator.cs
- WebPartConnectionCollection.cs
- WSHttpTransportSecurityElement.cs
- WeakHashtable.cs
- GenericTransactionFlowAttribute.cs
- UniqueConstraint.cs
- WorkflowMessageEventArgs.cs
- EventData.cs
- autovalidator.cs
- TextEditorDragDrop.cs
- PropertyChangeTracker.cs
- DifferencingCollection.cs
- TimerElapsedEvenArgs.cs
- AesCryptoServiceProvider.cs
- WindowsEditBoxRange.cs
- CodeCommentStatementCollection.cs
- ObjectItemLoadingSessionData.cs
- TypeLoadException.cs
- ProcessProtocolHandler.cs
- HostingEnvironmentSection.cs
- WebPartUserCapability.cs
- IxmlLineInfo.cs
- ContextMenu.cs
- SqlCrossApplyToCrossJoin.cs
- InkCollectionBehavior.cs
- BinaryFormatter.cs
- VirtualPathData.cs
- Panel.cs
- PersonalizableAttribute.cs
- Int64KeyFrameCollection.cs
- DataViewSettingCollection.cs
- XmlObjectSerializerWriteContextComplex.cs
- CollectionViewGroupRoot.cs
- MsmqBindingMonitor.cs
- OdbcParameterCollection.cs
- ResourceContainer.cs