■ 파노라마 뷰 사용하기
------------------------------------------------------------------------------------------------------------------------
▶ PanoramaViewer.cs
using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Media3D;
namespace TestProject { /// <summary> /// 파노라마 뷰어 /// </summary> public class PanoramaViewer : Viewport3D { //////////////////////////////////////////////////////////////////////////////////////////////////// Dependency Property ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public
#region 시야각 속성 - FieldOfViewProperty
/// <summary> /// 시야각 속성 /// </summary> public static readonly DependencyProperty FieldOfViewProperty = DependencyProperty.Register ( "FieldOfView", typeof(double), typeof(PanoramaViewer), new PropertyMetadata ( (double)0, new PropertyChangedCallback(FieldOfViewPropertyChangedCallback) ) );
#endregion #region X축 회전 속성 - RotationXProperty
/// <summary> /// X축 회전 속성 /// </summary> public static readonly DependencyProperty RotationXProperty = DependencyProperty.Register ( "RotationX", typeof(double), typeof(PanoramaViewer), new UIPropertyMetadata ( 0.0, (d, e) => ((PanoramaViewer)d).UpdateRotation() ) );
#endregion #region Y축 회전 속성 - RotationYProperty
/// <summary> /// Y축 회전 속성 /// </summary> public static readonly DependencyProperty RotationYProperty = DependencyProperty.Register ( "RotationY", typeof(double), typeof(PanoramaViewer), new UIPropertyMetadata ( 0.0, (d, e) => ((PanoramaViewer)d).UpdateRotation() ) );
#endregion #region Z축 회전 속성 - RotationZProperty
/// <summary> /// Z축 회전 속성 /// </summary> public static readonly DependencyProperty RotationZProperty = DependencyProperty.Register ( "RotationZ", typeof(double), typeof(PanoramaViewer), new UIPropertyMetadata ( 0.0, (d, e) => ((PanoramaViewer)d).UpdateRotation() ) );
#endregion #region 파노라마 이미지 속성 - PanoramaImageProperty
/// <summary> /// 파노라마 이미지 속성 /// </summary> public static readonly DependencyProperty PanoramaImageProperty = DependencyProperty.Register ( "PanoramaImage", typeof(ImageSource), typeof(PanoramaViewer), new PropertyMetadata ( null, new PropertyChangedCallback(PanoramaImagePropertyChangedCallback) ) );
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary> /// X축 벡터 /// </summary> private static readonly Vector3D _xAxisVector = new Vector3D(1, 0, 0);
/// <summary> /// Y축 벡터 /// </summary> private static readonly Vector3D _yAxisVector = new Vector3D(0, 1, 0);
/// <summary> /// Z축 벡터 /// </summary> private static readonly Vector3D _zAxisVector = new Vector3D(0, 0, 1);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 시야각 - FieldOfView
/// <summary> /// 시야각 /// </summary> public double FieldOfView { get { return (double)GetValue(FieldOfViewProperty); } set { SetValue(FieldOfViewProperty, value); } }
#endregion #region X축 회전 - RotationX
/// <summary> /// X축 회전 /// </summary> public double RotationX { get { return (double)GetValue(RotationXProperty); } set { SetValue(RotationXProperty, value); } }
#endregion #region Y축 회전 - RotationY
/// <summary> /// Y축 회전 /// </summary> public double RotationY { get { return (double)GetValue(RotationYProperty); } set { SetValue(RotationYProperty, value); } }
#endregion #region Z축 회전 - RotationZ
/// <summary> /// Z축 회전 /// </summary> public double RotationZ { get { return (double)GetValue(RotationZProperty); } set { SetValue(RotationZProperty, value); } }
#endregion #region 파노라마 이미지 - PanoramaImage
/// <summary> /// 파노라마 이미지 /// </summary> public ImageSource PanoramaImage { get { return (ImageSource)GetValue(PanoramaImageProperty); } set { SetValue(PanoramaImageProperty, value); } }
#endregion
#region 파노라마 객체 - PanoramaObject
/// <summary> /// 파노라마 객체 /// </summary> public ModelVisual3D PanoramaObject { get; set; }
#endregion #region 파노라마 지오메트리 - PanoramaGeometry
/// <summary> /// 파노라마 지오메트리 /// </summary> public GeometryModel3D PanoramaGeometry { get; set; }
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 파노라마 회전 - PanoramaRotation
/// <summary> /// 파노라마 회전 /// </summary> private QuaternionRotation3D PanoramaRotation { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - PanoramaViewer()
/// <summary> /// 생성자 /// </summary> public PanoramaViewer() { InitializeViewer(); }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private
#region 시야각 속성 변경시 콜백 처리하기 - FieldOfViewPropertyChangedCallback(sender, e)
/// <summary> /// 시야각 속성 변경시 콜백 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private static void FieldOfViewPropertyChangedCallback(object sender, DependencyPropertyChangedEventArgs e) { PanoramaViewer viewer = sender as PanoramaViewer;
PerspectiveCamera camera = viewer.Camera as PerspectiveCamera;
camera.FieldOfView = viewer.FieldOfView; }
#endregion #region 파노라마 이미지 속성 변경시 콜백 처리하기 - PanoramaImagePropertyChangedCallback(sender, e)
/// <summary> /// 파노라마 이미지 속성 변경시 콜백 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private static void PanoramaImagePropertyChangedCallback(object sender, DependencyPropertyChangedEventArgs e) { PanoramaViewer viewer = sender as PanoramaViewer;
ImageBrush brush = new ImageBrush(viewer.PanoramaImage);
viewer.PanoramaGeometry.BackMaterial = new DiffuseMaterial(brush); }
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Instance //////////////////////////////////////////////////////////////////////////////// Private
#region 위치 구하기 - GetPosition(theta, y)
/// <summary> /// 위치 구하기 /// </summary> /// <param name="theta">세타</param> /// <param name="y">Y</param> /// <returns>위치</returns> private Point3D GetPosition(double theta, double y) { double r = Math.Sqrt(1 - y * y); double x = r * Math.Cos(theta); double z = r * Math.Sin(theta);
return new Point3D(x, y, z); }
#endregion #region 법선 벡터 구하기 - GetNormalVector(t, y)
/// <summary> /// 법선 벡터 구하기 /// </summary> /// <param name="t">T</param> /// <param name="y">Y</param> /// <returns>법선</returns> private Vector3D GetNormalVector(double t, double y) { return (Vector3D)GetPosition(t, y); }
#endregion #region 텍스처 좌표 구하기 - GetTextureCoordinate(t, y)
/// <summary> /// 텍스처 좌표 구하기 /// </summary> /// <param name="t"& |