SlideShare a Scribd company logo
Mohammad Shaker
mohammadshaker.com
WPF Starter Course
@ZGTRShaker
2011, 2012, 2013, 2014
WPF Showcase
L03 – 3D Rendering and 3D Animations
3D Rendering
3D Rendering
3D Models
3D Models
3D Models
3D Models
3D Models
3D Models
3D Models
• With Texturing!
3D Models
• Visual Hit!
3D Models
Tools to fire up a 3D Area!
Tools to fire up a 3D Area!
• Set the desired area
– Viewport3D
• Light the area with a DirectionalLight!
– new ModelVisual3D
{
Content = new DirectionalLight
{
Color = Colors.White,
Direction = new Vector3D(0, 0, -1)
}
});
• Set a camera to look around!
– PerspectiveCamera
3D Rendering
3D Rendering
3D Rendering
The Craziness of Code Behind!
3D Rendering
What do u need to create a cuboid?!
So, Let’s start!
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
3D Rendering
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
3D Rendering
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
<Viewport3D Name="viewport3D">
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="-2,-3,-1" />
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
3D Rendering
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
3D Rendering
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
Set a camera to look around!
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
class CameraManagement
{
public PerspectiveCamera Camera { set; get; }
public CameraManagement(Viewport3D viewport3D)
{
this.Camera = new PerspectiveCamera();
this.Camera.FarPlaneDistance = 500;
this.Camera.NearPlaneDistance = 1;
// LookDirection
this.Camera.LookDirection = new Vector3D(-10, -15, -25);
// UpDirection
this.Camera.UpDirection = new Vector3D(0, 1, 0);
// Position
this.Camera.Position = new Point3D(50, 100, 150);
this.Camera.FieldOfView = 70;
this.Camera.Transform = new Transform3DGroup();
viewport3D.Camera = this.Camera;
}
}
Set a camera to look around!
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CameraManagement cameraManagement = new CameraManagement(viewport3D);
}
}
3D Rendering
• Set the desired area
• Light the area with a DirectionalLight!
• Set a camera to look around!
• Draw whatever u want!
– Our Cuboid!
3D Rendering
1. Set the desired area
2. Light the area with a DirectionalLight!
3. Set a camera to look around!
4. Draw whatever u want!
– Our Cuboid!
• What do u need to create a Cuboid?!
• Bunch of Triangles!
3D Rendering
1. Set the desired area
2. Light the area with a DirectionalLight!
3. Set a camera to look around!
4. Draw whatever u want!
– Our Cuboid!
• What do u need to create a Cuboid?!
• Bunch of 16 Triangles!
3D Rendering
class Triangle
{
public static Model3DGroup CreateTriangleModelGroup(Point3D p0,
Point3D p1,
Point3D p2,
Color myColor)
{
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(p0);
mesh.Positions.Add(p1);
mesh.Positions.Add(p2);
mesh.TriangleIndices.Add(0);
mesh.TriangleIndices.Add(1);
mesh.TriangleIndices.Add(2);
Material material = new DiffuseMaterial(new SolidColorBrush(myColor));
GeometryModel3D model = new GeometryModel3D(mesh, material);
Model3DGroup group = new Model3DGroup();
group.Children.Add(model);
return group;
}
}
3D Rendering
class Cuboid
{
public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color)
{
Model3D model = CreateModelGroup(initialPosition, length, width, height, color);
ModelVisual3D visualModel = new ModelVisual3D();
visualModel.Content = model;
viewport3D.Children.Add(visualModel);
}
private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color)
{
Model3DGroup group = new Model3DGroup();
// *HERE* //
return group;
}
public static Point3D GetSummedPoint(Point3D p1, Point3D p2)
{
Point3D myPoint = new Point3D();
// Manipulate Coordinates
myPoint.X = p1.X + p2.X;
myPoint.Y = p1.Y + p2.Y;
myPoint.Z = p1.Z + p2.Z;
return myPoint;
}
}
3D Rendering
class Cuboid
{
public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color)
{
Model3D model = CreateModelGroup(initialPosition, length, width, height, color);
ModelVisual3D visualModel = new ModelVisual3D();
visualModel.Content = model;
viewport3D.Children.Add(visualModel);
}
private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color)
{
Model3DGroup group = new Model3DGroup();
// *HERE* //
return group;
}
public static Point3D GetSummedPoint(Point3D p1, Point3D p2)
{
Point3D myPoint = new Point3D();
// Manipulate Coordinates
myPoint.X = p1.X + p2.X;
myPoint.Y = p1.Y + p2.Y;
myPoint.Z = p1.Z + p2.Z;
return myPoint;
}
}
//* HERE *//
Point3D p0 = initialPosition;
Point3D p1 = GetSummedPoint(initialPosition, new Point3D(width, 0, 0));
Point3D p2 = GetSummedPoint(initialPosition, new Point3D(width, 0, length));
Point3D p3 = GetSummedPoint(initialPosition, new Point3D(0, 0, length));
Point3D p4 = GetSummedPoint(initialPosition, new Point3D(0, height, 0));
Point3D p5 = GetSummedPoint(initialPosition, new Point3D(width, height, 0));
Point3D p6 = GetSummedPoint(initialPosition, new Point3D(width, height, length));
Point3D p7 = GetSummedPoint(initialPosition, new Point3D(0, height, length));
//front side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p3, p2, p6, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p3, p6, p7, color));
//right side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p1, p5, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p5, p6, color));
//back side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p1, p0, p4, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p1, p4, p5, color));
//left side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p0, p3, p7, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p0, p7, p4, color));
//top side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p7, p6, p5, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p7, p5, p4, color));
//bottom side triangles
group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p3, p0, color));
group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p0, p1, color));
3D Rendering
class Cuboid
{
public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color)
{
Model3D model = CreateModelGroup(initialPosition, length, width, height, color);
ModelVisual3D visualModel = new ModelVisual3D();
visualModel.Content = model;
viewport3D.Children.Add(visualModel);
}
private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color)
{
Model3DGroup group = new Model3DGroup();
// *HERE* //
return group;
}
public static Point3D GetSummedPoint(Point3D p1, Point3D p2)
{
Point3D myPoint = new Point3D();
// Manipulate Coordinates
myPoint.X = p1.X + p2.X;
myPoint.Y = p1.Y + p2.Y;
myPoint.Z = p1.Z + p2.Z;
return myPoint;
}
}
3D Rendering
• Now just call and play! :D
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CameraManagement cameraManagement = new CameraManagement(viewport3D);
Cuboid myFirstCuboid = new Cuboid(viewport3D, new Point3D(0, 0, 0), 40, 40, 40, Colors.Red);
}
}
3D Rendering
3D Rendering
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CameraManagement cameraManagement = new CameraManagement(viewport3D);
Cuboid myFirstCuboid = new Cuboid(viewport3D, new Point3D(0, 0, 0), 50, 60, 10, Colors.Red);
}
}
3D Rendering
3D Rendering
Hit Testing
Project “Track-Ball”
Provided by the WPF team 3-D tools
Visit: http://www.codeplex.com/3DTools/
<Window xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"... >
Then you can easily add the TrackballDecorator to your markup:
<tools:TrackballDecorator>
<Viewport3D>
...
</Viewport3D>
</tools:TrackballDecorator>
Hit Testing
Viewport2DVisual3D
Viewport2DVisual3D
awesome Control!
Viewport2DVisual3D!
Viewport2DVisual3D!
Viewport2DVisual3D!
Viewport2DVisual3D
• We’ll do this!
Viewport2DVisual3D
Viewport2DVisual3D
Viewport2DVisual3D From Code Behind!
Viewport2DVisual3D
• What’s needed to show 2D components in 3D environment?!
Viewport2DVisual3D
• What’s needed to show 2D components in 3D environment?!
Viewport2DVisual3D
• What’s needed to show 2D components in 3D environment?!
Viewport2DVisual3D
private void CreateMeshGeometry(Point3D initialPoint)
{
double pointParam = 0.5;
initialPoint.X = -initialPoint.X;
initialPoint.Y = -initialPoint.Y;
initialPoint.Z = -initialPoint.Z;
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions = new Point3DCollection
{
HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint),
HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ),
HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint),
HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint)
};
mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 });
mesh.TextureCoordinates = new PointCollection(new Point[]
{
new Point(0, 0),
new Point(0, 1),
new Point(1, 1),
new Point(1, 0)
});
this._viewport2DVisual3D.Geometry = mesh;
var material = new DiffuseMaterial
{
Brush = Brushes.White
};
Viewport2DVisual3D.SetIsVisualHostMaterial(material, true);
this._viewport2DVisual3D.Material = material;
}
Viewport2DVisual3D
private void CreateMeshGeometry(Point3D initialPoint)
{
double pointParam = 0.5;
initialPoint.X = -initialPoint.X;
initialPoint.Y = -initialPoint.Y;
initialPoint.Z = -initialPoint.Z;
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions = new Point3DCollection
{
HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint),
HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ),
HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint),
HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint)
};
mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 });
mesh.TextureCoordinates = new PointCollection(new Point[]
{
new Point(0, 0),
new Point(0, 1),
new Point(1, 1),
new Point(1, 0)
});
this._viewport2DVisual3D.Geometry = mesh;
var material = new DiffuseMaterial
{
Brush = Brushes.White
};
Viewport2DVisual3D.SetIsVisualHostMaterial(material, true);
this._viewport2DVisual3D.Material = material;
}
Viewport2DVisual3D
private void CreateMeshGeometry(Point3D initialPoint)
{
double pointParam = 0.5;
initialPoint.X = -initialPoint.X;
initialPoint.Y = -initialPoint.Y;
initialPoint.Z = -initialPoint.Z;
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions = new Point3DCollection
{
HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint),
HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ),
HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint),
HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint)
};
mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 });
mesh.TextureCoordinates = new PointCollection(new Point[]
{
new Point(0, 0),
new Point(0, 1),
new Point(1, 1),
new Point(1, 0)
});
this._viewport2DVisual3D.Geometry = mesh;
var material = new DiffuseMaterial
{
Brush = Brushes.White
};
Viewport2DVisual3D.SetIsVisualHostMaterial(material, true);
this._viewport2DVisual3D.Material = material;
}
Viewport2DVisual3D
• So how can we add 2D Components?!
Viewport2DVisual3D
• So how can we add 2D Components?!
– So easy!
Viewport2DVisual3D
• So how can we add 2D Components?!
– So easy!
_viewport2DVisual3D.Visual = InitializeVisualArea();
private StackPanel InitializeVisualArea()
{
StackPanel stackPanel = new StackPanel();
TextBlock textBlock = new TextBlock();
textBlock.Text = "Name: " + StudentInfo.Name + Environment.NewLine + "ID: "+ StudentInfo.Id;
Button button = new Button();
button.Content = "Rotate Me!";
button.Click += new RoutedEventHandler(button_Click);
stackPanel.Children.Add(textBlock);
stackPanel.Children.Add(button);
return stackPanel;
}
Viewport2DVisual3D
• So how can we add 2D Components?!
– So easy!
_viewport2DVisual3D.Visual = InitializeVisualArea();
private StackPanel InitializeVisualArea()
{
StackPanel stackPanel = new StackPanel();
TextBlock textBlock = new TextBlock();
textBlock.Text = "Name: " + StudentInfo.Name + Environment.NewLine + "ID: "+ StudentInfo.Id;
Button button = new Button();
button.Content = "Rotate Me!";
button.Click += new RoutedEventHandler(button_Click);
stackPanel.Children.Add(textBlock);
stackPanel.Children.Add(button);
return stackPanel;
}
public StudentInfo StudentInfo
{
get{return _studentInfo;}
set{_studentInfo = value;}
}
Viewport2DVisual3D
See the attached project
Animating Viewport2DVisual3D!
Constant Rotation
Animating Viewport2DVisual3D!
• Just a Rotation
public static void CreateViewportConstantRotationAnimationAroundX(Viewport2DVisual3D viewport2DVisual3D)
{
// Create Animation Around X Axis
var rotationAnimationAroundXAxis = new Rotation3DAnimation();
rotationAnimationAroundXAxis.From = new AxisAngleRotation3D
{
Angle = 0,
Axis = new Vector3D(0, 1, 0) // Y Axis
};
rotationAnimationAroundXAxis.To = new AxisAngleRotation3D
{
Angle = 20,
Axis = new Vector3D(0, 1, 0) // Y Axis
};
rotationAnimationAroundXAxis.Duration = new Duration(TimeSpan.FromSeconds(2));
rotationAnimationAroundXAxis.AutoReverse = true;
rotationAnimationAroundXAxis.RepeatBehavior = RepeatBehavior.Forever;
// Define Property to animate
viewport2DVisual3D.Transform.BeginAnimation(RotateTransform3D.RotationProperty, rotationAnimationAroundXAxis);
}
Animating Viewport2DVisual3D!
Flipping
Animating Viewport2DVisual3D
public static void CreateViewportFlipAnimation(Viewport2DVisual3D viewport2DVisual3D, Point3D position)
{
// Create Animation
Rotation3DAnimation FlipAnimation = new Rotation3DAnimation();
FlipAnimation.From = new AxisAngleRotation3D
{
Angle = 0,
Axis = new Vector3D(1, 0, 0) // X Axis
};
FlipAnimation.To = new AxisAngleRotation3D
{
Angle = 180,
Axis = new Vector3D(1, 0, 0) // X Axis
};
FlipAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
FlipAnimation.AutoReverse = true;
// Define Property to animate
RotateTransform3D rotateTransform3D = new RotateTransform3D();
rotateTransform3D.CenterZ = - position.Z;
rotateTransform3D.BeginAnimation(RotateTransform3D.RotationProperty, FlipAnimation);
viewport2DVisual3D.Transform = rotateTransform3D;
}
Animating Viewport2DVisual3D
public static void CreateViewportFlipAnimation(Viewport2DVisual3D viewport2DVisual3D, Point3D position)
{
// Create Animation
Rotation3DAnimation FlipAnimation = new Rotation3DAnimation();
FlipAnimation.From = new AxisAngleRotation3D
{
Angle = 0,
Axis = new Vector3D(1, 0, 0) // X Axis
};
FlipAnimation.To = new AxisAngleRotation3D
{
Angle = 180,
Axis = new Vector3D(1, 0, 0) // X Axis
};
FlipAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
FlipAnimation.AutoReverse = true;
// Define Property to animate
RotateTransform3D rotateTransform3D = new RotateTransform3D();
rotateTransform3D.CenterZ = - position.Z;
rotateTransform3D.BeginAnimation(RotateTransform3D.RotationProperty, FlipAnimation);
viewport2DVisual3D.Transform = rotateTransform3D;
}
Animating Camera Movement
Animating Camera!
• Just a Point3DAnimation
public static void MoveCameraDynamicallyWithUserInput(PerspectiveCamera camera, Point3D targettedPosition)
{
if (camera.Position!= targettedPosition)
{
Point3DAnimation animation = new Point3DAnimation();
animation.From = camera.Position;
animation.To = targettedPosition;
animation.Duration = new Duration(TimeSpan.FromSeconds(1.5));
camera.BeginAnimation(PerspectiveCamera.PositionProperty,animation);
}
}
Now test it and
see what you got!
Happy end of course!
I really had so much fun!
Hope you are too!
Take a Look on my other courses
@ http://www.slideshare.net/ZGTRZGTR
Available courses to the date of this slide:
C# Starter, C# Advanced, WPF, C++.NET, XNA, OpenGL, Delphi
http://www.mohammadshaker.com
mohammadshakergtr@gmail.com
https://twitter.com/ZGTRShaker @ZGTRShaker
https://de.linkedin.com/pub/mohammad-shaker/30/122/128/
http://www.slideshare.net/ZGTRZGTR
https://www.goodreads.com/user/show/11193121-mohammad-shaker
https://plus.google.com/u/0/+MohammadShaker/
https://www.youtube.com/channel/UCvJUfadMoEaZNWdagdMyCRA
http://mohammadshakergtr.wordpress.com/
WPF L03-3D Rendering and 3D Animation
Ad

Recommended

XNA L03–Models, Basic Effect and Animation
XNA L03–Models, Basic Effect and Animation
Mohammad Shaker
 
XNA L02–Basic Matrices and Transformations
XNA L02–Basic Matrices and Transformations
Mohammad Shaker
 
Learn Java 3D
Learn Java 3D
Jay Thakkar
 
Trident International Graphics Workshop 2014 4/5
Trident International Graphics Workshop 2014 4/5
Takao Wada
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
shelfrog
 
Learn Creative Coding: Begin Programming with the Processing Language
Learn Creative Coding: Begin Programming with the Processing Language
W M Harris
 
CS 354 Graphics Math
CS 354 Graphics Math
Mark Kilgard
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
Java3 d 1
Java3 d 1
Por Non
 
OpenGL L05-Texturing
OpenGL L05-Texturing
Mohammad Shaker
 
Autocad Training Delhi
Autocad Training Delhi
lalit_625
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
shivam chaurasia
 
3 d autocad_2009
3 d autocad_2009
Oscar Fuentes
 
TUTORIAL AUTO CAD 3D
TUTORIAL AUTO CAD 3D
Maharoni Karang Serang
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
Scmad Chapter06
Scmad Chapter06
Marcel Caraciolo
 
CS 354 Pixel Updating
CS 354 Pixel Updating
Mark Kilgard
 
3 d graphics with opengl part 2
3 d graphics with opengl part 2
Sardar Alam
 
Lec2
Lec2
Amba Research
 
CS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
Mark Kilgard
 
CS 354 Blending, Compositing, Anti-aliasing
CS 354 Blending, Compositing, Anti-aliasing
Mark Kilgard
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
stefan_b
 
3rd Seminar
3rd Seminar
ChristinaSaweres
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Mohammad Shaker
 
WPF - the future of GUI is near
WPF - the future of GUI is near
Bartlomiej Filipek
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
Mohammad Shaker
 
XNA L11–Shaders Part 2
XNA L11–Shaders Part 2
Mohammad Shaker
 
XNA L10–Shaders Part 1
XNA L10–Shaders Part 1
Mohammad Shaker
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects Cloning
Mohammad Shaker
 

More Related Content

What's hot (16)

Java3 d 1
Java3 d 1
Por Non
 
OpenGL L05-Texturing
OpenGL L05-Texturing
Mohammad Shaker
 
Autocad Training Delhi
Autocad Training Delhi
lalit_625
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
shivam chaurasia
 
3 d autocad_2009
3 d autocad_2009
Oscar Fuentes
 
TUTORIAL AUTO CAD 3D
TUTORIAL AUTO CAD 3D
Maharoni Karang Serang
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
Scmad Chapter06
Scmad Chapter06
Marcel Caraciolo
 
CS 354 Pixel Updating
CS 354 Pixel Updating
Mark Kilgard
 
3 d graphics with opengl part 2
3 d graphics with opengl part 2
Sardar Alam
 
Lec2
Lec2
Amba Research
 
CS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
Mark Kilgard
 
CS 354 Blending, Compositing, Anti-aliasing
CS 354 Blending, Compositing, Anti-aliasing
Mark Kilgard
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
stefan_b
 
3rd Seminar
3rd Seminar
ChristinaSaweres
 
Java3 d 1
Java3 d 1
Por Non
 
Autocad Training Delhi
Autocad Training Delhi
lalit_625
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
shivam chaurasia
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
The Ring programming language version 1.5.3 book - Part 48 of 184
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
CS 354 Pixel Updating
CS 354 Pixel Updating
Mark Kilgard
 
3 d graphics with opengl part 2
3 d graphics with opengl part 2
Sardar Alam
 
CS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
Mark Kilgard
 
CS 354 Blending, Compositing, Anti-aliasing
CS 354 Blending, Compositing, Anti-aliasing
Mark Kilgard
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
stefan_b
 

Viewers also liked (18)

WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Mohammad Shaker
 
WPF - the future of GUI is near
WPF - the future of GUI is near
Bartlomiej Filipek
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
Mohammad Shaker
 
XNA L11–Shaders Part 2
XNA L11–Shaders Part 2
Mohammad Shaker
 
XNA L10–Shaders Part 1
XNA L10–Shaders Part 1
Mohammad Shaker
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects Cloning
Mohammad Shaker
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
Mohammad Shaker
 
Utilizing Kinect Control for a More Immersive Interaction with 3D Environment
Utilizing Kinect Control for a More Immersive Interaction with 3D Environment
Mohammad Shaker
 
Delphi L02 Controls P1
Delphi L02 Controls P1
Mohammad Shaker
 
Android L01 - Warm Up
Android L01 - Warm Up
Mohammad Shaker
 
C# Advanced L10-Workflow Foundation
C# Advanced L10-Workflow Foundation
Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
Mohammad Shaker
 
C# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCF
Mohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
Mohammad Shaker
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
Mohammad Shaker
 
Car Dynamics with ABS, ESP and GPS Systems
Car Dynamics with ABS, ESP and GPS Systems
Mohammad Shaker
 
OpenGL Starter L02
OpenGL Starter L02
Mohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Mohammad Shaker
 
WPF L01-Layouts, Controls, Styles and Templates
WPF L01-Layouts, Controls, Styles and Templates
Mohammad Shaker
 
WPF - the future of GUI is near
WPF - the future of GUI is near
Bartlomiej Filipek
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
Mohammad Shaker
 
XNA L11–Shaders Part 2
XNA L11–Shaders Part 2
Mohammad Shaker
 
XNA L10–Shaders Part 1
XNA L10–Shaders Part 1
Mohammad Shaker
 
C# Starter L07-Objects Cloning
C# Starter L07-Objects Cloning
Mohammad Shaker
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
Mohammad Shaker
 
Utilizing Kinect Control for a More Immersive Interaction with 3D Environment
Utilizing Kinect Control for a More Immersive Interaction with 3D Environment
Mohammad Shaker
 
C# Advanced L10-Workflow Foundation
C# Advanced L10-Workflow Foundation
Mohammad Shaker
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
Mohammad Shaker
 
C# Advanced L08-Networking+WCF
C# Advanced L08-Networking+WCF
Mohammad Shaker
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
Mohammad Shaker
 
C# Starter L06-Delegates, Event Handling and Extension Methods
C# Starter L06-Delegates, Event Handling and Extension Methods
Mohammad Shaker
 
Car Dynamics with ABS, ESP and GPS Systems
Car Dynamics with ABS, ESP and GPS Systems
Mohammad Shaker
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Mohammad Shaker
 
Ad

Similar to WPF L03-3D Rendering and 3D Animation (20)

Games 3 dl4-example
Games 3 dl4-example
enrique_arguello
 
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Microsoft Mobile Developer
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
Tomi Aarnio
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
Takao Wada
 
CGLabLec6.pptx
CGLabLec6.pptx
Mohammad7Abudosh7
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
Mohammad Shaker
 
C++ L11-Polymorphism
C++ L11-Polymorphism
Mohammad Shaker
 
Developing games for Series 40 full-touch UI
Developing games for Series 40 full-touch UI
Microsoft Mobile Developer
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
10java 2d
10java 2d
Adil Jafri
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
Palak Sanghani
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
Korhan Bircan
 
3 d autocad_2009
3 d autocad_2009
Yayuk Setiyowati
 
IDC 2010 Conference Presentation
IDC 2010 Conference Presentation
Gonçalo Amador
 
How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?
RubenGray1
 
java_for_future_15-Multithreaded-Graphics.pptx
java_for_future_15-Multithreaded-Graphics.pptx
khoand6055
 
Auto cad 3d tutorial
Auto cad 3d tutorial
Reuven Neil Panganiban
 
Introduction to threejs
Introduction to threejs
Gareth Marland
 
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Getting Started with 3D Game Development on Nokia Series 40 Asha Phones
Microsoft Mobile Developer
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
Tomi Aarnio
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
Takao Wada
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
JinTaek Seo
 
XNA L07–Skybox and Terrain
XNA L07–Skybox and Terrain
Mohammad Shaker
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
building_games_with_ruby_rubyconf
building_games_with_ruby_rubyconf
tutorialsruby
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
Palak Sanghani
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
Korhan Bircan
 
IDC 2010 Conference Presentation
IDC 2010 Conference Presentation
Gonçalo Amador
 
How to Create Custom Shaders in Flutter?
How to Create Custom Shaders in Flutter?
RubenGray1
 
java_for_future_15-Multithreaded-Graphics.pptx
java_for_future_15-Multithreaded-Graphics.pptx
khoand6055
 
Introduction to threejs
Introduction to threejs
Gareth Marland
 
Ad

More from Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game Development
Mohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
Mohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - Color
Mohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - Typography
Mohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
Mohammad Shaker
 
Android L05 - Storage
Android L05 - Storage
Mohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and Threading
Mohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
Mohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
Mohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
Mohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and Gaming
Mohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / Parse
Mohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
Mohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes
Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and Adapters
Mohammad Shaker
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to Games
Mohammad Shaker
 
Indie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSeven
Mohammad Shaker
 
Indie Series 02: AI and Recent Advances in Games
Indie Series 02: AI and Recent Advances in Games
Mohammad Shaker
 
Roboconf DSL Advanced Software Engineering
Roboconf DSL Advanced Software Engineering
Mohammad Shaker
 
12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
Mohammad Shaker
 
Unity L01 - Game Development
Unity L01 - Game Development
Mohammad Shaker
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
Mohammad Shaker
 
Interaction Design L03 - Color
Interaction Design L03 - Color
Mohammad Shaker
 
Interaction Design L05 - Typography
Interaction Design L05 - Typography
Mohammad Shaker
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
Mohammad Shaker
 
Android L04 - Notifications and Threading
Android L04 - Notifications and Threading
Mohammad Shaker
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
Mohammad Shaker
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
Mohammad Shaker
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
Mohammad Shaker
 
Android L10 - Stores and Gaming
Android L10 - Stores and Gaming
Mohammad Shaker
 
Android L06 - Cloud / Parse
Android L06 - Cloud / Parse
Mohammad Shaker
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
Mohammad Shaker
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes
Mohammad Shaker
 
Android L02 - Activities and Adapters
Android L02 - Activities and Adapters
Mohammad Shaker
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to Games
Mohammad Shaker
 
Indie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSeven
Mohammad Shaker
 
Indie Series 02: AI and Recent Advances in Games
Indie Series 02: AI and Recent Advances in Games
Mohammad Shaker
 
Roboconf DSL Advanced Software Engineering
Roboconf DSL Advanced Software Engineering
Mohammad Shaker
 

Recently uploaded (20)

Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Automated Testing and Safety Analysis of Deep Neural Networks
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
declaration of Variables and constants.pptx
declaration of Variables and constants.pptx
meemee7378
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
Complete WordPress Programming Guidance Book
Complete WordPress Programming Guidance Book
Shabista Imam
 
Sysinfo OST to PST Converter Infographic
Sysinfo OST to PST Converter Infographic
SysInfo Tools
 
Automated Testing and Safety Analysis of Deep Neural Networks
Automated Testing and Safety Analysis of Deep Neural Networks
Lionel Briand
 
Heat Treatment Process Automation in India
Heat Treatment Process Automation in India
Reckers Mechatronics
 
Building Geospatial Data Warehouse for GIS by GIS with FME
Building Geospatial Data Warehouse for GIS by GIS with FME
Safe Software
 
HYBRIDIZATION OF ALKANES AND ALKENES ...
HYBRIDIZATION OF ALKANES AND ALKENES ...
karishmaduhijod1
 
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
OpenChain Webinar - AboutCode - Practical Compliance in One Stack – Licensing...
Shane Coughlan
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
A Guide to Telemedicine Software Development.pdf
A Guide to Telemedicine Software Development.pdf
Olivero Bozzelli
 
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Folding Cheat Sheet # 9 - List Unfolding 𝑢𝑛𝑓𝑜𝑙𝑑 as the Computational Dual of ...
Philip Schwarz
 
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
From Code to Commerce, a Backend Java Developer's Galactic Journey into Ecomm...
Jamie Coleman
 
declaration of Variables and constants.pptx
declaration of Variables and constants.pptx
meemee7378
 
Download Adobe Illustrator Crack free for Windows 2025?
Download Adobe Illustrator Crack free for Windows 2025?
grete1122g
 
Digital Transformation: Automating the Placement of Medical Interns
Digital Transformation: Automating the Placement of Medical Interns
Safe Software
 
Y - Recursion The Hard Way GopherCon EU 2025
Y - Recursion The Hard Way GopherCon EU 2025
Eleanor McHugh
 
Simplify Insurance Regulations with Compliance Management Software
Simplify Insurance Regulations with Compliance Management Software
Insurance Tech Services
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Best Practice for LLM Serving in the Cloud
Best Practice for LLM Serving in the Cloud
Alluxio, Inc.
 
Azure AI Foundry: The AI app and agent factory
Azure AI Foundry: The AI app and agent factory
Maxim Salnikov
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 

WPF L03-3D Rendering and 3D Animation

  • 1. Mohammad Shaker mohammadshaker.com WPF Starter Course @ZGTRShaker 2011, 2012, 2013, 2014 WPF Showcase L03 – 3D Rendering and 3D Animations
  • 10. 3D Models • With Texturing!
  • 13. Tools to fire up a 3D Area!
  • 14. Tools to fire up a 3D Area! • Set the desired area – Viewport3D • Light the area with a DirectionalLight! – new ModelVisual3D { Content = new DirectionalLight { Color = Colors.White, Direction = new Vector3D(0, 0, -1) } }); • Set a camera to look around! – PerspectiveCamera
  • 18. The Craziness of Code Behind!
  • 19. 3D Rendering What do u need to create a cuboid?!
  • 20. So, Let’s start! • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want!
  • 21. 3D Rendering • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid!
  • 22. 3D Rendering • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid! <Viewport3D Name="viewport3D"> <ModelVisual3D> <ModelVisual3D.Content> <DirectionalLight Color="White" Direction="-2,-3,-1" /> </ModelVisual3D.Content> </ModelVisual3D> </Viewport3D>
  • 23. 3D Rendering • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid!
  • 24. 3D Rendering • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid!
  • 25. Set a camera to look around! • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid! class CameraManagement { public PerspectiveCamera Camera { set; get; } public CameraManagement(Viewport3D viewport3D) { this.Camera = new PerspectiveCamera(); this.Camera.FarPlaneDistance = 500; this.Camera.NearPlaneDistance = 1; // LookDirection this.Camera.LookDirection = new Vector3D(-10, -15, -25); // UpDirection this.Camera.UpDirection = new Vector3D(0, 1, 0); // Position this.Camera.Position = new Point3D(50, 100, 150); this.Camera.FieldOfView = 70; this.Camera.Transform = new Transform3DGroup(); viewport3D.Camera = this.Camera; } }
  • 26. Set a camera to look around! • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid! public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CameraManagement cameraManagement = new CameraManagement(viewport3D); } }
  • 27. 3D Rendering • Set the desired area • Light the area with a DirectionalLight! • Set a camera to look around! • Draw whatever u want! – Our Cuboid!
  • 28. 3D Rendering 1. Set the desired area 2. Light the area with a DirectionalLight! 3. Set a camera to look around! 4. Draw whatever u want! – Our Cuboid! • What do u need to create a Cuboid?! • Bunch of Triangles!
  • 29. 3D Rendering 1. Set the desired area 2. Light the area with a DirectionalLight! 3. Set a camera to look around! 4. Draw whatever u want! – Our Cuboid! • What do u need to create a Cuboid?! • Bunch of 16 Triangles!
  • 30. 3D Rendering class Triangle { public static Model3DGroup CreateTriangleModelGroup(Point3D p0, Point3D p1, Point3D p2, Color myColor) { MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions.Add(p0); mesh.Positions.Add(p1); mesh.Positions.Add(p2); mesh.TriangleIndices.Add(0); mesh.TriangleIndices.Add(1); mesh.TriangleIndices.Add(2); Material material = new DiffuseMaterial(new SolidColorBrush(myColor)); GeometryModel3D model = new GeometryModel3D(mesh, material); Model3DGroup group = new Model3DGroup(); group.Children.Add(model); return group; } }
  • 31. 3D Rendering class Cuboid { public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color) { Model3D model = CreateModelGroup(initialPosition, length, width, height, color); ModelVisual3D visualModel = new ModelVisual3D(); visualModel.Content = model; viewport3D.Children.Add(visualModel); } private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color) { Model3DGroup group = new Model3DGroup(); // *HERE* // return group; } public static Point3D GetSummedPoint(Point3D p1, Point3D p2) { Point3D myPoint = new Point3D(); // Manipulate Coordinates myPoint.X = p1.X + p2.X; myPoint.Y = p1.Y + p2.Y; myPoint.Z = p1.Z + p2.Z; return myPoint; } }
  • 32. 3D Rendering class Cuboid { public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color) { Model3D model = CreateModelGroup(initialPosition, length, width, height, color); ModelVisual3D visualModel = new ModelVisual3D(); visualModel.Content = model; viewport3D.Children.Add(visualModel); } private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color) { Model3DGroup group = new Model3DGroup(); // *HERE* // return group; } public static Point3D GetSummedPoint(Point3D p1, Point3D p2) { Point3D myPoint = new Point3D(); // Manipulate Coordinates myPoint.X = p1.X + p2.X; myPoint.Y = p1.Y + p2.Y; myPoint.Z = p1.Z + p2.Z; return myPoint; } } //* HERE *// Point3D p0 = initialPosition; Point3D p1 = GetSummedPoint(initialPosition, new Point3D(width, 0, 0)); Point3D p2 = GetSummedPoint(initialPosition, new Point3D(width, 0, length)); Point3D p3 = GetSummedPoint(initialPosition, new Point3D(0, 0, length)); Point3D p4 = GetSummedPoint(initialPosition, new Point3D(0, height, 0)); Point3D p5 = GetSummedPoint(initialPosition, new Point3D(width, height, 0)); Point3D p6 = GetSummedPoint(initialPosition, new Point3D(width, height, length)); Point3D p7 = GetSummedPoint(initialPosition, new Point3D(0, height, length)); //front side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p3, p2, p6, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p3, p6, p7, color)); //right side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p1, p5, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p5, p6, color)); //back side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p1, p0, p4, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p1, p4, p5, color)); //left side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p0, p3, p7, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p0, p7, p4, color)); //top side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p7, p6, p5, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p7, p5, p4, color)); //bottom side triangles group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p3, p0, color)); group.Children.Add(Triangle.CreateTriangleModelGroup(p2, p0, p1, color));
  • 33. 3D Rendering class Cuboid { public Cuboid(Viewport3D viewport3D, Point3D initialPosition, double length, double width, double height, Color color) { Model3D model = CreateModelGroup(initialPosition, length, width, height, color); ModelVisual3D visualModel = new ModelVisual3D(); visualModel.Content = model; viewport3D.Children.Add(visualModel); } private Model3D CreateModelGroup(Point3D initialPosition,double length, double width, double height, Color color) { Model3DGroup group = new Model3DGroup(); // *HERE* // return group; } public static Point3D GetSummedPoint(Point3D p1, Point3D p2) { Point3D myPoint = new Point3D(); // Manipulate Coordinates myPoint.X = p1.X + p2.X; myPoint.Y = p1.Y + p2.Y; myPoint.Z = p1.Z + p2.Z; return myPoint; } }
  • 34. 3D Rendering • Now just call and play! :D public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CameraManagement cameraManagement = new CameraManagement(viewport3D); Cuboid myFirstCuboid = new Cuboid(viewport3D, new Point3D(0, 0, 0), 40, 40, 40, Colors.Red); } }
  • 36. 3D Rendering public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); CameraManagement cameraManagement = new CameraManagement(viewport3D); Cuboid myFirstCuboid = new Cuboid(viewport3D, new Point3D(0, 0, 0), 50, 60, 10, Colors.Red); } }
  • 40. Project “Track-Ball” Provided by the WPF team 3-D tools Visit: http://www.codeplex.com/3DTools/ <Window xmlns:tools="clr-namespace:_3DTools;assembly=3DTools"... > Then you can easily add the TrackballDecorator to your markup: <tools:TrackballDecorator> <Viewport3D> ... </Viewport3D> </tools:TrackballDecorator> Hit Testing
  • 49. Viewport2DVisual3D • What’s needed to show 2D components in 3D environment?!
  • 50. Viewport2DVisual3D • What’s needed to show 2D components in 3D environment?!
  • 51. Viewport2DVisual3D • What’s needed to show 2D components in 3D environment?!
  • 52. Viewport2DVisual3D private void CreateMeshGeometry(Point3D initialPoint) { double pointParam = 0.5; initialPoint.X = -initialPoint.X; initialPoint.Y = -initialPoint.Y; initialPoint.Z = -initialPoint.Z; MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions = new Point3DCollection { HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint), HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ), HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint), HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint) }; mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }); mesh.TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }); this._viewport2DVisual3D.Geometry = mesh; var material = new DiffuseMaterial { Brush = Brushes.White }; Viewport2DVisual3D.SetIsVisualHostMaterial(material, true); this._viewport2DVisual3D.Material = material; }
  • 53. Viewport2DVisual3D private void CreateMeshGeometry(Point3D initialPoint) { double pointParam = 0.5; initialPoint.X = -initialPoint.X; initialPoint.Y = -initialPoint.Y; initialPoint.Z = -initialPoint.Z; MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions = new Point3DCollection { HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint), HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ), HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint), HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint) }; mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }); mesh.TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }); this._viewport2DVisual3D.Geometry = mesh; var material = new DiffuseMaterial { Brush = Brushes.White }; Viewport2DVisual3D.SetIsVisualHostMaterial(material, true); this._viewport2DVisual3D.Material = material; }
  • 54. Viewport2DVisual3D private void CreateMeshGeometry(Point3D initialPoint) { double pointParam = 0.5; initialPoint.X = -initialPoint.X; initialPoint.Y = -initialPoint.Y; initialPoint.Z = -initialPoint.Z; MeshGeometry3D mesh = new MeshGeometry3D(); mesh.Positions = new Point3DCollection { HelperClass.GetSummedPoint(new Point3D(-pointParam, pointParam, 0),initialPoint), HelperClass.GetSummedPoint(new Point3D(-pointParam, -pointParam, 0),initialPoint ), HelperClass.GetSummedPoint(new Point3D(pointParam, -pointParam, 0), initialPoint), HelperClass.GetSummedPoint(new Point3D(pointParam, pointParam, 0),initialPoint) }; mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 0, 2, 3 }); mesh.TextureCoordinates = new PointCollection(new Point[] { new Point(0, 0), new Point(0, 1), new Point(1, 1), new Point(1, 0) }); this._viewport2DVisual3D.Geometry = mesh; var material = new DiffuseMaterial { Brush = Brushes.White }; Viewport2DVisual3D.SetIsVisualHostMaterial(material, true); this._viewport2DVisual3D.Material = material; }
  • 55. Viewport2DVisual3D • So how can we add 2D Components?!
  • 56. Viewport2DVisual3D • So how can we add 2D Components?! – So easy!
  • 57. Viewport2DVisual3D • So how can we add 2D Components?! – So easy! _viewport2DVisual3D.Visual = InitializeVisualArea(); private StackPanel InitializeVisualArea() { StackPanel stackPanel = new StackPanel(); TextBlock textBlock = new TextBlock(); textBlock.Text = "Name: " + StudentInfo.Name + Environment.NewLine + "ID: "+ StudentInfo.Id; Button button = new Button(); button.Content = "Rotate Me!"; button.Click += new RoutedEventHandler(button_Click); stackPanel.Children.Add(textBlock); stackPanel.Children.Add(button); return stackPanel; }
  • 58. Viewport2DVisual3D • So how can we add 2D Components?! – So easy! _viewport2DVisual3D.Visual = InitializeVisualArea(); private StackPanel InitializeVisualArea() { StackPanel stackPanel = new StackPanel(); TextBlock textBlock = new TextBlock(); textBlock.Text = "Name: " + StudentInfo.Name + Environment.NewLine + "ID: "+ StudentInfo.Id; Button button = new Button(); button.Content = "Rotate Me!"; button.Click += new RoutedEventHandler(button_Click); stackPanel.Children.Add(textBlock); stackPanel.Children.Add(button); return stackPanel; } public StudentInfo StudentInfo { get{return _studentInfo;} set{_studentInfo = value;} }
  • 61. Animating Viewport2DVisual3D! • Just a Rotation public static void CreateViewportConstantRotationAnimationAroundX(Viewport2DVisual3D viewport2DVisual3D) { // Create Animation Around X Axis var rotationAnimationAroundXAxis = new Rotation3DAnimation(); rotationAnimationAroundXAxis.From = new AxisAngleRotation3D { Angle = 0, Axis = new Vector3D(0, 1, 0) // Y Axis }; rotationAnimationAroundXAxis.To = new AxisAngleRotation3D { Angle = 20, Axis = new Vector3D(0, 1, 0) // Y Axis }; rotationAnimationAroundXAxis.Duration = new Duration(TimeSpan.FromSeconds(2)); rotationAnimationAroundXAxis.AutoReverse = true; rotationAnimationAroundXAxis.RepeatBehavior = RepeatBehavior.Forever; // Define Property to animate viewport2DVisual3D.Transform.BeginAnimation(RotateTransform3D.RotationProperty, rotationAnimationAroundXAxis); }
  • 63. Animating Viewport2DVisual3D public static void CreateViewportFlipAnimation(Viewport2DVisual3D viewport2DVisual3D, Point3D position) { // Create Animation Rotation3DAnimation FlipAnimation = new Rotation3DAnimation(); FlipAnimation.From = new AxisAngleRotation3D { Angle = 0, Axis = new Vector3D(1, 0, 0) // X Axis }; FlipAnimation.To = new AxisAngleRotation3D { Angle = 180, Axis = new Vector3D(1, 0, 0) // X Axis }; FlipAnimation.Duration = new Duration(TimeSpan.FromSeconds(1)); FlipAnimation.AutoReverse = true; // Define Property to animate RotateTransform3D rotateTransform3D = new RotateTransform3D(); rotateTransform3D.CenterZ = - position.Z; rotateTransform3D.BeginAnimation(RotateTransform3D.RotationProperty, FlipAnimation); viewport2DVisual3D.Transform = rotateTransform3D; }
  • 64. Animating Viewport2DVisual3D public static void CreateViewportFlipAnimation(Viewport2DVisual3D viewport2DVisual3D, Point3D position) { // Create Animation Rotation3DAnimation FlipAnimation = new Rotation3DAnimation(); FlipAnimation.From = new AxisAngleRotation3D { Angle = 0, Axis = new Vector3D(1, 0, 0) // X Axis }; FlipAnimation.To = new AxisAngleRotation3D { Angle = 180, Axis = new Vector3D(1, 0, 0) // X Axis }; FlipAnimation.Duration = new Duration(TimeSpan.FromSeconds(1)); FlipAnimation.AutoReverse = true; // Define Property to animate RotateTransform3D rotateTransform3D = new RotateTransform3D(); rotateTransform3D.CenterZ = - position.Z; rotateTransform3D.BeginAnimation(RotateTransform3D.RotationProperty, FlipAnimation); viewport2DVisual3D.Transform = rotateTransform3D; }
  • 66. Animating Camera! • Just a Point3DAnimation public static void MoveCameraDynamicallyWithUserInput(PerspectiveCamera camera, Point3D targettedPosition) { if (camera.Position!= targettedPosition) { Point3DAnimation animation = new Point3DAnimation(); animation.From = camera.Position; animation.To = targettedPosition; animation.Duration = new Duration(TimeSpan.FromSeconds(1.5)); camera.BeginAnimation(PerspectiveCamera.PositionProperty,animation); } }
  • 67. Now test it and see what you got!
  • 68. Happy end of course!
  • 69. I really had so much fun! Hope you are too!
  • 70. Take a Look on my other courses @ http://www.slideshare.net/ZGTRZGTR Available courses to the date of this slide: C# Starter, C# Advanced, WPF, C++.NET, XNA, OpenGL, Delphi