<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silverlight Buzz &#187; Silverlight C# Tutorials</title>
	<atom:link href="http://www.silverlightbuzz.com/category/silverlight-c-sharp-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.silverlightbuzz.com</link>
	<description>Gavin Wignall Blogs about Silverlight tutorials and examples</description>
	<lastBuildDate>Wed, 23 Jun 2010 08:57:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Silverlight Brush Effect &#8211; Paint Splatter</title>
		<link>http://www.silverlightbuzz.com/2010/02/09/silverlight-brush-effect-paint-splatter/</link>
		<comments>http://www.silverlightbuzz.com/2010/02/09/silverlight-brush-effect-paint-splatter/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 13:52:50 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[Brush Effect]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Colour palette]]></category>
		<category><![CDATA[Designers]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Drag]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Paint]]></category>
		<category><![CDATA[Paint Splatter]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=814</guid>
		<description><![CDATA[Please upgrade your browser Using the Line element and some Random math I have created a paint splatter brush effect. Use...]]></description>
			<content:encoded><![CDATA[<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/PaintSplatter/paintSplats.html" frameborder="0" style="height:560px;width:560px;">Please upgrade your browser</iframe>
</div>
<p>Using the <strong><span style="color: #000000;">Line </span></strong>element and some <strong><span style="color: #000000;">Random </span></strong>math I have created a paint splatter brush effect. Use the color palette at the top of the example to change color and then draw using the mouse.</p>
<p>To create this effect, I plot lines one after the other using the Line element. Starting from the mouse co-ordinates and then using Random math to plot each further point. The length and size of each splatter is also set each time using Random math.</p>
<h2>To create a line using the Line component:</h2>
<p>To create a new line we perform the following</p>
<p><span style="color: #888888;"><em>Create a new Line and call it Line1&#8230;</em></span></p>
<p><span style="color: #000000;">Line Line1 = new Line();</span></p>
<p><span style="color: #888888;"><em>Set the start co-ordinates of the line&#8230;</em></span></p>
<p><span style="color: #000000;">Line1.X1 = 0;</span></p>
<p><span style="color: #000000;">Line1.Y1 = 0;</span></p>
<p><span style="color: #888888;"><em>Set the end co-ordinates of the line&#8230;</em></span></p>
<p><span style="color: #000000;">Line1.X2 = 10;</span></p>
<p><span style="color: #000000;">Line1.Y2 = 10;</span></p>
<p><span style="color: #888888;"><em>Add the line to the page&#8230;</em></span></p>
<p><span style="color: #000000;">LayoutRoot.Children.Add(Line1);</span></p>
<p><span style="color: #808080;">You can see another post I made on <a title="Building a Paint Application" href="http://www.silverlightbuzz.com/2009/03/15/building-a-paint-application-in-silverlight-using-the-line-element/" target="_self">building a Paint Application here</a>.</span></p>
<h2>To get a Random number we use the following code in C#:</h2>
<p><em><span style="color: #888888;">First define the variable&#8230;</span></em></p>
<p><span style="color: #000000;">private Random NextDouble = new Random();</span></p>
<p><em><span style="color: #888888;">Then each time you want a new Random number perform the following&#8230;</span></em></p>
<p><span style="color: #000000;">NextDouble.NextDouble();</span></p>
<p>This value will be of a double figure between 0 and 1. To get a specific range of random numbers we need to multiply this value.</p>
<p><em><span style="color: #888888;">To get a Random number between 0 and 100&#8230;</span></em></p>
<p><span style="color: #000000;">NextDouble.NextDouble() * 100;</span></p>
<p><em><span style="color: #888888;">To get a Random number between 50 and 100&#8230;</span></em></p>
<p><span style="color: #000000;">(NextDouble.NextDouble() * 50) + 50;</span></p>
<h2>Grab the Source</h2>
<p>As always, you can grab the <a title="Download the source files for this post" href="http://www.silverlightbuzz.com/examples/paintSplatter.zip" target="_self">source files to this post here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2010/02/09/silverlight-brush-effect-paint-splatter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mixing it up! Using the InkPresenter with 3D Projection</title>
		<link>http://www.silverlightbuzz.com/2010/02/04/mixing-it-up-using-the-inkpresenter-with-3d-projection/</link>
		<comments>http://www.silverlightbuzz.com/2010/02/04/mixing-it-up-using-the-inkpresenter-with-3d-projection/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 21:57:21 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight Blend Tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[Designers]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Paint]]></category>
		<category><![CDATA[Projection]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=805</guid>
		<description><![CDATA[Two great tools in Silverlight are the Projection properties and the InkPresenter, so what happens if you put the two...]]></description>
			<content:encoded><![CDATA[<p>Two great tools in Silverlight are the Projection properties and the InkPresenter, so what happens if you put the two together? Well, maybe something like below. Use the mouse to draw within the Silverlight area.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/drawingin3d/drawingIn3D.html" frameborder="0" style="height:350px;width:560px;">Please upgrade your browser</iframe>
</div>
<p>In this example I have used the InkPresenter to capture the mouse and produce vector paths. I also have a basic interface to change the colour and path size. I then use that captured data to duplicate the vector path upon 16 faces each rotating around a common point using the Projection properties.</p>
<p>The Projection properties in this example have been created inside Expression Blend using a storyboard activated by behaviors.</p>
<p>The InkPresenter control is this example has been created inside Expression Blend, but we need to do a bit of work in the code behind file to record the data and convert it into a visual path. You can read more about this process<a title="Learn how to use the InkPresenter control" href="http://msdn.microsoft.com/en-us/magazine/cc721604.aspx" target="_blank"> in this MSDN article</a>.</p>
<h2>Grab the Source</h2>
<p>As always, you can grab the <a title="Download the source files to this post here" href="http://www.silverlightbuzz.com/examples/projection3DShapes.zip">source files to this post here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2010/02/04/mixing-it-up-using-the-inkpresenter-with-3d-projection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shadow effect using 3D projection in Silverlight 3</title>
		<link>http://www.silverlightbuzz.com/2009/06/20/shadow-effect-using-3d-projection-in-silverlight-3/</link>
		<comments>http://www.silverlightbuzz.com/2009/06/20/shadow-effect-using-3d-projection-in-silverlight-3/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 01:14:20 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Projection]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Shadow]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=253</guid>
		<description><![CDATA[In the below example I use the new projection properties in Silverlight 3 to produce a realistic 3D shadow upon...]]></description>
			<content:encoded><![CDATA[<p>In the below example I use the new projection properties in Silverlight 3 to produce a realistic 3D shadow upon a sphere based on the mouse position on screen.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/shadowEffect/shadowEffect.html" frameborder="0" style="height:350px;width:490px;">Please upgrade your browser</iframe>
</div>
<p>In my previous 3 posts I played with the projection property as the primary effect. In this example I wanted to show how the projection property can be used as a more subtle effect, in this case a shadow based on the users mouse position. To view the previous 3 posts on projection please view the links below:</p>
<p><span style="text-decoration: none;"><strong><a href="http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/">Controlling Projection in Silverlight 3</a></strong></span></p>
<p><span style="text-decoration: none;"><strong><a href="http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/"></a><span style="font-weight: normal;"><a href="http://www.silverlightbuzz.com/2009/06/12/using-projection-to-build-a-3d-carousel-in-silverlight-3/"><span style="text-decoration: none;"><strong>Using projection to build a 3D carousel in Silverlight 3</strong></span></a></span></strong></span></p>
<p><a title="Permanent Link to Creating a 3D cube with images in Silverlight 3" rel="bookmark" href="http://www.silverlightbuzz.com/2009/06/16/creating-a-3d-cube-with-images-in-silverlight-3/"><span style="text-decoration: none;"><strong>Creating a 3D cube with images in Silverlight 3</strong></span></a></p>
<h2>The &#8216;how to&#8217; bit</h2>
<p>There are two effects that I create in the above example. The first is the lighting and the second is the shadow.</p>
<p>The first step is to run an event everytime the mouse is moved. Then to create the lighting effect, I first take the mouse position value and I use a small equation to give me a value that I can apply to a radial gradient&#8217;s &#8216;<strong>GradientOrigin</strong>&#8216; value. To control this i place an <strong>x:Name </strong>in the XAML called &#8220;<strong>lightAngle</strong>&#8220;:</p>
<p><em><strong>&lt;RadialGradientBrush x:Name=&#8221;LightAngle&#8221; GradientOrigin=&#8221;0.258,0.253&#8243;&gt;</strong></em></p>
<p>To create the shadow effect I use the  new projection properties given to us in Silverlight 3. I have drawn an ellipse with a radial gradient fill that goes from black to transparency. I then use the projection values in Blend to make the ellipse look like it is the shadow of the orignial red ball graphic. To animate the shadow I first take the mouse position value and use a series of equations to convert the values to apply to the projection <strong>globalOffest </strong>values of  <strong>LocalOffsetX </strong>and <strong>LocalOffsetY</strong>.</p>
<h2>The tricky bit</h2>
<p>To get the shadow to lie in the correct position we need to tell the LocalOffsetX value to point in the opposite direction to the mouse position. To do this we have to reverse the original value taken from the mouse. We can do this using the following equation:</p>
<p><span style="font-family: mceinline;">Mouse X position = A</span></p>
<p><em><strong>A = (A &#8211; (A * 2)) + 1</strong></em></p>
<p>or in my example (where Mouse X = pt.X)</p>
<p><em><strong>pt.X -= (pt.X * 2);</strong></em></p>
<p><em><strong>pt.X += 1;</strong></em></p>
<h2>Grab the code</h2>
<p>As always you can grab the source <a href="http://www.silverlightbuzz.com/examples/FilterEffectsShadow.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/06/20/shadow-effect-using-3d-projection-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a 3D cube with images in Silverlight 3</title>
		<link>http://www.silverlightbuzz.com/2009/06/16/creating-a-3d-cube-with-images-in-silverlight-3/</link>
		<comments>http://www.silverlightbuzz.com/2009/06/16/creating-a-3d-cube-with-images-in-silverlight-3/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 21:47:29 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Projection]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=247</guid>
		<description><![CDATA[In the below example I have used the new Projection properties in Silverlight 3 to create a3D cube that has a...]]></description>
			<content:encoded><![CDATA[<p>In the below example I have used the new Projection properties in Silverlight 3 to create a3D cube that has a different image on each face.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/ImageCube/ImageCube.html" frameborder="0" style="height:250px;width:490px;">Please upgrade your browser</iframe>
</div>
<h2>The ‘how to’ bit</h2>
<p>You can read more about using the new Projection properties in my 2 previous posts here:</p>
<p/>
<a href="http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/"> Controlling Projection in Silverlight 3</a><br />
<a href="http://www.silverlightbuzz.com/2009/06/12/using-projection-to-build-a-3d-carousel-in-silverlight-3/"> Using projection to build a 3D carousel in Silverlight 3</a></p>
<p/>
I use the same process with the 3D cube to control the movement dependant on the mouse position. To get the cube to work correctly I have had to use all three dimensions (X, Y and Z) of the projection properties. The more complicated the shape the harder it is to get all angles to move together. In the above example I have had to manipulate 12 projection values to get the cube to move correctly.</p>
<h2>Moving forward</h2>
<p>This example is still a fairly simple example of interaction, there is no reason that the images could not be updated dynamically or video be used instead. Also each image face could have it’s own navigation interface to spin to the next face.</p>
<h2>
Grab the code</h2>
<p>As always you can grab the code for the example in this post <a href="http://www.silverlightbuzz.com/examples/ImageCube.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/06/16/creating-a-3d-cube-with-images-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using projection to build a 3D carousel in Silverlight 3</title>
		<link>http://www.silverlightbuzz.com/2009/06/12/using-projection-to-build-a-3d-carousel-in-silverlight-3/</link>
		<comments>http://www.silverlightbuzz.com/2009/06/12/using-projection-to-build-a-3d-carousel-in-silverlight-3/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 21:18:22 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight Blend Tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Carousel]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=238</guid>
		<description><![CDATA[In the below example I used the new projection properties in Silverlight 3 to build a 3D image carousel. Moving...]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span>In the below example I used the new projection properties in Silverlight 3 to build a 3D image carousel. Moving the mouse left to right controls the speed and direction of the carousel. Moving the mouse up and down changes the opacity of the carousel, allowing you to see what is going on behind the carousel.</span></p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/ImageSpindle/ImageSpindle.html" frameborder="0" style="height:200px;width:490px;">Please upgrade your browser</iframe>
</div>
<h2><span>The &#8216;how to&#8217; bit</span></h2>
<p class="MsoNormal"><span>To start with I have placed 6 images inside Blend and used the projection properties to offset them against each other to form a 3 dimensional hexagon. I do this by changing 2 projection properties:</span></p>
<p class="MsoNormal"><strong>CenterOfRotationZ=&#8221;-173&#8243;</strong><strong></strong></p>
<p class="MsoNormal"><strong>RotationY=&#8221;60&#8243;</strong><span></span></p>
<p class="MsoNormal"><span>I use the &#8216;CenterOfRotationZ&#8217; value to move the center point away from each image plane. This value needs to be the same on each of the 6 images I use in order to get them to match up at the edges. I then use the &#8216;RotationY&#8217; value to change the angle of each image, as I have 6 images each image is rotated by a factor of 60 degrees (6 x 60 = 360 degrees).</span></p>
<p class="MsoNormal"><span>I then place an x:Name on each images projection tag as seen in the below example:</span></p>
<p class="MsoNormal"><strong>&lt;PlaneProjection x:Name=&#8221;Image1Projection&#8221; CenterOfRotationZ=&#8221;-173&#8243; RotationZ=&#8221;0&#8243;/&gt;</strong></p>
<p class="MsoNormal"><span>This will allow me to easily change the angle of each image dynamically in the C#.</span></p>
<p class="MsoNormal"><span>In the C# I set up a listener to monitor the mouse movement and store the values in &#8216;pt&#8217;:</span></p>
<p class="MsoNormal"><strong>void LayoutRoot_MouseMove(object sender, MouseEventArgs e)</strong><strong></strong></p>
<p class="MsoNormal"><strong>{</strong><strong></strong></p>
<p class="MsoNormal"><strong> pt = e.GetPosition(LayoutRoot);</strong><strong></strong></p>
<p class="MsoNormal"><strong>}</strong></p>
<p class="MsoNormal"><span>Next I set up a CompositionTarget.Rendering function so that I can update my 3 dimensional carousel constantly. I use the mouse X co-ordinates to change the speed and direction of the carousel and the mouse Y value to change the opacity:</span></p>
<p class="MsoNormal"><strong>void CompositionTarget_Rendering(object sender, EventArgs e)</strong><strong></strong></p>
<p class="MsoNormal"><strong>{</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image1Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image2Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image3Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image4Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image5Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> Image6Projection.RotationY += ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 10;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image1.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image2.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image3.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image4.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image5.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong> image6.Opacity = (pt.Y / LayoutRoot.ActualHeight) * 0.5 + 0.5;</strong><strong></strong></p>
<p class="MsoNormal"><strong>}</strong></p>
<h2><span>Grab the code</span></h2>
<p class="MsoNormal"><span>As always you can grab the code source </span><a href="http://www.silverlightbuzz.com/examples/ImageSpindle.zip">here</a><span>.</span></p>
<p class="MsoNormal">
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/06/12/using-projection-to-build-a-3d-carousel-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Controlling Projection in Silverlight 3</title>
		<link>http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/</link>
		<comments>http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 21:06:37 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 3 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Expression Blend]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Projection]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 3]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[XAML]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=224</guid>
		<description><![CDATA[In the below example I use the new Projection control to create a 3d effect based on the users mouse...]]></description>
			<content:encoded><![CDATA[<p>In the below example I use the new Projection control to create a 3d effect based on the users mouse position.</p>
<p>In Silverlight 3 we have 2 new variables to give us the ability to show perspective. We can use this effect on any item, including Images and Text. These 2 new variables are:</p>
<p><em><span style="color: #0000ff;">RotationY<br />
RotationX</span></em></p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/ProjectionEffect/ProjectionEffect.html" frameborder="0" style="height:490px;width:490px;">Please upgrade your browser</iframe>
</div>
<h2><span style="color: #000000;">Step by step</span></h2>
<p>Firstly, I place an x:Name called <strong>&#8216;ProjectionFactor&#8217;</strong> in the XAML. This gets placed in the &#8216;PlaneProjection&#8217; tag of the object I want to control:</p>
<p><em><span style="color: #808080;">&lt;Image Source=&#8221;images/sbLogo.png&#8221; Stretch=&#8221;Fill&#8221;&gt;<br />
&lt;Image.Projection&gt;<br />
&lt;PlaneProjection </span></em><span style="color: #0000ff;"><em><span style="color: #0000ff;">x:Name=&#8221;ProjectionFactor&#8221;</span></em></span><em><span style="color: #808080;"> RotationY=&#8221;0&#8243; RotationX=&#8221;0&#8243;/&gt;<br />
&lt;/Image.Projection&gt;<br />
&lt;/Image&gt;</span></em></p>
<p>I then set up a listener in the C# to capture when the mouse is moved. Everytime the mouse is moved I capture the mouse co-ordinates and use the values in the below equations to get the desired effect:</p>
<address><span style="color: #808080;">v</span><span style="color: #808080;">oid LayoutRoot_MouseMove(object sender, MouseEventArgs e)<br />
</span></address>
<address><span style="color: #808080;"> {<br />
</span></address>
<address><span style="color: #000000;"><span style="color: #008000;"><strong> //Get the mouse X and Y positions and store it in &#8216;pt&#8217;</strong></span><span style="color: #808080;"><br />
</span></span></address>
<address><span style="color: #808080;"> pt = e.GetPosition(LayoutRoot);<br />
</span></address>
<address><span style="color: #000000;"><span style="color: #008000;"><strong> //Use the values stored in &#8216;pt&#8217; to effect the value of &#8216;ProjectionFactor&#8217; </strong></span><span style="color: #808080;"><br />
</span></span></address>
<address><span style="color: #000000;"><span style="color: #808080;"> ProjectionFactor.</span><span style="color: #0000ff;">RotationY</span><span style="color: #808080;"> = ((pt.X &#8211; (LayoutRoot.ActualWidth / 2)) / LayoutRoot.ActualWidth) * 100;<br />
</span></span></address>
<address><span style="color: #000000;"><span style="color: #808080;"> ProjectionFactor.</span><span style="color: #0000ff;">RotationX</span><span style="color: #808080;"><span style="color: #0000ff;"> </span>= ((pt.Y &#8211; (LayoutRoot.ActualHeight / 2)) / LayoutRoot.ActualHeight) * 100;<br />
</span></span></address>
<address><span style="color: #808080;"> }</span></address>
<address><span style="color: #000000;"><br />
</span></address>
<h2><span style="font-style: normal; ">Grab the code</span></h2>
<address><span style="color: #000000;"><span style="font-style: normal;">As usual you can download the example files <a title="Grab the source" href="http://www.silverlightbuzz.com/examples/Projection.zip">here</a>.</span></span></address>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/06/10/controlling-projection-in-silverlight-3/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Using the mouse position to control movement</title>
		<link>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/</link>
		<comments>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/#comments</comments>
		<pubDate>Wed, 27 May 2009 15:30:40 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=218</guid>
		<description><![CDATA[In the below example we take the co-ordinates of the mouse and use that data to control the position of...]]></description>
			<content:encoded><![CDATA[<p>In the below example we take the co-ordinates of the mouse and use that data to control the position of another item. This can be used for sliders, menus, carousels etc;</p>
<p>I have written the code to adapt to the size of the scrollable area, you can see this by clicking on the &#8216;+&#8217; and &#8216;-&#8217; buttons. These will add / remove the items inside the scrollable area. If you remove enough items so that the area taken up is less than that of the screen, the items are positioned in the middle.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/menuSlider/menuSlider.html" frameborder="0" style="height:200px;width:490px;">Please upgrade your browser</iframe>
</div>
<p/>
To carry out this effect I need to keep track of the mouse position, the width of the screen and the width of the Stack panel containing the items. Each of these values need to be updated when ever they are changed.</p>
<p>I then position the movable area based on the following equations;</p>
<p><em><span style="color: #339966;">Where:</span></em><br />
a = Mouse X position<br />
b = Width of Screen area<br />
c = Width of area to be moved<br />
<em><span style="color: #339966;"> if movable area is bigger than screen area:</span></em><br />
moveable area X position = (a/b)*(b-c)<br />
<em><span style="color: #339966;"> if moveable area is smaller than screen area:</span></em><br />
moveable area X position = (b-c)/2</p>
<p>This equation is run every time a frame is rendered.</p>
<h2><span style="font-weight: normal;">T</span>he User Experience bit</h2>
<p>It is an important interaction that when working with scrolling content like this, especially when the content is a menu, to make sure that the direction of new content approaches the movement of the mouse.</p>
<h2><span style="font-weight: normal;">G</span>et the code</h2>
<p>As always you can download the example files <a href="http://www.silverlightbuzz.com/examples/MenuSlider.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/05/27/using-the-mouse-position-to-control-movement/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Zoom in and out using the Mouse wheel in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/#comments</comments>
		<pubDate>Tue, 19 May 2009 13:01:58 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverlight Effects]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Mouse position]]></category>
		<category><![CDATA[Mouse Wheel]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Zoom]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=203</guid>
		<description><![CDATA[Below is an example showing a simple zoom in / out interaction controlled via the mouse wheel, a slider and...]]></description>
			<content:encoded><![CDATA[<address>Below is an example showing a simple zoom in / out interaction controlled via the mouse wheel, a slider and some buttons.<span style="color: #ff0000;"> </span><span style="color: #808080;"><span style="color: #ff0000;">*Please note, mouse wheel functionality not currently working in the <strong>Google Chrome browser</strong>. Due to the Silverlight example being displayed within an iFrame you will experience issues with scrolling, to open the example in a new window click </span><a title="Mouse Wheel Scroll" href="http://www.silverlightbuzz.com/silverlightProjects/MouseWheelZoom/MouseWheelZoom.html" target="_blank"><span style="color: #ff0000;"><strong>here</strong></span></a><span style="color: #ff0000;">.</span></span></address>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/MouseWheelZoom/MouseWheelZoom.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br/>First off I add the following reference at the top of my C# file so that we can interact with the browser;</p>
<p><em><span style="color: #666699;">using System.Windows.Browser;</span></em></p>
<p>To then listen for the Mouse wheel interaction I set events in the browser using the following piece of C#;</p>
<p><em><span style="color: #666699;">HtmlPage.Window.AttachEvent(&#8220;DOMMouseScroll&#8221;, OnMouseWheel);<br />
HtmlPage.Window.AttachEvent(&#8220;onmousewheel&#8221;, OnMouseWheel);<br />
HtmlPage.Document.AttachEvent(&#8220;onmousewheel&#8221;, OnMouseWheel);</span></em></p>
<p>I can then check for a value to see if the mouse wheel is being moved forward or backward using the following Method;</p>
<p><em><span style="color: #666699;">private void OnMouseWheel(object sender, HtmlEventArgs args)<br />
{<br />
double mouseDelta = 0;<br />
ScriptObject e = args.EventObject;</span></em></p>
<p><em><span style="color: #666699;"><span style="color: #339966;"> // Mozilla and Safari</span><br />
if (e.GetProperty(&#8220;detail&#8221;) != null)<br />
{<br />
mouseDelta = ((double)e.GetProperty(&#8220;detail&#8221;));<br />
}<br />
<span style="color: #339966;"> // IE and Opera</span><br />
else if (e.GetProperty(&#8220;wheelDelta&#8221;) != null)<br />
mouseDelta = ((double)e.GetProperty(&#8220;wheelDelta&#8221;));<br />
mouseDelta = Math.Sign(mouseDelta);<br />
}</span></em></p>
<p>This now gives me a value in the form of &#8216;mouseDelta&#8217; which can be applied to what ever you want your interaction to be. In this case we are controlling the scale factor of a canvas.</p>
<p>To limit the scale factor I run a check to see if the scale value has gone under 1 or over 10 and if so reset the value to the minimum or maximum amount;</p>
<p><em><span style="color: #666699;">if (ScaleFactor.ScaleX &lt; 1)<br />
{<br />
ScaleFactor.ScaleX = 1;<br />
ScaleFactor.ScaleY = 1;<br />
}</span></em></p>
<p><em><span style="color: #666699;"> if (ScaleFactor.ScaleX &gt; 10)<br />
{<br />
ScaleFactor.ScaleX = 10;<br />
ScaleFactor.ScaleY = 10;<br />
}</span></em></p>
<p>I also check where the mouse cursor is and focus the zoom in / out on that position. I do this by storing the mouse co-ordinates everytime the user moves their mouse and then changing the &#8216;RenderTransformOrigin&#8217; value;</p>
<p><span style="color: #339966;">//get mouse co-ordinates</span><br />
<em><span style="color: #666699;"> void zoomArea_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
pt = e.GetPosition(zoomArea);<br />
}</span></em></p>
<p><span style="color: #339966;">//change the RenderTransformOrigin</span><span style="color: #666699;"><br />
</span><em><span style="color: #666699;"> zoomArea.RenderTransformOrigin = new Point(pt.X / zoomArea.Width, pt.Y / zoomArea.Height);</span></em></p>
<h2>Get the code</h2>
<p>You can download the above example <a href="http://www.silverlightbuzz.com/examples/PanAndZoom.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/05/19/zoom-in-and-out-using-the-mouse-wheel-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Rotation controlled direction using trigonometry and radians in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 15:22:02 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Radians]]></category>
		<category><![CDATA[Rotation]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=170</guid>
		<description><![CDATA[The below example shows an object being controlled by user input. To get the object to turn left or right...]]></description>
			<content:encoded><![CDATA[<p>The below example shows an object being controlled by user input. To get the object to turn left or right is a relatively simple procedure as seen below:</p>
<p><em>if (e.Key == Key.Left)<br />
{<br />
      </em><span style="color: #ff0000;"><strong><em>tankRotate.Angle -= 1;</em></strong></span><em><br />
}<br />
if (e.Key == Key.Right)<br />
{<br />
      </em><span style="color: #ff0000;"><strong><em>tankRotate.Angle += 1;</em></strong></span><em><br />
}</em><br />
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/RotationDirection/TestPage.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />The above example turns the object by 1 degree left or 1 degree right, you can use any value to make the object turn faster or slower.</p>
<p>To get the object to move forward in the direction it is facing is going to require our old friend &#8216;Trig&#8217; to take center stage. We can use the following formulae to calculate how far to move our object by its X and Y co-ordinates:</p>
<p><strong><span style="color: #ff0000;"><span style="color: #000000;"><span style="font-weight: normal;">Move X by:</span></span> Math.Cos(Angle) * Speed</span></strong></p>
<p><strong><span style="color: #ff0000;"><span style="color: #000000;"><span style="font-weight: normal;">Move Y by:</span></span> Math.Sin(Angle) * Speed</span></strong></p>
<p>Where <span style="color: #ff0000;"><strong>Angle </strong></span>is in radians.</p>
<h2>Radians</h2>
<p>1 radian is equal to 57.29577 degrees of a full circle. So if our object is turned at an angle of 57.29577 degrees it is equal to 1 radian. To work out the value of our angle in radians we can use the following formula:</p>
<p><span style="color: #ff0000;"><strong><span style="color: #000000;"><span style="font-weight: normal;">Radians =</span></span> Angle / 360 * 2 * Pi</strong></span></p>
<h2>Working out how much to move our object</h2>
<p><span style="color: #ff0000;"><em><span style="color: #000000;">i.e. <span style="font-style: normal;">if our object is turned to <span style="color: #ff0000;">45 </span>degrees and our required movement speed is <span style="color: #ff0000;">2</span>.</span></span></em></span></p>
<p><span style="color: #ff0000;"><em><span style="color: #000000;"></span></em></span></p>
<p><span style="color: #ff0000;"><strong>X += Math.Cos(45 / 360 * 2 * 3.14159) * 2;</strong></span></p>
<p><span style="color: #ff0000;"><strong>Y += Math.Sin(45 / 360 * 2 * 3.14159) * 2;</strong></span></p>
<h2><span style="color: #000000;">Applying this formula to the C#</span></h2>
<p>So to return to the example at the begining of this post. I use the below calculations to work out how much to increase or decrease the X and Y positions of my object:</p>
<p><em>if (e.Key == Key.Up) </em></p>
<p><em>{</em></p>
<p><span style="color: #ff0000;"><strong><em>        tankMovement.X += Math.Cos(tankRotate.Angle / 360 * 2 * 3.14159) * 1;</em></strong></span></p>
<p><span style="color: #ff0000;"><strong><em>        tankMovement.Y += Math.Sin(tankRotate.Angle / 360 * 2 * 3.14159) * 1;</em></strong></span></p>
<p><em>}</em></p>
<h2>Get the code</h2>
<p>Feel free to grab the <a href="http://www.silverlightbuzz.com/examples/RotationControlledDirection.zip">code here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/29/rotation-controlled-direction-using-trigonometry-and-radians-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Controlling an object using the Keydown function in Silverlight</title>
		<link>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/</link>
		<comments>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 01:10:38 +0000</pubDate>
		<dc:creator>Gavin Wignall</dc:creator>
				<category><![CDATA[All Silverlight Examples]]></category>
		<category><![CDATA[Silverlight 2 tutorials]]></category>
		<category><![CDATA[Silverlight C# Tutorials]]></category>
		<category><![CDATA[Silverllight Games]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Collision]]></category>
		<category><![CDATA[Direction]]></category>
		<category><![CDATA[Effects]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Silverlight 2]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[User Input]]></category>

		<guid isPermaLink="false">http://www.silverlightbuzz.com/?p=165</guid>
		<description><![CDATA[The below example shows an object being controlled by user input on a keyboard. I capture the &#8216;Keydown&#8216; event and...]]></description>
			<content:encoded><![CDATA[<p>The below example shows an object being controlled by user input on a keyboard. I capture the &#8216;<strong>Keydown</strong>&#8216; event and then check what keys are being pressed using a range of &#8216;<strong>if</strong>&#8216; statements.</p>
<p>Upon recognition of a key assigned to a direction, an increase (or decrease depending on direction) is made to a variable that is then applied to the the Helicopters &#8216;<strong>Canvas.setTop</strong>&#8216; or &#8216;<strong>Canvas.setLeft</strong>&#8216;.</p>
<div class="iframe-wrapper">
  <iframe src="http://www.silverlightbuzz.com/silverlightProjects/helicopter/TestPage.html" frameborder="0" style="height:400px;width:500px;">Please upgrade your browser</iframe>
</div><br />This movement is then applied every frame using the &#8216;<strong>CompositionTarget.Rendering</strong>&#8216; event.</p>
<p>The &#8216;Space bar&#8217; or Numeric &#8217;5&#8242; key will level the Helicopter out and stop it moving in any direction. This is done by reducing or increasing the movement in all directions until all values equal zero.</p>
<p>I constantly repeat 2 storyboards to animate the helicopter blades and make visible/collapse one of 5 graphics to display the helicopter facing in the relevant direction that it is moving in. Finally I constantly run a calculation to tilt (RotateTransform) the helicopter in the direction it is moving and making it level when not moving.</p>
<p>To save the user from loosing sight of the helicopter in the above example I have put in a collision check to make sure the helicopter can not fly outside of the viewable area. If the user controls the helicopter to fly past any boundary then the helicopters movement in that direction will be reset to zero.</p>
<h2>Next steps</h2>
<p>I would like to add a winch that can be dropped down below the helicopter. The winch could then be made to pick objects up and drop them on command.</p>
<h2>Get the code</h2>
<p>Feel free to grab the code <a href="http://www.silverlightbuzz.com/examples/HeliGame.zip">here</a> and start playing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.silverlightbuzz.com/2009/03/25/controlling-an-object-using-the-keydown-function-in-silverlight/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
