Window Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Sunday, 25 July 2010

Silverlight On Mobile : 3D on your Windows Phone 7 with Silverlight

Posted on 06:02 by Unknown

With my last “Hello World” post, I am sure you must be in position to write some basic apps for your Windows Phone 7. Now we already spend some time to explore basics of Phone and other Development Environment. Now from this article onwards let’s try to look further.

3D in Silverlight is nothing new to us now since it has been made available to us by Microsoft from Silverlight Version 3. Since most of the features of version 3 are well supported on phone, 3D is one of them. Open a new Windows Phone Project and Open a Blend Instance to design your app. My 3D app look like this :

Blend3D


To demonstrate 3D, I have a simple Stack Panel over here and I have put one cool Super Mario Image inside that (Image is taken from Internet and have its own respective copyrights). To showcase 3D, I have taken 3 scrolls which will allow us to rotate the Image along X,Y and Z axis. Initial values for all of the three will be 0 like this :

<StackPanel.Projection>
                <PlaneProjection
                   RotationX="0"
                   RotationY="0"
                   RotationZ="0"/>
</StackPanel.Projection>

3D in Silverlight is mainly achieve by “Plane Projection” class under System.Windows.Media namespace.Plane Projection Class gives you certain Methods and Properties, Plane Projection helps you to set orientation across X,Y and Z axis with properties like RotationX,Y and Z respectively.Now UIElement have property as Projection. You can even set the Center of Rotation with CenterOfRotationX,Y and Z property respectively.

XAML Code :

<Grid x:Name="ContentGrid" Grid.Row="1" Grid.ColumnSpan="5" Grid.RowSpan="3">
           <TextBlock Margin="22,0,0,0" Foreground="Black" VerticalAlignment="Top" HorizontalAlignment="Left" Width="31"><Run Text="X:"/></TextBlock>
           <Slider Margin="8,7,0,0" x:Name="Slider1" Maximum="360" Minimum="-360"  ValueChanged="Slider1_ValueChanged" Height="78" VerticalAlignment="Top" HorizontalAlignment="Left" Width="201" />
           <TextBlock Margin="120,42,0,0" Foreground="Black" VerticalAlignment="Top" HorizontalAlignment="Left" Width="25"><Run Text="Y:"/></TextBlock>
           <Slider Margin="106,46,173,0" x:Name="Slider2" Maximum="360" Minimum="-360" ValueChanged="Slider2_ValueChanged" Height="80" VerticalAlignment="Top" />
           <TextBlock Margin="215,79,0,0" Foreground="Black" VerticalAlignment="Top" HorizontalAlignment="Left" Width="24"><Run Text="Z:"/></TextBlock>
           <Slider Margin="202,86,91,0" x:Name="Slider3" Maximum="360" Minimum="-360" ValueChanged="Slider3_ValueChanged" Height="80" VerticalAlignment="Top" />
           <StackPanel x:Name="MyStack" Margin="0,232,0,0">
               <StackPanel.Projection>
                   <PlaneProjection
                  RotationX="0"
                  RotationY="0"
                  RotationZ="0"
                  />
               </StackPanel.Projection>
               <Image x:Name="MyImg" Source="real-mario-face.jpg" Stretch="UniformToFill" Height="418" Canvas.Top="194"/>
           </StackPanel>
       </Grid>
   </Grid>

C# Code :

using System.Windows;
using System.Windows.Media;
using Microsoft.Phone.Controls;

namespace Demo_3D_Home
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void Slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            ((PlaneProjection)MyStack.Projection).RotationX = e.NewValue;
        }

        private void Slider2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            ((PlaneProjection)MyStack.Projection).RotationY = e.NewValue;
        }

        private void Slider3_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            ((PlaneProjection)MyStack.Projection).RotationZ = e.NewValue;
        }
    }
}

Once you execute application,It will look like this on emulator :

MarioDesk

Now once you start scrolling for corresponding X,Y and Z axis, You will get following outputs for X,Y and Z respectively.

MarioXMarioYMarioZ

So, This is how you can implement 3D on your Windows Phone 7 with the help of Silverlight on Mobile. In reality you can plug this 3D feature on your phone for some Object Representation or Images.This module can be further enhance by adding some animations to it. So its upto your creativity now, Sky is the limit !

Hope you like this feature and I assume you will start putting it in your apps. I am soon covering some more and odd features and then I will go for DataBinding and Service calls etc. which falls in Business Applications category.

Vikram.

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • First Windows Phone 7 update February 2011 - Small update but Big start
    After tons of rumors and set of predictions on Windows Phone 7 all over Internet, Microsoft came up with first Windows Phone 7 minor update ...
  • The little Story of “I Unlock Joy” event by Microsoft and Pune User Group
      This post is about recent “I Unlock Joy” event happened in Pune which was conducted by Microsoft and Pune User Group. Little History : ...
  • Silverlight On Mobile : Windows Phone 7 Splash Screen and Customization
    After talking about 3D capabilities on Windows Phone 7 using Silverlight in last article , Now I am moving ahead with small but equally impo...
  • Silverlight 5 : Platform Invoke (PInvoke) in Silverlight
      Two days back Microsoft announced availability of Silverlight 5 RC,I encourage you to download bits from here , My friend Pete Brown alr...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 1
    After a long..I am writing blog, I hope and I wish I will resume blogging like I use to in past. Lots of things happened in past few months....
  • MCTS : Microsoft Silverlight 4 Development Exam Guide (70-506) by Packt Publishing
      Hello, After a long time I got chance to come back here.I will soon resume blogging in month of August. Last 4-5 months were horrible due...
  • Introduction to Speech Capabilities in Windows Phone 8 – Part 2
    Hope you enjoyed my last article on Speech Capability in Windows Phone 8, Today I am posting another part or you can say little extension t...
  • Silverlight 3 : Insert & Update Data using WCF Service with DataForm and DataGrid
    In my Lap around Silverlight 3 series, I have written a separate article on DataForm in Silverlight 3, This article is a basic extension to ...
  • Mango : Using DeviceStatus in Windows Phone 7.1
    First of all “Thank You” for your wonderful response and comments on my last article on Silverlight Vs HTML5 ,I hope you like the points I ...
  • Silverlight, HTML5 & Windows 8 : Where we are heading to ?
    This is not the post or yet another post on most happening debate of Silverlight and HTML5, This is just a visit to all of them to realize t...

Blog Archive

  • ►  2013 (4)
    • ►  August (1)
    • ►  April (3)
  • ►  2012 (4)
    • ►  July (1)
    • ►  March (2)
    • ►  January (1)
  • ►  2011 (24)
    • ►  December (1)
    • ►  September (4)
    • ►  August (2)
    • ►  July (1)
    • ►  June (4)
    • ►  May (3)
    • ►  April (3)
    • ►  March (1)
    • ►  February (4)
    • ►  January (1)
  • ▼  2010 (21)
    • ►  December (1)
    • ►  November (2)
    • ►  October (3)
    • ►  September (2)
    • ►  August (4)
    • ▼  July (5)
      • Silverlight On Mobile : 3D on your Windows Phone 7...
      • Silverlight on Mobile : Write your first Windows P...
      • Silverlight on Mobile : Get Ready with the Tools a...
      • Silverlight on Mobile : Getting started
      • I am Silverlight MVP
    • ►  May (1)
    • ►  April (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2009 (49)
    • ►  December (1)
    • ►  November (5)
    • ►  October (2)
    • ►  September (1)
    • ►  August (5)
    • ►  July (5)
    • ►  June (1)
    • ►  May (5)
    • ►  April (5)
    • ►  March (9)
    • ►  February (4)
    • ►  January (6)
  • ►  2008 (43)
    • ►  December (3)
    • ►  November (9)
    • ►  October (7)
    • ►  September (4)
    • ►  August (2)
    • ►  July (3)
    • ►  June (4)
    • ►  May (3)
    • ►  March (3)
    • ►  February (5)
Powered by Blogger.

About Me

Unknown
View my complete profile