РЕДАКТИРОВАТЬ: Исправлено
Привет всем, у меня в окне есть следующий обработчик событий:
private void buttonView_Click(object sender, RoutedEventArgs e)
{
//Camera
PerspectiveCamera camera = new PerspectiveCamera();
camera.LookDirection = new Vector3D(5, -2, -3);
camera.Position = new Point3D(-5, 2, 3);
camera.UpDirection = new Vector3D(0, 1, 0);
camera.NearPlaneDistance = 1;
camera.FarPlaneDistance = 10;
//Lighting
DirectionalLight light = new DirectionalLight(Colors.White, new Vector3D(-3, -4, -5));
//Cube
Cube cube = new Cube();
GeometryModel3D cubeModel = new GeometryModel3D();
cubeModel.Geometry = cube.Mesh;
cubeModel.Material = new DiffuseMaterial(Brushes.Red);
//ModelGroup
Model3DGroup modelGroup = new Model3DGroup();
modelGroup.Children.Add(light);
modelGroup.Children.Add(cubeModel);
//Model
ModelVisual3D model = new ModelVisual3D();
model.Content = modelGroup;
//Viewport
Viewport3D view = new Viewport3D();
view.Camera = camera;
view.Children.Add(model);
//Show it all
Frame f = new Frame();
f.Content = view;
grid1.Children.Add(f);
}
, и это мой класс куба:
public class Cube : Primitive
{
Point3D[] positions = new Point3D[] {
new Point3D(0, 1, 1),
new Point3D(0, 0, 1),
new Point3D(1, 1, 1),
new Point3D(1, 0, 1),
new Point3D(1, 1, 0),
new Point3D(0, 0, 0),
new Point3D(0, 1, 1),
new Point3D(0, 0, 1),
new Point3D(0, 1, 0),
new Point3D(0, 1, 0),
new Point3D(1, 1, 1),
new Point3D(0, 1, 1),
new Point3D(1, 1, 1),
new Point3D(1, 0, 1),
new Point3D(1, 1, 0),
new Point3D(1, 0, 0),
new Point3D(1, 0, 1),
new Point3D(0, 0, 1),
new Point3D(1, 0, 0),
new Point3D(0, 0, 0),
new Point3D(1, 1, 0),
new Point3D(1, 0, 0),
new Point3D(0, 1, 0),
new Point3D(0, 0, 0)
};
int[] vertices = new int[] {
0,
1,
2,
1,
3,
2,
4,
5,
6,
5,
7,
6,
8,
9,
10,
9,
11,
10,
12,
13,
14,
13,
15,
14,
16,
17,
18,
17,
19,
18,
20,
21,
22,
21,
23,
22
};
public Cube()
{
this.Mesh.Positions = new Point3DCollection(positions);
this.Mesh.TriangleIndices = new Int32Collection(vertices);
}
}
public abstract class Primitive
{
public Primitive()
{
this.Mesh = new MeshGeometry3D();
}
public MeshGeometry3D Mesh { get; protected set; }
}
Однако, когда я нажимаю кнопку, ничего не отображается. Есть ли ошибка в моем обработчике событий?