<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://pavanpodila.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fpavanpodila.spaces.live.com%2fcategory%2f3D%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>the WPF way...: 3D</title><description /><link>http://pavanpodila.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=cat3D</link><language>en-US</language><pubDate>Tue, 25 Mar 2008 03:33:19 GMT</pubDate><lastBuildDate>Tue, 25 Mar 2008 03:33:19 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://pavanpodila.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-7161136268153875560</live:id><live:alias>pavanpodila</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>An improved water effect</title><link>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!165.entry</link><description>&lt;p&gt;Sometime back I &lt;a href="http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!141.entry"&gt;posted a video of the Water ripple effect&lt;/a&gt; created using a 3D Mesh. In that I had only used a height-map to simulate the ripples which ofcourse wasn't the most convincing Water effect. This time around I have improved it with the some refraction effects happening to the texture. &lt;a href="http://en.wikipedia.org/wiki/Refraction"&gt;Refraction&lt;/a&gt; is the phenomenon where the light rays get bent when they change the medium of propagation; for example a change from air to water. Due to refraction the objects in the new medium appear displaced from their original positions. The amount of displacement is dependent on the Refraction Index of the medium. Water has a refractive index of 1.33. With this improvement the Water effect looks much better and closer to reality! &lt;p&gt;&lt;a href="http://video.google.com/videoplay?docid=1536259699335459617&amp;amp;hl=en"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px" height=384 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qlaUqgvS_wM2cTmFDEMy9d_fPYH6e1EBo_VyUTKHHG-v8lXBh2bMj0e0wGdgmGBo2lOGJh_dox_itiKLI9zCgmaMwJYwlB5QA6CfKPf2jGzTg" width=526 border=0&gt;&lt;/a&gt;  &lt;p&gt;I will be making these effects reusable so that you can drop them on any control and apply the effect. The power of the VisualBrush will defintely come to aid &lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-7161136268153875560&amp;page=RSS%3a+An+improved+water+effect&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=pavanpodila.spaces.live.com&amp;amp;GT1=pavanpodila"&gt;</description><comments>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!165.entry#comment</comments><guid isPermaLink="true">http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!165.entry</guid><pubDate>Fri, 29 Sep 2006 02:02:08 GMT</pubDate><slash:comments>5</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!165/comments/feed.rss</wfw:commentRss><wfw:comment>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!165.entry#comment</wfw:comment><dcterms:modified>2006-09-29T02:02:08Z</dcterms:modified></item><item><title>Genie Effect, the WPF way</title><link>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!161.entry</link><description>&lt;p&gt;I have been contemplating for many days about creating the Genie effect that you see in Mac OSX, when you minimize a window. It kind of creates a suction effect like a cloth being sucked into a vacuum cleaner. If you have a Mac, you would know. Unfortunately I don't have a Mac, well not yet! So what better can I do to fill the void...what about creating the Genie Effect in WPF? &lt;p&gt;Before we go onto the boring parts of how this was done, have a look at the &lt;a href="http://video.google.com/videoplay?docid=8775170776607857561&amp;amp;hl=en"&gt;Video&lt;/a&gt; (about 5 mins) so you know what you are up for! You can also download the &lt;a href="http://www.mediamax.com/pavan_podila/Hosted/MySpacesBlog/GenieEffect.zip"&gt;Demo&lt;/a&gt;. You will need the RC1 of .Net Framework 3.0. &lt;p&gt;&lt;a href="http://video.google.com/videoplay?docid=8775170776607857561&amp;amp;hl=en"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=480 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qmXBjlzNz6ZU4YN3YJtgj7zwhNYYQxt3lqVkVES2Bo3VmAr3KQ2E0pkxVS6oAuTsB7oPGuQbdSLaCAfeWvkgOoNPRitJgge1PB5MzLffnr4Sw" width=640 border=0&gt;&lt;/a&gt;  &lt;p&gt;&lt;strong&gt;Dismantling the components&lt;/strong&gt; &lt;p&gt;To understand what goes on here, let me show in XAML what the end result should look like. &lt;p&gt;  &lt;p&gt;&amp;lt;Page xmlns=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;&lt;/a&gt; &lt;p&gt;xmlns:x=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;"&gt;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;&lt;/a&gt;&amp;gt;&lt;br&gt;&amp;lt;Grid&amp;gt;&lt;br&gt;&lt;strong&gt;&amp;lt;Path Stroke=&amp;quot;Black&amp;quot; StrokeThickness=&amp;quot;1&amp;quot;&lt;br&gt;Data=&amp;quot;M 100,100 C 100,200 400,300 400,400 &lt;br&gt;M 600,100 C 600,200 500,300 500,400 &lt;br&gt;M 100,100 L 600,100 &lt;/strong&gt; &lt;p&gt;&lt;strong&gt;M 400,400 L 500,400&amp;quot;&amp;gt;&lt;br&gt;&amp;lt;/Path&amp;gt; &lt;/strong&gt; &lt;p&gt;&amp;lt;/Grid&amp;gt;&lt;br&gt;&amp;lt;/Page&amp;gt; &lt;p&gt;You can copy+paste it in XAMLPad and it should look like: &lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=326 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qmPxoQB0h-Tbyc2o3Xj8Yj9n4kZpsr_shEOkSLAK2rrVieWak7H38wr-gjcGeBZEjJBe4DkAfNWfKWbWX0JrS_rb1JTcb64HTbaTHpErm0mqw" width=515 border=0&gt;  &lt;p&gt;We have to create a surface like this in 3D so that it can be deformed. In fact the reason we are going to 3D is for the better control over deformations. Now if you look closely, our mesh is going to be defined by a curvy left edge and a curvy right edge. In more technical terms we have a Bezier curve for the left edge and another Bezier for the right edge. The rest of the mesh points will be interpolations between these two Beziers. &lt;p&gt;The best way to use a Bezier curve is to use its parametric form. Since we are using a cubic Bezier, we will have 4 control points. Each control point contributes to the curvature based on the Basis functions, which are also called the Bernstein polynomials. Ok, those were some loaded terms but it suffices to say that our Bezier will be defined by 4 control points that give it curvature. Each control point contributes based on a function as shown below: &lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px" height=134 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qkox5QpeEhFndCi_H1Odf1JjG95x8pAJf6LngWP25jYAb3wB35CzeNjYVHXtu-6aB_hD1XA0IcrZndbMomHmKzZT4uG-IY13yXVMQsYKmjoeA" width=154 border=0&gt;  &lt;p&gt;Since we have two Beziers we will use separate control points for each. So in all we will have 8 control points. The first and fourth control point of each Bezier are the start and end locations. The parameter &lt;strong&gt;t&lt;/strong&gt; varies from 0 to 1 ( &lt;strong&gt;0 &amp;lt;= t &amp;lt;= 1&lt;/strong&gt; ). At t=0, we are at the start of the curve and at t=1, we are the end of the curve. You can check that by substituting the values for t in the equations above. Using these equations we can get various points on the curve. Note that we need to apply these equations for each of the X, Y and Z components and get the Point3D that lies on the curve. &lt;p&gt;Once we have the curves, the rest of the mesh points are just a linear interpolation from one end of the curve to the other. With the mesh in place, we can now animate it by just manipulating the values of &lt;strong&gt;t&lt;/strong&gt; for each Bezier &lt;p&gt;&lt;strong&gt;Links&lt;/strong&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="http://video.google.com/videoplay?docid=8775170776607857561&amp;amp;hl=en"&gt;Video&lt;/a&gt; &lt;li&gt;&lt;a href="http://www.mediamax.com/pavan_podila/Hosted/MySpacesBlog/GenieEffect.zip"&gt;Download the Demo&lt;/a&gt;&lt;/ul&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-7161136268153875560&amp;page=RSS%3a+Genie+Effect%2c+the+WPF+way&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=pavanpodila.spaces.live.com&amp;amp;GT1=pavanpodila"&gt;</description><comments>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!161.entry#comment</comments><guid isPermaLink="true">http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!161.entry</guid><pubDate>Tue, 26 Sep 2006 01:46:59 GMT</pubDate><slash:comments>1</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!161/comments/feed.rss</wfw:commentRss><wfw:comment>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!161.entry#comment</wfw:comment><dcterms:modified>2006-09-26T01:46:59Z</dcterms:modified></item><item><title>Auto position a Viewport3D Camera for Full view</title><link>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!151.entry</link><description>&lt;p&gt;I have been spending a lot of time lately in developing 3D effects and some reusable controls for overlaying 3D effects on 2D controls (a subject of a forthcoming blog post). One of the core requirements is that the position of the PerspectiveCamera should be such that the 3D model is completely visible and has the same bounds as that of the Viewport3D. Now, what do I mean by that? A diagram should elucidate this concept. &lt;p&gt;  &lt;p&gt;&lt;strong&gt;What we really want!&lt;/strong&gt; &lt;p&gt;Lets take the case where the model is positioned far in front of the camera, so we can see it completely. The camera position is &lt;strong&gt;(0, 0, 2.154)&lt;/strong&gt; &lt;p&gt;&lt;img height=316 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qlherI_YiB5mxH_RpvaMzPNUdG-NDwYKqauW3q0bi_IH0Tqnam403XMHwGI2c5W5niJ_hCGPUKtU4rKsXnI_PYz1mKuVWiq0bDw27tMbCnO6A" width=414&gt;  &lt;p&gt;However we want the model to be as big as the viewport and also completely visible, something like: &lt;p&gt;&lt;img height=316 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64ql1-jwv0z1AX9Iy9ZzsocX_8y73YOWoFLPPfsdAyGnSq03DtVtI6URtNP14eMOV3bXNGSjGMsCr4rf1TWJHn0x7OOCpJS-ZUvPHWg-yjLSdPQ" width=414&gt;   The camera position is &lt;strong&gt;(0, 0, 1.1525)&lt;/strong&gt;. This is how we want it positioned all the time. If we bring the camera forward a little more, we would be too close to the object, as in: &lt;p&gt;&lt;img height=316 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qmZ6j5cjmPOdq6eYQulrGg480ZDLL1Ds-FrLmqmWr2LQaSWE8DS0QChv8f4u9s8mPc213gYqOnQgPsrpokICnZ55MtNyXPemz4LqEoDmF5QyQ" width=414&gt;   The camera position is &lt;strong&gt;(0, 0, 0.85)&lt;/strong&gt;. &lt;p&gt;What we want is that magic camera position that always seems to fit the model exactly as big as the viewport. Can we get that? Absolutely, but there is a little math involved in this. &lt;p&gt;  &lt;p&gt;&lt;strong&gt;Positioning the PerspectiveCamera&lt;/strong&gt; &lt;p&gt;There are couple of quantities we need to fix to arrive at this camera position.  &lt;ul&gt; &lt;li&gt;First of all we need the &lt;strong&gt;aspect ratio of the Viewport3D&lt;/strong&gt;. This is simple: &lt;strong&gt;aspect = ActualWidth / ActualHeight &lt;/strong&gt;of the Viewport3D instance.  &lt;li&gt;Using this aspect ratio, we have to now define the mesh positions. Note that our mesh will always be positioned at Z=0, in the XY plane. Lets take a simple mesh of 4 points. These 4 points should be defined as:&lt;br&gt;&lt;br&gt;mesh.Position[0] = new Point3D(-aspect / 2, 0.5, 0);&lt;br&gt;mesh.Position[1] = new Point3D(aspect / 2, 0.5, 0);&lt;br&gt;mesh.Position[2] = new Point3D(aspect / 2, -0.5, 0);&lt;br&gt;mesh.Position[3] = new Point3D(-aspect / 2, -0.5, 0);&lt;br&gt; &lt;li&gt;Finally its time for the camera position. Since we are using a PerspectiveCamera we need to take the FieldOfView property into account. Lets fix the FieldOfView = 60. With this the camera configuration looks like:&lt;br&gt;&lt;br&gt; &lt;img height=249 src="http://tk4.storage.msn.com/x1pUXuoQw6UT5_lWK8toAz6R38fFBeOmz-I8FMmQMe64qmEubzst6jqz1F9MprcR_780RVs663XEP2JsZPmJs0B-9-DOFbQd7Ssw3jV3znHA3oEuHb6ZPryQfVYtTjwKkY66XjlK13UqeXyU3TrA6nZXw" width=304&gt; What we are looking at is the top view. The FieldOfView angle spans horizontally. The distance of the camera from the Origin (0, 0, 0), along the Z-axis is &lt;strong&gt;e&lt;/strong&gt;. Using some simple trigonometry we can see that:&lt;br&gt;&lt;br&gt;tan(30) = (aspect / 2) / e&lt;br&gt;            = aspect / 2e&lt;br&gt;&lt;br&gt;Thus e = aspect / 2 * tan(30) = aspect * 0.866&lt;br&gt;&lt;br&gt;&lt;strong&gt;e = aspect * 0.86655&lt;br&gt;&lt;/strong&gt;&lt;br&gt;&lt;/ul&gt; &lt;p&gt;Lets take an example. Let the &lt;strong&gt;ActualWidth / ActualHeight&lt;/strong&gt; of the Viewport3D be &lt;strong&gt;400 / 300&lt;/strong&gt;. So our &lt;strong&gt;aspect = 1.33&lt;/strong&gt;. Also our &lt;strong&gt;FieldOfView = 60&lt;/strong&gt;. We have also defined our mesh as: &lt;p&gt;&amp;lt;MeshGeometry3D&lt;br&gt;&lt;strong&gt;Positions=&amp;quot;-0.666,0.5,0 0.666,0.5,0 0.666,-0.5,0 -0.666,-0.5,0.&amp;quot;&lt;br&gt;&lt;/strong&gt;Normals=&amp;quot;0,0,1 0,0,1 0,0,1 0,0,1&amp;quot;&lt;br&gt;TriangleIndices=&amp;quot;0,3,2 0,2,1&amp;quot;&lt;br&gt;TextureCoordinates=&amp;quot;0,0 1,0 1,1 0,1&amp;quot;/&amp;gt; &lt;p&gt;  &lt;p&gt;Therefore our camera Z-position should be at e = 1.33 * 0.86655 = 1.1525. Thus the position is &lt;strong&gt;(0, 0, 1.1525)&lt;/strong&gt;. If you recollect this is the same position from our discussion above (Figure 2). And ofcourse we will have our PerspectiveCamera defined as: &lt;p&gt;  &lt;p&gt;&amp;lt;Viewport3D.Camera&amp;gt;&lt;br&gt;&amp;lt;PerspectiveCamera &lt;br&gt;FieldOfView=&amp;quot;60&amp;quot; Position=&amp;quot;0,0,1.1525&amp;quot; LookDirection=&amp;quot;0,0,-1&amp;quot;&lt;br&gt;UpDirection=&amp;quot;0,1,0&amp;quot;/&amp;gt;&lt;br&gt;&amp;lt;/Viewport3D.Camera&amp;gt;  &lt;p&gt;   &lt;p&gt;In future posts I am going to build on this concept to create some reusable controls for overlaying 3D effects on 2D controls. Keep visiting!&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-7161136268153875560&amp;page=RSS%3a+Auto+position+a+Viewport3D+Camera+for+Full+view&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=pavanpodila.spaces.live.com&amp;amp;GT1=pavanpodila"&gt;</description><comments>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!151.entry#comment</comments><guid isPermaLink="true">http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!151.entry</guid><pubDate>Sat, 23 Sep 2006 02:59:12 GMT</pubDate><slash:comments>4</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!151/comments/feed.rss</wfw:commentRss><wfw:comment>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!151.entry#comment</wfw:comment><dcterms:modified>2006-09-23T14:40:38Z</dcterms:modified></item><item><title>Great tutorial on TextureCoordinates</title><link>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!129.entry</link><description>&lt;p&gt;I have been working on the 2D side of WPF for a long time now and its about time I added an extra dimension; 3D. I have worked with 3D before, just that I haven't done anything substantial. Its time now for me to ramp up. One of the tricky concepts of 3D is to understand how to map textures to 3D geometry. This, according to me is a fundamental concept that needs to be understood very well. Daniel Lehenbauer does a great job to explain TextureCoordinates.  &lt;p&gt;Check it out &lt;a href="http://blogs.msdn.com/danlehen/archive/2005/11/06/489627.aspx"&gt;here&lt;/a&gt;.&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-7161136268153875560&amp;page=RSS%3a+Great+tutorial+on+TextureCoordinates&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=pavanpodila.spaces.live.com&amp;amp;GT1=pavanpodila"&gt;</description><comments>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!129.entry#comment</comments><guid isPermaLink="true">http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!129.entry</guid><pubDate>Wed, 16 Aug 2006 01:54:06 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://pavanpodila.spaces.live.com/blog/cns!9C9E888164859398!129/comments/feed.rss</wfw:commentRss><wfw:comment>http://pavanpodila.spaces.live.com/Blog/cns!9C9E888164859398!129.entry#comment</wfw:comment><dcterms:modified>2006-08-16T02:34:53Z</dcterms:modified></item></channel></rss>