| By Miguel Katrib, Mario del Valle | Article Rating: |
|
| October 13, 2008 07:30 AM EDT | Reads: |
2,454 |
Before thinking in a 3D panel it's important to review the main issues solved by the bi-dimensional panels.
Positioning
If we only have a Canvas to arrange controls in the bi-dimensional space, we will need to calculate and recalculate formulas using the Left and Top properties and the size of the controls. To avoid the repetition of some recalculation patterns, WPF includes some specialized panels for the bi-dimensional world: StackPanel, Grid, etc. A common goal of all these panels is the ability to position their contained elements in a bi-dimensional area.
Resizing
In addition to the above positioning functionality, according to its kind of distribution logic the panels should decide the final size to visualize each element contained inside of them.
Arrange and Measure
The type Panel is the main class in the WPF bi-dimensional layout system. Panel and its descendant types solve the positioning and resizing problems using the Arrange and Measure methods of each contained UIElement. Measure finds the desired size requested by each contained element and Arrange is called to place and resize them according to the desired size obtained from the property DesiredSize (which is calculated by each call to Measure).
Unfortunately till now UIElement3D didn't have analogous methods for the 3D world as can be seen in the note in Figure 4.
Unhappily it seems that the 3D world won't have these essential methods then. However, the good news is that at least there is a feature (Transformations) that could help to mitigate the problem of positioning 3D elements without recalculating their placements.
Tri-Dimensional Transformations
As in the bi-dimensional space there are linear-transformations for the tri-dimensional world. These transformations can be applied to any element of type Visual3D or Model3D, and to the Camera. The 3D elements can be rotated, scaled, and translated throughout the RotateTransform3D, ScaleTransform3D, and TranslateTransform3D transformations. There is also a special transformation called Transform3DGroup that can be used to group and apply more than one transformation over the same element. In Listing 1 we use these transformations to place the models according to the layout logic.
Definition of the Panel3D
Listing 1 shows an approach to implementing a Panel3D. The default value for the property Transform of a Visual3D is MatrixTransform3D.Identity; that's why the method Move in Listing 1 asks for this value to know if the Transform property isn't explicitly set yet. The function of this Move method is to support moving elements according to the parameter offset using the transformations TranslateTransform3D and Transformation3DGroup.
The method OnVisualChildrenChanged calls the corresponding method of the base class ModelVisual3D and invokes the Arrange method when a new element is added to the panel. This Arrange method is abstract and must be implemented by the concrete descendants of Panel3D as we will see in the following case of a CubePanel.
Definition of a CubePanel
A CubePanel will be a sort of tri-dimensional grid that can be defined as a descendant of the type Panel3D overriding the Arrange method, as shown in Listing 2. A Grid in WPF allows elements to be added in a plane area, aligning them in rows and columns. The goal of a CubePanel is to add a third dimension so that if you want to put an element in some row and column, you can use YIndex instead of Row, XIndex instead of Column, with the ability to send the element back or bring it to the front with very realistic depth perspective using a ZIndex attached property. These indices refer to one of the coordinate descriptions declared in the collections XCoord and YCoord (equivalent to ColumnDescriptions and RowDescriptions of the Grid type) and the newest ZCoord. Accordingly, the SizeX, SizeY, and SizeZ properties define the dimensions of the whole CubePanel (see Listing 2).
A Pawn on the Chess Table
Listing 3 illustrates an application example of this CubePanel. The XAML code is used to place five planes, one sphere, and one cone as shown in Figure 5. The types SphereBuilder, PlaneBuilder, and ConeBuilder are essentially used to build the mesh of these figures. Their property Geometry returns a MeshGeometry3D bound to the Geometry property of the GeometryModel3D to get the result in Figure 5. We could discuss these types further but won't for want of space.
Conclusion
The WPF team is working hard to increment the primitives and basic capabilities of the API 3D. This article invites readers to dare to use the current capabilities of WPF to obtain 3D layout effects while waiting for the next generation of WPF 3D. Enjoy it!
Resources
- Natham, A. (2007). Windows Presentation Foundation Unleashed. SAMS Publications.
- Griffiths, I., and Sells, C. (2005). Programming Windows Presentation Foundation. O'Reilly.
- Petzold, C. (2006). Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation. Microsoft Press.
More about panels in WPF can be found in the following Spanish publications of the authors:
- Del Valle, M.; Sierra, I.; Hernández, Y.; and Katrib, M. "Cómo definir nuestros propios paneles personalizados en WPF." DotNetmanía No 35. Marzo 2007.
- Katrib, M.; Del Valle, M.; Sierra, I.; and Hernández, Y. "Windows Presentation Foundation." DotNetManía Cuaderno Técnico No 7. Netalia 2007.
- Del Valle, M.; Sierra, I.;Yamil Hernández, Y.; and Katrib, M. "Entrando en la tercera dimensión." DotNetmanía No 37. Mayo 2007.
Published October 13, 2008 Reads 2,454
Copyright © 2008 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Miguel Katrib
Miguel Katrib is a PhD and a professor in the Computer Science Department at the University of Havana. He is also the head of the WEBOO group dedicated to Web and object-oriented technologies. Miguel is also a scientific advisor in .NET for the software enterprise CARE Technologies, Denia, Spain.
More Stories By Mario del Valle
Mario del Valle is working toward his MS at the Computer Science Department at the University of Havana, and is a software developer at the WEBOO group dedicated to Web and object-oriented technologies.
- The Top 150 Players in Cloud Computing
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- Industry Experts Discuss the State of Cloud Computing
- Cloud Expo New York Call for Papers Now Open
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- US Federal Government is Major Cloud Computing Innovator
- Google Wave
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Adaptivity & Cloud Computing: Exclusive Q&A with CEO Tony Bishop
- 4th International Cloud Expo: Photo Album
- The Top 150 Players in Cloud Computing
- SYS-CON.TV: Cloud Computing Expo Power Panel
- Commercial vs Federal Cloud Computing
- Why IBM’s Server Chief Got Busted
- 1st Annual GovIT Expo: Letter from the Technical Chair
- Industry Experts Discuss the State of Cloud Computing
- Deputy CIO of the CIA to Keynote 1st Annual GovIT Expo
- SOA World Power Panel on SYS-CON.TV
- CIA was Headed to an Enterprise Cloud All Along: Jill Tummler Singer
- Cloud Expo New York Call for Papers Now Open
- 1st Annual Government IT Conference & Expo: Themes & Topics
- Stock in Focus: Dragon Capital
- The i-Technology Right Stuff
- Who Are The All-Time Heroes of i-Technology?
- Get the Message
- Where Are RIA Technologies Headed in 2008?
- i-Technology Viewpoint: Is Web 2.0 the Global SOA?
- i-Technology Viewpoint: Thinking Outside the VC Box
- ESB Myth Busters: 10 Enterprise Service Bus Myths Debunked
- i-Technology Viewpoint: When to Leave Your First IT Job
- SOA Web Services Edge Conference Coverage on SYS-CON.TV
- Five Reasons Why Web 2.0 Matters
- SYS-CON.TV's "SOA Web Services" and "Enterprise Open Source" Programs To Air in December
- SOA World Conference & Expo SYS-CON.TV Power Panel Live From Times Square









Cloud computing is a game changer. The cloud ...





















