using System using System Collections Generic using System Linq using

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
// Declare scene objects.
Viewport3D myViewport3D = new Viewport3D();
Model3DGroup myModel3DGroup = new Model3DGroup();
GeometryModel3D myGeometryModel = new GeometryModel3D();
ModelVisual3D myModelVisual3D = new ModelVisual3D();
//PerspectiveCamera myPCamera = new PerspectiveCamera();
//myPCamera.Position = new Point3D(0, 0, 1);
//myPCamera.LookDirection = new Vector3D(0, 0, -1);
OrthographicCamera myOCamera = new OrthographicCamera(new Point3D(0, 0, 1), new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), 8);
myViewport3D.Camera = myOCamera;
DirectionalLight myDirectionalLight = new DirectionalLight();
myDirectionalLight.Color = Colors.White;
myDirectionalLight.Direction = new Vector3D(-0, -0, -3);
myModel3DGroup.Children.Add(myDirectionalLight);
// The geometry specifes the shape of the 3D plane. In this sample, a flat sheet
// is created.
MeshGeometry3D myMeshGeometry3D = new MeshGeometry3D();
// Create a collection of normal vectors for the MeshGeometry3D.
Vector3DCollection myNormalCollection = new Vector3DCollection();
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myNormalCollection.Add(new Vector3D(0, 0, 1));
myMeshGeometry3D.Normals = myNormalCollection;
// Create a collection of vertex positions for the MeshGeometry3D.
Point3DCollection myPositionCollection = new Point3DCollection();
myPositionCollection.Add(new Point3D(0.0, 0.0, 0.0));
myPositionCollection.Add(new Point3D(1.0, 0.0, 0.0));
myPositionCollection.Add(new Point3D(1.0, 1.0, 0.0));
myPositionCollection.Add(new Point3D(0.0, 1.0, 0.0));
myPositionCollection.Add(new Point3D(0.0, 0.0, 1.0));
myPositionCollection.Add(new Point3D(1.0, 0.0, 1.0));
myPositionCollection.Add(new Point3D(1.0, 1.0, 1.0));
myPositionCollection.Add(new Point3D(0.0, 1.0, 1.0));
myMeshGeometry3D.Positions = myPositionCollection;
// Create a collection of triangle indices for the MeshGeometry3D.
Int32Collection myTriangleIndicesCollection = new Int32Collection();
myTriangleIndicesCollection.Add(1);
myTriangleIndicesCollection.Add(2);
myTriangleIndicesCollection.Add(6);
myTriangleIndicesCollection.Add(1);
myTriangleIndicesCollection.Add(6);
myTriangleIndicesCollection.Add(5);
myTriangleIndicesCollection.Add(5);
myTriangleIndicesCollection.Add(7);
myTriangleIndicesCollection.Add(4);
myTriangleIndicesCollection.Add(5);
myTriangleIndicesCollection.Add(6);
myTriangleIndicesCollection.Add(7);
myTriangleIndicesCollection.Add(3);
myTriangleIndicesCollection.Add(6);
myTriangleIndicesCollection.Add(7);
myTriangleIndicesCollection.Add(3);
myTriangleIndicesCollection.Add(2);
myTriangleIndicesCollection.Add(6);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(3);
myTriangleIndicesCollection.Add(7);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(7);
myTriangleIndicesCollection.Add(4);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(2);
myTriangleIndicesCollection.Add(3);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(1);
myTriangleIndicesCollection.Add(2);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(1);
myTriangleIndicesCollection.Add(5);
myTriangleIndicesCollection.Add(0);
myTriangleIndicesCollection.Add(5);
myTriangleIndicesCollection.Add(4);
myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection;
// Apply the mesh to the geometry model.
myGeometryModel.Geometry = myMeshGeometry3D;
// Define material and apply to the mesh geometries.
DiffuseMaterial myMaterial = new DiffuseMaterial(Brushes.Green);
myGeometryModel.Material = myMaterial;
RotateTransform3D myRotateTransform3D = new RotateTransform3D();
AxisAngleRotation3D myAxisAngleRotation3d = new AxisAngleRotation3D();
myAxisAngleRotation3d.Axis = new Vector3D(0, 3, 0);
myAxisAngleRotation3d.Angle = 45;
myRotateTransform3D.Rotation = myAxisAngleRotation3d;
myGeometryModel.Transform = myRotateTransform3D;
Vector3DAnimation myVectorAnimation = new Vector3DAnimation(new Vector3D(-1, -1, -1), new Duration(TimeSpan.FromMilliseconds(2000)));
myVectorAnimation.RepeatBehavior = RepeatBehavior.Forever;
myRotateTransform3D.Rotation.BeginAnimation(AxisAngleRotation3D.AxisProperty, myVectorAnimation);
// Add the geometry model to the model group.
myModel3DGroup.Children.Add(myGeometryModel);
// Add the group of models to the ModelVisual3d.
myModelVisual3D.Content = myModel3DGroup;
//
myViewport3D.Children.Add(myModelVisual3D);
// Apply the viewport to the page so it will be rendered.
this.Content = myViewport3D;
}
}
}