Модераторы: gambit, Kefir, Partizan
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Поворот камеры по оси с помощью мыши, Поворот камеры по оси с помощью мыши 
V
    Опции темы
vinograd2008
Дата 10.8.2011, 19:40 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Бывалый
*


Профиль
Группа: Участник
Сообщений: 197
Регистрация: 7.12.2008

Репутация: нет
Всего: нет



Как повернуть камеру по осям с помощью мыши.

Есть код нужно поворачивать объект сферы в пространстве по осям X, Y, Z с помощью мыши как сделать? 

Код

  public partial class MaW : Window
    {
  public MaW()
        {
            InitializeComponent();
 
            // Create Viewport3D as content of window.
            Viewport3D viewport = new Viewport3D();
 
            //  Content = viewport;
           Content = viewport;
 
            // Get the MeshGeometry3D from the GenerateSphere method.
            MeshGeometry3D mesh =
                GenerateSphere(new Point3D(0, 0, 0), 2, 100, 100);
            mesh.Freeze();
 
            // Define a brush for the sphere.
            Brush[] brushes = new Brush[2] { Brushes.White, Brushes.WhiteSmoke };
            DrawingGroup drawgrp = new DrawingGroup();
            drawgrp.Opacity = 0.75;
 
            for (int i = 0; i < brushes.Length; i++)
            {
                RectangleGeometry rectgeo =
                    new RectangleGeometry(new Rect(10 * i, 0, 10, 580));
 
                GeometryDrawing geodraw =
                    new GeometryDrawing(brushes[i], null, rectgeo);
 
                drawgrp.Children.Add(geodraw);
            }
            DrawingBrush drawbrsh = new DrawingBrush(drawgrp);
            drawbrsh.Freeze();
 
            // Define the GeometryModel3D.
            GeometryModel3D geomod = new GeometryModel3D();
            geomod.Geometry = mesh;
            geomod.Material = new DiffuseMaterial(drawbrsh);
 
            // Create a ModelVisual3D for the GeometryModel3D.
            ModelVisual3D modvis = new ModelVisual3D();
            modvis.Content = geomod;
        viewport.Children.Add(modvis);
 
            // Create another ModelVisual3D for light.
            Model3DGroup modgrp = new Model3DGroup();
            modgrp.Children.Add(new AmbientLight(Color.FromRgb(128, 128, 128)));
            modgrp.Children.Add(
                new DirectionalLight(Color.FromRgb(128, 128, 128),
                                     new Vector3D(2, -3, -1)));
 
            modvis = new ModelVisual3D();
            modvis.Content = modgrp;
            viewport.Children.Add(modvis);
 
            // Create the camera.
            PerspectiveCamera cam = new PerspectiveCamera(new Point3D(0, 0, 8),
                            new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), 45);
            viewport.Camera = cam;
 
            // Create a transform for the GeometryModel3D.
            AxisAngleRotation3D axisangle =
                new AxisAngleRotation3D(new Vector3D(1, 1, 0), 0);
            RotateTransform3D rotate = new RotateTransform3D(axisangle);
            geomod.Transform = rotate;
 
            // Animate the RotateTransform3D.
            //DoubleAnimation anima =
            //    new DoubleAnimation(360, new Duration(TimeSpan.FromSeconds(5)));
            //anima.RepeatBehavior = RepeatBehavior.Forever;
            //axisangle.BeginAnimation(AxisAngleRotation3D.AngleProperty, anima);
            //Storyboard.SetTargetProperty(anima, new PropertyPath("(0.75)", new DependencyProperty[] { Brush.OpacityProperty })); 
        }
 
        MeshGeometry3D GenerateSphere(Point3D center, double radius,
                                    int slices, int stacks)
        {
            // Create the MeshGeometry3D.
            MeshGeometry3D mesh = new MeshGeometry3D();
 
            // Fill the Position, Normals, and TextureCoordinates collections.
            for (int stack = 0; stack <= stacks; stack++)
            {
                double phi = Math.PI / 2 - stack * Math.PI / stacks;
                double y = radius * Math.Sin(phi);
                double scale = -radius * Math.Cos(phi);
 
                for (int slice = 0; slice <= slices; slice++)
                {
                    double theta = slice * 2 * Math.PI / slices;
                    double x = scale * Math.Sin(theta);
                    double z = scale * Math.Cos(theta);
 
                    Vector3D normal = new Vector3D(x, y, z);
                    mesh.Normals.Add(normal);
                    mesh.Positions.Add(normal + center);
                    mesh.TextureCoordinates.Add(
                            new Point((double)slice / slices,
                                      (double)stack / stacks));
 
                }
            }
 
            // Fill the TriangleIndices collection.
            for (int stack = 0; stack < stacks; stack++)
                for (int slice = 0; slice < slices; slice++)
                {
                    int n = slices + 1; // Keep the line length down.
 
                    if (stack != 0)
                    {
                        mesh.TriangleIndices.Add((stack + 0) * n + slice);
                        mesh.TriangleIndices.Add((stack + 1) * n + slice);
                        mesh.TriangleIndices.Add((stack + 0) * n + slice + 1);
                    }
                    if (stack != stacks - 1)
                    {
                        mesh.TriangleIndices.Add((stack + 0) * n + slice + 1);
                        mesh.TriangleIndices.Add((stack + 1) * n + slice);
                        mesh.TriangleIndices.Add((stack + 1) * n + slice + 1);
                    }
                }
            return mesh;
        }
}
 

PM MAIL   Вверх
zel25b
Дата 19.8.2011, 14:30 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 9
Регистрация: 1.2.2010

Репутация: нет
Всего: нет



http://3dtools.codeplex.com/ класс Trackball
PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | WPF и Silverlight | Следующая тема »


 




[ Время генерации скрипта: 0.0766 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.