Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Media3D;
  13. using System.Windows.Media.Animation;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17.  
  18.  
  19. namespace WpfApplication1
  20. {
  21. /// <summary>
  22. /// Логика взаимодействия для MainWindow.xaml
  23. /// </summary>
  24. public partial class MainWindow : Window
  25. {
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. }
  30.  
  31. private void Window_Loaded(object sender, RoutedEventArgs e)
  32.  
  33. {
  34.  
  35. // Declare scene objects.
  36.  
  37. Viewport3D myViewport3D = new Viewport3D();
  38.  
  39. Model3DGroup myModel3DGroup = new Model3DGroup();
  40.  
  41. GeometryModel3D myGeometryModel = new GeometryModel3D();
  42.  
  43. ModelVisual3D myModelVisual3D = new ModelVisual3D();
  44.  
  45. OrthographicCamera myOCamera = new OrthographicCamera(new Point3D(0, 0, 5), new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), 8);
  46.  
  47. myViewport3D.Camera = myOCamera;
  48.  
  49. DirectionalLight myDirectionalLight = new DirectionalLight();
  50.  
  51. myDirectionalLight.Color = Colors.White;
  52.  
  53. myDirectionalLight.Direction = new Vector3D(0, 0, -5);
  54.  
  55. myModel3DGroup.Children.Add(myDirectionalLight);
  56.  
  57. // The geometry specifes the shape of the 3D plane. In this sample, a flat sheet
  58.  
  59. // is created.
  60.  
  61. MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D();
  62.  
  63. // Create a collection of normal vectors for the MeshGeometry3D.
  64.  
  65. Vector3DCollection myNormalCollection = new Vector3DCollection();
  66.  
  67. myNormalCollection.Add(new Vector3D(0, 0, 1));
  68. myNormalCollection.Add(new Vector3D(0, 0, 1));
  69. myNormalCollection.Add(new Vector3D(0, 0, 1));
  70. myNormalCollection.Add(new Vector3D(0, 0, 1));
  71. myNormalCollection.Add(new Vector3D(0, 0, 1));
  72. myNormalCollection.Add(new Vector3D(0, 0, 1));
  73.  
  74. myMeshGeometry3D.Normals = myNormalCollection;
  75.  
  76. // Create a collection of vertex positions for the MeshGeometry3D.
  77.  
  78. Point3DCollection myPositionCollection = new Point3DCollection();
  79.  
  80. myPositionCollection.Add(new Point3D(0.0, 1.0, 1.0));
  81. myPositionCollection.Add(new Point3D(1.0, 1.0, 1.0));
  82. myPositionCollection.Add(new Point3D(1.0, 1.0, 0.0));
  83. myPositionCollection.Add(new Point3D(0.0, 1.0, 0.0));
  84. myPositionCollection.Add(new Point3D(0.0, 0.0, 1.0));
  85. myPositionCollection.Add(new Point3D(1.0, 0.0, 1.0));
  86. myPositionCollection.Add(new Point3D(1.0, 0.0, 0.0));
  87. myPositionCollection.Add(new Point3D(0.0, 0.0, 0.0));
  88.  
  89.  
  90. myMeshGeometry3D.Positions = myPositionCollection;
  91.  
  92. // Create a collection of triangle indices for the MeshGeometry3D.
  93.  
  94. Int32Collection myTriangleIndicesCollection = new Int32Collection();
  95.  
  96. myTriangleIndicesCollection.Add(0);
  97. myTriangleIndicesCollection.Add(1);
  98. myTriangleIndicesCollection.Add(2);
  99.  
  100. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  101. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  102. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  103. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  104. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));
  105. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  106.  
  107. myTriangleIndicesCollection.Add(2);
  108. myTriangleIndicesCollection.Add(3);
  109. myTriangleIndicesCollection.Add(0);
  110.  
  111. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  112. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  113. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  114. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  115. myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));
  116. myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  117.  
  118. myTriangleIndicesCollection.Add(4);
  119. myTriangleIndicesCollection.Add(7);
  120. myTriangleIndicesCollection.Add(6);
  121.  
  122. myTriangleIndicesCollection.Add(6);
  123. myTriangleIndicesCollection.Add(5);
  124. myTriangleIndicesCollection.Add(4);
  125.  
  126. myTriangleIndicesCollection.Add(0);
  127. myTriangleIndicesCollection.Add(4);
  128. myTriangleIndicesCollection.Add(5);
  129.  
  130. myTriangleIndicesCollection.Add(5);
  131. myTriangleIndicesCollection.Add(1);
  132. myTriangleIndicesCollection.Add(0);
  133.  
  134. myTriangleIndicesCollection.Add(1);
  135. myTriangleIndicesCollection.Add(5);
  136. myTriangleIndicesCollection.Add(6);
  137.  
  138. myTriangleIndicesCollection.Add(6);
  139. myTriangleIndicesCollection.Add(2);
  140. myTriangleIndicesCollection.Add(1);
  141.  
  142. myTriangleIndicesCollection.Add(2);
  143. myTriangleIndicesCollection.Add(6);
  144. myTriangleIndicesCollection.Add(7);
  145.  
  146. myTriangleIndicesCollection.Add(7);
  147. myTriangleIndicesCollection.Add(3);
  148. myTriangleIndicesCollection.Add(2);
  149.  
  150. myTriangleIndicesCollection.Add(0);
  151. myTriangleIndicesCollection.Add(3);
  152. myTriangleIndicesCollection.Add(7);
  153.  
  154. myTriangleIndicesCollection.Add(7);
  155. myTriangleIndicesCollection.Add(4);
  156. myTriangleIndicesCollection.Add(0);
  157.  
  158. myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection;
  159.  
  160. // Apply the mesh to the geometry model.
  161.  
  162. myGeometryModel.Geometry = myMeshGeometry3D;
  163.  
  164. // Define material and apply to the mesh geometries.
  165.  
  166.  
  167.  
  168. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  169. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  170. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  171. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  172. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  173. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  174.  
  175. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  176. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  177. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  178. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  179. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));
  180. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  181.  
  182. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  183. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));
  184. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  185. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));
  186. //myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));
  187. //myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));
  188.  
  189. BitmapImage bm1 = new BitmapImage();
  190. bm1.BeginInit();
  191. bm1.UriSource = new Uri("f.jpg", UriKind.Relative);
  192. bm1.EndInit();
  193. ImageBrush imgBrush = new ImageBrush(bm1);
  194. DiffuseMaterial myMaterial = new DiffuseMaterial(imgBrush);
  195. myMaterial = new DiffuseMaterial(imgBrush);
  196. myGeometryModel.Material = myMaterial;
  197. //TranslateTransform3D myTranslateTransform3D = new TranslateTransform3D();
  198. //DoubleAnimation xAnim = new DoubleAnimation();
  199. //xAnim.From = -1;
  200. //xAnim.To = 1;
  201. //xAnim.RepeatBehavior = new RepeatBehavior(200);
  202. //xAnim.Duration = TimeSpan.FromSeconds(4);
  203. //xAnim.AutoReverse = true;
  204. //myTranslateTransform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnim);
  205. //myGeometryModel.Transform = myTranslateTransform3D;
  206. //myModel3DGroup.Children.Add(myGeometryModel);
  207. //myModelVisual3D.Content = myModel3DGroup;
  208. ////myViewport3D.Children.Add(myModelVisual3D);
  209.  
  210. //DiffuseMaterial myMaterial = new DiffuseMaterial(Brushes.Blue);
  211.  
  212. //myGeometryModel.Material = myMaterial;
  213.  
  214. RotateTransform3D myRotateTransform3D = new RotateTransform3D();
  215.  
  216. Quaternion q1 = new Quaternion(new Vector3D(1, 1, 1), 45);
  217.  
  218. QuaternionRotation3D myQuaternionRotation3D1 = new QuaternionRotation3D(q1);
  219.  
  220. myRotateTransform3D.Rotation = myQuaternionRotation3D1;
  221.  
  222. myGeometryModel.Transform = myRotateTransform3D;
  223.  
  224. QuaternionAnimation qa = new QuaternionAnimation(new Quaternion(new Vector3D(1, 1, 1), 0), new Quaternion(new Vector3D(1, 1, 1), 359), new Duration(TimeSpan.FromSeconds(1)));
  225.  
  226. qa.UseShortestPath = false;
  227.  
  228. qa.RepeatBehavior = RepeatBehavior.Forever;
  229.  
  230.  
  231. myRotateTransform3D.Rotation.BeginAnimation(QuaternionRotation3D.QuaternionProperty, qa);
  232.  
  233.  
  234.  
  235. myModel3DGroup.Children.Add(myGeometryModel);
  236. myModelVisual3D.Content = myModel3DGroup;
  237. myViewport3D.Children.Add(myModelVisual3D);
  238.  
  239.  
  240. this.Content = myViewport3D;
  241.  
  242. }
  243.  
  244.  
  245. }
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement