Wpf Workgroup 4

1,498 views

Published on

The fourth WPF workgroup at FCS, UAIC

Published in: Art & Photos, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,498
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Wpf Workgroup 4

  1. 1. Andrei Iacob Microsoft Student Partners
  2. 2. Agenda <ul><li>3D </li></ul><ul><li>- Sistemul de coordonate </li></ul><ul><li>- Marii juc ători (Point3D, Vector3D, Size3D, Visual3D, MeshGeometry3D, GeometryModel3D, ModelVisual3D, PerspectiveCamera) - O scenă simplă - Randarea controalelor în 3D - Transformari 3D - ZAM3D - Crearea unei scene 3D din cod - Hit testing - Tema: controale 2D în spaţiul 3D </li></ul>
  3. 3. Bazele unei scene 3D +x -x +y -y +z -z Sistemul de coordonate – right handed
  4. 4. Bazele unei scene 3D <ul><li>C âteva clase: </li></ul><ul><li>System.Windows.Media.Media3D </li></ul><ul><li>Point3D </li></ul><ul><li>Size3D </li></ul><ul><li>Rect3D </li></ul><ul><li>Vector3D </li></ul><ul><li>X,Y,Z </li></ul>
  5. 5. Bazele unei scene 3D <ul><li>Ce constituie o scenă 3D ? </li></ul><ul><li>Cel pu ţin o formă geometrică </li></ul><ul><li>Cel puţin o sursă de lumină </li></ul><ul><li>O cameră (de luat vederi) </li></ul><ul><li>Viewport3D: </li></ul><ul><li>- Camera (System.Windows.Media3D.Camera) </li></ul><ul><li>- Children (Visual3DCollection) </li></ul>
  6. 6. Bazele unei scene 3D MeshGeometry3D Object DispatcherObject (abstract) DependencyObject Freezable (abstract) Animatable (abstract) Geometry3D (abstract) MeshGeometry3D
  7. 7. Bazele unei scene 3D MeshGeometry3D – exemplu <MeshGeometry3D Positions=&quot;-1 0 0, 0 1 0, 1 0 0&quot; TriangleIndices=&quot;0 2 1&quot; />
  8. 8. Bazele unei scene 3D MeshGeometry3D + material = GeometryModel3D Object DispatcherObject (abstract) DependencyObject Freezable (abstract) Animatable (abstract) Material (abstract) DiffuseMaterial EmissiveMaterial MaterialGroup SpecularMaterial
  9. 9. Bazele unei scene 3D MeshGeometry3D + material = GeometryModel3D <ModelVisual3D> <ModelVisual3D.Content> <GeometryModel3D> <GeometryModel3D.Geometry> <MeshGeometry3D Positions=&quot;-1 0 0, 0 1 0, 1 0 0&quot; TriangleIndices=&quot;0 2 1&quot; /> </GeometryModel3D.Geometry>   <GeometryModel3D.Material> <DiffuseMaterial Brush=&quot;Red&quot; /> </GeometryModel3D.Material>   <GeometryModel3D.BackMaterial> <DiffuseMaterial Brush=&quot;Blue&quot; /> </GeometryModel3D.BackMaterial> </GeometryModel3D> </ModelVisual3D.Content> </ModelVisual3D>
  10. 10. Bazele unei scene 3D Lumini Object DispatcherObject (abstract) DependencyObject Freezable (abstract) Animatable (abstract) Model3D (abstract) GeometryModel3D Light (abstract) AmbientLight DirectionalLight PointLightBase (abstract) PointLight SpotLight
  11. 11. Bazele unei scene 3D Lumini <ModelVisual3D> <ModelVisual3D.Content> <AmbientLight Color=&quot;White&quot; /> </ModelVisual3D.Content> </ModelVisual3D>
  12. 12. Bazele unei scene 3D Camere Object DispatcherObject (abstract) DependencyObject Freezable (abstract) Animatable (abstract) Camera (abstract) MatrixCamera ProjectionCamera (abstract) OrthographicCamera PerspectiveCamera
  13. 13. Bazele unei scene 3D Camere <Viewport3D.Camera> <PerspectiveCamera Position=&quot;0 0.5 3&quot; LookDirection=&quot;0 0 -1&quot; UpDirection=&quot;0 1 0&quot; FieldOfView=&quot;90&quot; /> </Viewport3D.Camera> LookDirection = VisualCenter – Position
  14. 14. Bazele unei scene 3D Prima scen ă <Viewport3D> <ModelVisual3D> <ModelVisual3D.Content> <GeometryModel3D.Geometry> <!– Forma geometrica  </GeometryModel3D.Geometry>  <GeometryModel3D.Material>  <!-- Material --> </GeometryModel3D.Material>  </GeometryModel3D> </ModelVisual3D.Content> </ModelVisual3D> <!-- Lumina -->   <ModelVisual3D> <ModelVisual3D.Content> <AmbientLight Color=&quot;White&quot; /> </ModelVisual3D.Content> </ModelVisual3D> <!-- Camera. --> <Viewport3D.Camera> <PerspectiveCamera Position=&quot;0 0.5 1.5&quot; LookDirection=&quot;0 0 -1&quot; UpDirection=&quot;0 1 0&quot; FieldOfView=&quot;120&quot; /> </Viewport3D.Camera> </Viewport3D> 
  15. 15. Bazele unei scene 3D Transform ări Object DispatcherObject (abstract) DependencyObject Freezable (abstract) Animatable (abstract) Transform3D (abstract) AffineTransform3D (abstract) RotateTransform3D ScaleTransform3D TranslateTransform3D MatrixTransform3D Transform3DGroup
  16. 16. Scena 3D din C# <ul><li>Pasul 1: </li></ul><ul><li>Proiectarea unei structuri de date care să stocheze modelele 3D (pentru prelucrare) ex. ArrayList </li></ul><ul><li>Pasul 2: </li></ul><ul><li>Crearea unui model: </li></ul><ul><li>Model3DGroup m odel =new Model3DGroup(); GeometryModel3D geometrie = new GeometryModel3D(); geometrie.Geometry = (MeshGeometry3D)t.FindResource(“cub”); // de ex </li></ul><ul><li>m odel .Children.Add(geometrie); </li></ul><ul><li>Pasul 3: </li></ul><ul><li>Ad ăugarea modelului în Viewport </li></ul><ul><li>Viewport.Children.Add(model); </li></ul>
  17. 17. Hit Testing public HitTestResultBehavior HTResult(System.Windows.Media.HitTestResult rawresult) {     RayHitTestResult rayResult = rawresult as RayHitTestResult;    if (rayResult != null)     {         RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;         if (rayMeshResult != null)         {             GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;      // Aici facem ceva cu modelul.         }    }    return HitTestResultBehavior.Continue; } PointHitTestParameters pointparams = new PointHitTestParameters(mouseposition); VisualTreeHelper.HitTest(mainViewport, null, HTResult, pointparams);

×