Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Windows.Media.Media3D;
- using System.Windows.Media.Animation;
- namespace WpfApp6
- {
- /// <summary>
- /// Логика взаимодействия для MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- Model3DGroup modelGroup = new Model3DGroup();
- PerspectiveCamera myPCamera = new PerspectiveCamera();
- GeometryModel3D teapotModel = new GeometryModel3D();
- Transform3DCollection myTransforms = new Transform3DCollection();
- Viewport3D myViewport = new Viewport3D();
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- //Set camera viewpoint and properties.
- myPCamera.FarPlaneDistance = 20;
- myPCamera.NearPlaneDistance = 1;
- myPCamera.FieldOfView = 45;
- myPCamera.Position = new Point3D(0, 0, 10);
- myPCamera.LookDirection = new Vector3D(0, 0, -10);
- myPCamera.UpDirection = new Vector3D(0, 1, 0);
- //Add light sources to the scene.
- //PointLight myDirLight = new PointLight(Color.FromRgb(255, 255, 255), new Point3D(0, 0, 10));
- DirectionalLight myDirLight = new DirectionalLight(Color.FromRgb(255, 255, 255), new Vector3D(1, 1, -3));
- teapotModel.Geometry = (MeshGeometry3D)Application.Current.Resources["myTeapot"];
- Brush objectBrush;
- DiffuseMaterial diffuseMaterial;
- SpecularMaterial specularMaterial;
- MaterialGroup matGroup = new MaterialGroup();
- matGroup.Children.Clear();
- objectBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
- diffuseMaterial = new DiffuseMaterial(objectBrush);
- specularMaterial = new SpecularMaterial(new SolidColorBrush(Color.FromRgb(255, 255, 255)), 100);
- matGroup.Children.Add(diffuseMaterial);
- matGroup.Children.Add(specularMaterial);
- ColorAnimationUsingKeyFrames objColorAnim = new ColorAnimationUsingKeyFrames();
- objColorAnim.KeyFrames.Add(new DiscreteColorKeyFrame(Color.FromRgb(255, 255, 255), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 5))));
- objColorAnim.KeyFrames.Add(new DiscreteColorKeyFrame(Color.FromRgb(255, 0, 0), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 10))));
- objColorAnim.KeyFrames.Add(new DiscreteColorKeyFrame(Color.FromRgb(0, 255, 0), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 15))));
- objColorAnim.KeyFrames.Add(new LinearColorKeyFrame(Color.FromRgb(0, 0, 255), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 20))));
- objColorAnim.KeyFrames.Add(new LinearColorKeyFrame(Color.FromRgb(255,255, 0), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 25))));
- objColorAnim.KeyFrames.Add(new LinearColorKeyFrame(Color.FromRgb(0, 255, 255), KeyTime.FromTimeSpan(new TimeSpan(0, 0, 30))));
- teapotModel.Material = matGroup;
- objColorAnim.RepeatBehavior = RepeatBehavior.Forever;
- objectBrush.BeginAnimation(SolidColorBrush.ColorProperty, objColorAnim);
- // Quaternion Структура, представляющая поворот в трех измерениях.
- RotateTransform3D myRotateTransform3D = new RotateTransform3D();
- Quaternion q1 = new Quaternion(new Vector3D(1, 1, 0), 0);
- QuaternionRotation3D myQuaternionRotation3D1 = new QuaternionRotation3D(q1);
- myRotateTransform3D.Rotation = myQuaternionRotation3D1;
- teapotModel.Transform = myRotateTransform3D;
- QuaternionAnimation qa = new QuaternionAnimation(new Quaternion(new Vector3D(1, 1, 0), 0), new Quaternion(new Vector3D(1, 1, 0), 359), new Duration(TimeSpan.FromSeconds(5)));
- qa.UseShortestPath = false;
- qa.RepeatBehavior = RepeatBehavior.Forever;
- myRotateTransform3D.Rotation.BeginAnimation(QuaternionRotation3D.QuaternionProperty, qa);
- modelGroup.Children.Add(teapotModel);
- modelGroup.Children.Add(myDirLight);
- ModelVisual3D modelsVisual = new ModelVisual3D();
- modelsVisual.Content = modelGroup;
- //Add the visual and camera to the Viewport3D.
- myViewport.Camera = myPCamera;
- myViewport.Children.Add(modelsVisual);
- this.Content = myViewport;
- }
- }
- }
- <Window x:Class="WpfApp6.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:WpfApp6"
- mc:Ignorable="d"
- Title="MainWindow" Height="740.408" Width="1179.404" Loaded="Window_Loaded">
- </Window>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement