Often, by raising new reporting models, and even new models of interaction, display the need for 3D objects or components in our interfaces.
Speaking of 3D, it is necessary to clarify what we mean kind of 3D. Hereinafter referred to as "simulated 3D" the set of visual techniques to simulate three dimensions, and "real 3D" the set of tools / techniques that support for:
- Management of space in three dimensions (x, y , z)
- Creating and editing three-dimensional models
- Application of 3D transformations (motion, scaling, rotation)
- Provision
camera - 3D Lighting
Silverlight, in the absence of, for example, the library System.Windows.Media3D WPF does not support 3D. Nevertheless, there are several ways to dispose of 3D elements in our interfaces.
Parallax (3D simulation)
The Parallax is a 3D simulation based on two aspects: the relative difference in size and the relative difference in movement between the elements that are near and those far away.
Car.cs
public class Car {
private int xPosition;
private int yPosition;
private int zPosition;
}
CarCollection.cs
public class CarCollection
{
private List
public List
{
get { return cars; }
set { cars = value; }
}
}
CarShow.xaml
CarShow.xaml.cs
private void FillCanvasWithCars()
{Random rand = new Random ();
/ / For every car we will create an image of the car and placed it on the Canvas 'cnvCars'
for (int i = 0; i < Carcollection.Cars.Count; i++)
{
/ / Create the image
car
Image = new Image ();
BitmapImage
car.Source = new (new Uri ("../ images / car.png "UriKind.Relative)) ;
/ / calculate, depending on how far you are, how we need to reduce
double scalefactor = 1;
if (Carcollection.Cars [i]. Zposition> 0)
scalefactor = carOriginalSize / Carcollection.Cars [i]. Zposition;
/ / Create the transformation of scaling
ScaleTransform ScaleTransform scaleCar = new () ;
scaleCar.ScaleX = scalefactor;
scaleCar.ScaleY = scalefactor;
/ / Create a translation transformation
TranslateTransform TranslateTransform translateCar = new ();
rand.NextDouble
translateCar.X = ( ) * this.cnvCars.ActualWidth;
rand.NextDouble translateCar.Y = () * this.cnvCars.ActualHeight;
/ / apply transformations from object center
car.RenderTransformOrigin = new Point (0.5, 0.5);
/ / apply transformations in order
transformations = new TransformGroup TransformGroup ();
/ / First
scaling always
transformaciones.Children.Add (scaleCar)
/ / And finally always Travel the
transformaciones.Children.Add (translateCar)
car.RenderTransform = transformations
}}
2.5D (Hybrid)
commonly known as 2.5D to applications that do not support real 3D, but allow projection of components / elements on any level. That is, allow perspective effects on its components.
Silverlight 2 does not allow projection effects to be applied in any of its components. Although you can get to emulate in the case of images.
The technique to achieve this is to create a 2D mesh using triangles - triangular paths - and develop behavior manually manage the movement of each of the points apply for projection.
completed this first step, it is necessary to decompose the image according to the positions of the vertices of the mesh, so that will be N images we will use as
One of the interesting points of Silverlight 3 (and which is now available in version 3 Beta Silverlight) is the ability to make projections of on any 3D plane through the property. Projection.
Or in other words, the ability to perform any kind of perspective on any object (images, video, buttons, text boxes, etc.).. This allows, for example, create whole pages as a 3D component.
MainPage.xaml
CenterOfRotationX = "0"
CenterOfRotationY = "0.5"
CenterOfRotationZ = "0"
RotationY = "45" />
Margin = "40,0,0, 0 "MaxWidth =" 250 "Stretch =" Uniform "/>
Swift3D (3D simulation)
Swift 3D is a 3D editing software created by ElectricRain (http://www.erain . com /) which, although not comparable - in terms of possibilities - with none of the major applications currently on the market (for 3D Studio MAX, Maya, etc.) does have a very interesting tool. Swift3D to export to XAML (2D) any scene and animation that is created inside.
Until version 4, the exported XAML Swift3D was only valid for WPF, but as of version 5 provides the ability to choose who "play "animation, if WPF or Silverlight, and code XAML generated depends on this.
Kit3D (real 3D)
Kit3D is a 3D graphics engine developed specifically for Silverlight by Mark Dawson (http://www.markdawson.org/Kit3D/), and aims to provide this tool offers the same capabilities System.Windows.Media.Media3D to WPF, so that the result of Silverlight applications developed with Kit3D are comparable to those produced by WPF3D.
would be, comparatively, the equivalent of Papervision3D (http://www.papervision3d.org/) or Astro (http://labs.adobe.com/technologies/flashplayer10/) in the case of Flash.
Kit3D allows, like WPF, defining and arranging objects Viewports3D (Even with color or texture), cameras and lights inside, apply 3D transformations of objects, or define and manage the 3D space.
But unlike WPF, not possible using XAML code, but everything must be generated using code behind. So the XAML code only house the container (usually a Canvas).
dynamically create a grid, however, can be a complex process. A mesh is formed from a set of 3D points, and how to relate to each other, so to define a 3D mesh is necessary to know (or estimate):
- the position (in 3D) of each of the vertices that make up the mesh.
- what are the two vertices with each vertex which is related to form a triangle (in any editing system 3D mesh is defined using polygons. Kit3D For, these are triangles).
- the normal vector to the visible surface of the triangle (to determine which side is the "up" and what is "down").
MainPage.xaml
MainPage.cs (Part 1 - add a reference to Kit3d.dll and we include in the code)
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Kit3D.Windows.Controls;
using Kit3D.Windows.Media;
using Kit3D.Windows.Media.Media3D;
EjemploCubo.Controles3D
namespace {public partial class
OurCube:
UserControl {
MainPage.cs (Part 2 - define the viewport, create the object, and add a perspective camera)
private Viewport3D viewport;
RotateTransform3D Rotate;
public OurCube()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Our_Cube_Loaded);
}
void Our_Cube_Loaded(object sender, RoutedEventArgs e)
{
ModelVisual3D Visual = new ModelVisual3D();
GeometryModel3D MyCube = new GeometryModel3D();
MyCube.Geometry = CreateCubeMesh();
MyCube.Material = new DiffuseMaterial(new
Kit3DBrush(new SolidColorBrush(Colors.Gray)));
Visual.Content = MyCube;
Transform3DGroup Transform = new Transform3DGroup();
Transform.Children.Add(new ScaleTransform3D(3, 3, 3));
Rotate = new RotateTransform3D();
Rotate.Rotation = new AxisAngleRotation3D();
Transform.Children.Add(Rotate);
MyCube.Transform = Transform;
viewport = new Viewport3D();
viewport.Camera = new PerspectiveCamera(
new Point3D(-5, 15, 25),
new Vector3D(5, -15, -25),
new Vector3D(0, 1, 0),
45);
viewport.Children.Add (Visual);
viewport.HorizontalAlignment = HorizontalAlignment.Stretch;
viewport.VerticalAlignment = VerticalAlignment.Stretch;
this.LayoutRoot.Children.Add (viewport);}
MainPage.cs (Part 3 - the function that creates the 3D mesh of the cube)
private
MeshGeometry3D CreateCubeMesh () {
MeshGeometry3D MeshGeometry3D mesh = new ();
/ / define the position of each of 3D points
mesh.Positions = new Point3DCollection
new Point3D {(-0.5,0.5,0.5)
new Point3D(0.5,0.5,0.5),
new Point3D(-0.5,-0.5,0.5),
new Point3D(0.5,-0.5,0.5),
new Point3D(0.5,0.5,-0.5),
new Point3D(-0.5, 0.5, -0.5),
new Point3D(0.5,-0.5,-0.5),
new Point3D(-0.5,-0.5,-0.5),
new Point3D(-0.5,0.5,-0.5),
new Point3D(-0.5,0.5,0.5),
new Point3D(-0.5,-0.5,-0.5),
new Point3D(-0.5,-0.5,0.5),
new Point3D(0.5,0.5,0.5),
new Point3D(0.5,0.5,-0.5),
new Point3D(0.5,-0.5,0.5),
new Point3D(0.5,-0.5,-0.5),
new Point3D (-0.5,0.5, -0.5),
new Point3D (0.5,0.5, -0.5), new Point3D
(-0.5,0.5,0.5)
new Point3D (0.5,0.5,0.5),
new Point3D (0.5, -0.5, -0.5),
new Point3D (-0.5, -0.5, -0.5),
new Point3D (0.5, -0.5,0.5),
new Point3D (-0.5, -0.5,0.5)
};
/ / define the association of 3D points including
mesh.TriangleIndices = new Int32Collection
{0, 2, 1, 1, 2, 3,
4, 6, 5, 5, 6, 7,
8, 10, 9, 9, 10, 11,
12, 14, 13, 13, 14, 15,
16, 18, 17, 17, 18, 19,
20, 22, 21, 21, 22, 23
};
return mesh;}
Theoretically, using this system, the representation of any mesh is possible, the complexity of its creation in code grows exponentially as the mesh away from a primitive (cubes, spheres, torus, etc.) or a simple object, so it is difficult to conceive of 3D meshes representing, for example, figures or real people.
Kit3D performance, as happens with Papervision3D in the case of Flash, is not noticeable. So far it is not feasible to raise interfaces with over 40,000 polygons, lighting and camera movement, because all processing is done by CPU (Kit3D as Silverlight 2, no GPU advantage), so its utility is limited to scenes with timely presence of 3D objects. Conclusions
During these past years we have seen the interaction between user and machine has changed dramatically with the advent of so-called NUI (Natural User Interface).
The advent of devices like the iPhone or Microsoft Surface, and systems that manage and tactile interactions, such as Windows 7, responds to the need to interact interfaces with a different way. A mode of interaction, object-based, not graphics, or text.
is why the 3D object begins to become relevant in reporting systems, it is the most common presentation in the real world, and everything suggests that it will soon also in new models of presentation and interaction .
methods, techniques and technologies described above do not cease to be a first approximation to this approach. A first step that will undoubtedly be followed by many