Студопедия — MeshGeometry3D - класс 4 страница
Студопедия Главная Случайная страница Обратная связь

Разделы: Автомобили Астрономия Биология География Дом и сад Другие языки Другое Информатика История Культура Литература Логика Математика Медицина Металлургия Механика Образование Охрана труда Педагогика Политика Право Психология Религия Риторика Социология Спорт Строительство Технология Туризм Физика Философия Финансы Химия Черчение Экология Экономика Электроника

MeshGeometry3D - класс 4 страница






myAxisAngleRotation3d.Axis = new Vector3D(1, 1, 1);

myAxisAngleRotation3d.Angle = 45;

myRotateTransform3D.Rotation = myAxisAngleRotation3d;

teapotModel.Transform = myRotateTransform3D;

 

Vector3DAnimation myVectorAnimation = new Vector3DAnimation(new Vector3D(-1, -1, -1), new Duration(TimeSpan.FromMilliseconds(1000)));

myVectorAnimation.RepeatBehavior = RepeatBehavior.Forever;

myRotateTransform3D.Rotation.BeginAnimation(AxisAngleRotation3D.AxisProperty, myVectorAnimation);

 

 

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;

 

}

}

}

 


 

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();

}

Point3D GetPosition(double t, double y)

{

double r = Math.Sqrt(1 - y * y);

double x = r * Math.Cos(t);

double z = r * Math.Sin(t);

 

return new Point3D(x, y, z);

}

 

Vector3D GetNormal(double t, double y)

{

return (Vector3D)GetPosition(t, y);

}

 

Point GetTextureCoordinate(double t, double y)

{

Matrix TYtoUV = new Matrix();

TYtoUV.Scale(1 / (2 * Math.PI), -0.5);

 

Point p = new Point(t, y);

p = p * TYtoUV;

 

return p;

}

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();

 

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);

 

 

int tDiv = 32;

int yDiv = 32;

double maxTheta = Math.PI*2;

double minY = -1.0;

double maxY = 1.0;

double dt = maxTheta / tDiv;

double dy = (maxY - minY) / yDiv;

MeshGeometry3D mesh = new MeshGeometry3D();

for (int yi = 0; yi <= yDiv; yi++)

{

double y = minY + yi * dy;

for (int ti = 0; ti <= tDiv; ti++)

{

double t = ti * dt;

mesh.Positions.Add(GetPosition(t, y));

mesh.Normals.Add(GetNormal(t, y));

mesh.TextureCoordinates.Add(GetTextureCoordinate(t, y));

}

}

for (int yi = 0; yi < yDiv; yi++)

{

for (int ti = 0; ti < tDiv; ti++)

{

int x0 = ti;

int x1 = (ti + 1);

int y0 = yi * (tDiv + 1);

int y1 = (yi + 1) * (tDiv + 1);

mesh.TriangleIndices.Add(x0 + y0);

mesh.TriangleIndices.Add(x0 + y1);

mesh.TriangleIndices.Add(x1 + y0);

mesh.TriangleIndices.Add(x1 + y0);

mesh.TriangleIndices.Add(x0 + y1);

mesh.TriangleIndices.Add(x1 + y1);

}

}

 

// Apply the mesh to the geometry model.

myGeometryModel.Geometry = mesh;

 

ImageBrush im = new ImageBrush();

im.ImageSource = new BitmapImage(new Uri(@"http://img0.liveinternet.ru/images/attach/c/7/97/89/97089440_large_skvorechnik11.jpg"));

 

// Define material and apply to the mesh geometries.

DiffuseMaterial myMaterial = new DiffuseMaterial(im);

 

// Define material and apply to the mesh geometries.

 

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(5000)));

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;

 

}

 

 

}

}

 


 

16 апреля 2014 г.

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(object sender, RoutedEventArgs e)

{

 

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));

 

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(3.0, 0.0, 0.0));

myPositionCollection.Add(new Point3D(3.0, 3.0, 0.0));

myPositionCollection.Add(new Point3D(3.0, 3.0, 0.0));

myPositionCollection.Add(new Point3D(0.0, 3.0, 0.0));

myPositionCollection.Add(new Point3D(0.0, 0.0, 0.0));

 

 

myMeshGeometry3D.Positions = myPositionCollection;

 

// Create a collection of triangle indices for the MeshGeometry3D.

Int32Collection myTriangleIndicesCollection = new Int32Collection();

myTriangleIndicesCollection.Add(0);

myTriangleIndicesCollection.Add(1);

myTriangleIndicesCollection.Add(2);

myTriangleIndicesCollection.Add(3);

myTriangleIndicesCollection.Add(4);

myTriangleIndicesCollection.Add(5);

 

myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 1));

myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 1));

myMeshGeometry3D.TextureCoordinates.Add(new Point(0, 0));

myMeshGeometry3D.TextureCoordinates.Add(new Point(1, 0));

 

myMeshGeometry3D.TriangleIndices = myTriangleIndicesCollection;

 

// Apply the mesh to the geometry model.

myGeometryModel.Geometry = myMeshGeometry3D;

 

BitmapImage bm1 = new BitmapImage();

bm1.BeginInit();

bm1.UriSource = new Uri("verona.jpg", UriKind.Relative);

bm1.EndInit();

 

ImageBrush imgBrush = new ImageBrush(bm1);

 

// Define material and apply to the mesh geometries.

DiffuseMaterial myMaterial = new DiffuseMaterial(imgBrush);

myGeometryModel.Material = myMaterial;

 

TranslateTransform3D myTranslateTransform3D = new TranslateTransform3D();

myModel3DGroup.Transform = myTranslateTransform3D;

DoubleAnimation xAnim = new DoubleAnimation();

xAnim.From = -1;

xAnim.To = 1;

xAnim.RepeatBehavior = new RepeatBehavior(200);

xAnim.Duration = TimeSpan.FromSeconds(4);

xAnim.AutoReverse = true;

myTranslateTransform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnim);

 

myGeometryModel.Transform = myTranslateTransform3D;

// 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;

}

}

}

 







Дата добавления: 2015-09-04; просмотров: 281. Нарушение авторских прав; Мы поможем в написании вашей работы!



Кардиналистский и ординалистский подходы Кардиналистский (количественный подход) к анализу полезности основан на представлении о возможности измерения различных благ в условных единицах полезности...

Обзор компонентов Multisim Компоненты – это основа любой схемы, это все элементы, из которых она состоит. Multisim оперирует с двумя категориями...

Композиция из абстрактных геометрических фигур Данная композиция состоит из линий, штриховки, абстрактных геометрических форм...

Важнейшие способы обработки и анализа рядов динамики Не во всех случаях эмпирические данные рядов динамики позволяют определить тенденцию изменения явления во времени...

Искусство подбора персонала. Как оценить человека за час Искусство подбора персонала. Как оценить человека за час...

Этапы творческого процесса в изобразительной деятельности По мнению многих авторов, возникновение творческого начала в детской художественной практике носит такой же поэтапный характер, как и процесс творчества у мастеров искусства...

Тема 5. Анализ количественного и качественного состава персонала Персонал является одним из важнейших факторов в организации. Его состояние и эффективное использование прямо влияет на конечные результаты хозяйственной деятельности организации.

КОНСТРУКЦИЯ КОЛЕСНОЙ ПАРЫ ВАГОНА Тип колёсной пары определяется типом оси и диаметром колес. Согласно ГОСТ 4835-2006* устанавливаются типы колесных пар для грузовых вагонов с осями РУ1Ш и РВ2Ш и колесами диаметром по кругу катания 957 мм. Номинальный диаметр колеса – 950 мм...

Философские школы эпохи эллинизма (неоплатонизм, эпикуреизм, стоицизм, скептицизм). Эпоха эллинизма со времени походов Александра Македонского, в результате которых была образована гигантская империя от Индии на востоке до Греции и Македонии на западе...

Демографияда "Демографиялық жарылыс" дегеніміз не? Демография (грекше демос — халық) — халықтың құрылымын...

Studopedia.info - Студопедия - 2014-2024 год . (0.012 сек.) русская версия | украинская версия