Thursday, January 31, 2008
Last fall I showed off a new game that I had built using Silverlight 1.1 at a few User Group meetings across the southeast. I showed the internal "guts" of the puzzle game, and I think people generally thought it was a really cool project. I promised that I would make the code available, but never actually got around to publishing it. Until tonight. Gem Blaster is now (finally!) published to CodePlex at http://www.codeplex.com/gemblaster Full source code is available there. Also, if you just want to play the game (after all, it IS a game, and somewhat addictive too), I have a "live demo" posted to the Wintellect server here: http://demo.wintellect.com/gemblaster/default.html Enjoy!
Wednesday, January 30, 2008
Yes, you read that right. Silverlight 1.0 - as in unmanaged JavaScript - and 3D. Last week I was reminded of the FarSeer Physics engine for XNA and Silverlight 2.0. I have a strange fascination for 3D software - stemming back from the years when I was a beta tester and plugin developer for Caligari trueSpace 3D - so I decided to poke around in the source code from CodePlex to see what they were doing. Turns out it was just mostly linear algebra and some simple mechanics - things I remembered working with many years ago before the age of managed runtimes and rich visual APIs. Back then we had to do all the heavy lifting with highly optimized C++ routines and drawing directly to an HWND. But things are different now, and what seemed incredibly hard in years past really didn't seem all that hard anymore. So I was inspired I guess. I know I could have started with the FarSeer code, and built upon that using C# and targeting the managed runtime. But oh no - that was too easy! I figured that if it can be done using simple trig and a solid model design, I bet I could make it work in JavaScript. After all, JavaScript's Math intrinsic object supports Sin() and Cos(), extensible objects, and arrays - and at the end of the day, that's all one really needs in order to create a 3D runtime. Sure, it involves a fair amount of matrix operations and dot-products and cross-products, but all those things can be learned by reading up on Wikipedia these days (or mathreference.com). So with that, I set out to create an unmanaged 3D visualization engine for Silverlight... I am making the code freely available and have already published out to CodePlex here: http://www.codeplex.com/polygraph3d My efforts so far are looking pretty good (I think). Over the course of about 8 hours of coding and testing, I have the basics working. I can create a 3-dimensional polyhedron (a mesh if you will), and I can display the object in a Silverlight Canvas. I can apply scaling, rotations, and positioning of the polyhedra, and I can also build complex objects using polyhedron groups, each of which has its own local scaling/rotation/position transforms. It also supports a movable camera and performs rudimentary perspective correction as well as small optimizations for backface-culling. It currently only supports simple brushes for the object faces - I would like to implement a real texture mapping system, but that will require some very creative use of image skewing to pull it off. I have a test page up that demos a simple 3D cube that you can move around the virtual viewport space... For sure, it is a very simple demo. Clicking the red, green, and blue axis bars will move the cube around. The "spin" button introduces a gradual rotation around the Y axis... but since my rotation transform code is currently broken, the effect isn't quite what I had in mind. Hopefully I will figure that particular bug out soon. One major hurdle I encountered was the fact that Silverlight does not let you draw directly on a Canvas, nor does it let you create your own controls. This posed a problem since I wanted to display things that simply could not be expressed using 2D XAML. I "solved" this problem by performing all of the mathematics needed to project the 3D scene into a 2D viewport, and then I use the vertex data from the projected mesh to build a series of 2D Path elements. It was indeed a dirty trick - but hey, sometimes you just have to make do with the capabilities of the platform.
Last Friday was a sad day for Atlanta. One of the local radio stations went off the air. It wasn't just any old radio station though - for a decade and a half 99x was THE station that thousands, probably hundreds of thousands, of people tuned in to every day. You see, 99.7 FM was one of the first "alternative" stations back in the 1990's. Many people heard Nirvana, Pearl Jam, Stone Temple Pilots, and a vast array of other little-known artists for the first time on 99x. Nowadays, many of those "alternative" bands are considered mainstream - but back then they weren't so widely listened to. And 99.7 played a big part in bringing that music to the younger generation. Not to mention all of the local events they supported - Big Day Out, Mistletoe Jam, and many other concerts and other events. When I first came to Atlanta for a job interview, I remember driving into the city for the first time. In fact, it was April 17th, 1997. It was a very nice day - clear sky and about 80 degrees - a typical spring day in Atlanta. As I rounded a corner of I-20 (from the West) and saw the skyline for the first time, I began tuning my radio dial to maybe find a local station that I could bear to listen to. I quickly found 99.7 - I think they were playing a Weezer song (or maybe it was Green Day). Since that day I pretty much never moved my dial from 99.7. Well... except for those painful band interview segments that Axel used to do... Over the last 10 years the station has had ups and downs. More down than up in the past year or so though. I think they were bought out by a large syndicate around that time (the station was independent prior). It is kinda hard to know exactly what was going on, since the station management never seemed to want to just come out and let the listeners know what was happening. Early last week I noticed they started running some weird advertisements about some new "Visual 99x", recommending that people go visit their web site. I blew that off since online streaming music (or worse - video) is just not something I can use while in my car or at a customer site. And then Friday morning I was driving in to work.... And WTF do I hear on the radio? JUSTIN TIMBERLAKE! Or at least that's who I think it was. I was too busy cursing under my breath at my wife who I assumed had run an errand using my car and changed to station to some Top 40 garbage. But no, the tuner claimed it was on 99.7 as always. Then one of little filler stations ads came across - announcing that I was listening to "All the hits - Q100". I think I threw up a little in the back of my throat. So apparently, the new management had fired most of the on-air staff for various reasons over the past few months, and now they finally put the last nail in the coffin and took it off the air completely... and in the process giving the high-power transmission tower to one of their other stations. They could have at least given a real warning to the (many) loyal listeners. So R.I.P. 99x, hopefully another local station will step in to fill your shoes. Because if there is one thing this city does NOT need is another god-awful top-40, country, or hip-hop station.
Thursday, January 17, 2008
Looks like I got suckered into being a part of Sleepless in Washington, DC. Dan originally talked me into going to Sleepless in Atlanta, but after that was canceled due to last minute participant cancellations, we got cleared to pack our bags and head out to DC instead. I think Brendon and Matt are going too - and a few others. And you might be asking "What is the Sleepless Roadshow?"... according to their website: "Three weekends, seven cities, $100,000 In prizes and round the clock SharePoint and Office training" This is my first time attending an event like this. Not sure what to expect, but I guess I will find out soon enough... Thanks, Dan!
Thursday, January 10, 2008
To work with an "attached" property in Silverlight (such as Left and Top and ZIndex), we must normally use the pair of accessor methods GetValue() and SetValue(). This is because these properties are not defined for the object that actually uses them, but they are instead defined by another object that contains them. In the case of the Left and Top properties, this would be the containing Canvas. So in order to position an object, we often find that we must write code that resembles this: var LeftPosition = MyXamlElement.GetValue("Canvas.Left"); LeftPosition += 100.0; MyXamlElement.SetValue("Canvas.Left", LeftPosition); This works just dandy, but I often forget that there is an easier shorthand way to work with these attached properties. It turns out that the default indexer for all Xaml objects is implemented through those very same accessor methods. This means that we can write the code from above as such: var LeftPosition = MyXamlElement["Canvas.Left"]; LeftPosition += 100.0; MyXamlElement["Canvas.Left"] = Left Position; This is considerably more readable and even saves a few bytes of JavaScript code, which cuts down on code bloat - even if only slightly. Of course if I really wanted to reduce my code as much as possible, I could have reduced the above snippet even further to this last version: MyXamlElement["Canvas.Left"] += 100.0; And that's about as condensed as it gets.
Monday, January 07, 2008
I ran into a small, but dastardly quirk in Silverlight today. I haven't seen it mentioned out there so figured I would post this in case someone else might suffer from the same problem someday...
If you have a MediaElement being used to display video, chances are pretty good that you also have what is known as a "scrub bar". or at least some buttons used to jump forward or backward in the video timeline. The documentation says that you can accomplish this by interacting with the Position property of the MediaElement. The Position property is of type TimeSpan, which is documented as being immutable except for the Seconds property, which is read/write. In other words, the only way to change the current playback position of a playing media element is to set Position.Seconds to the location you wish to jump to.
The only thing is - this actually doesn't work if you take the documentation at face value. This bit of code doesn't work as you might think it would:
MyVideo.Position.Seconds = MyVideo.Position.Seconds + 10.0;
In fact, that code has no effect at all. No error message, but also no change to the position.
The secret here is that while the TimeSpan is indeed modifiable through the Seconds property, the MediaElement doesn't really care about it unless you reassign the Position property itself. To compound this, there is no way to create your own TimeSpan from code in Silverlight 1.0, so the only option we have is to take an existing one. Here is the code to change the current position (which actually works):
var pos = MyVideo.Position;
pos.Seconds = pos.Seconds + 10.0;
MyVideo.Position = pos;
HTH
|
On this page....
Archives
| June, 2008 (3) |
| May, 2008 (1) |
| April, 2008 (1) |
| March, 2008 (2) |
| February, 2008 (3) |
| January, 2008 (6) |
| December, 2007 (2) |
| November, 2007 (2) |
| October, 2007 (5) |
| September, 2007 (1) |
| August, 2007 (4) |
| July, 2007 (3) |
| June, 2007 (1) |
| May, 2007 (3) |
| April, 2007 (3) |
| March, 2007 (3) |
| February, 2007 (3) |
| January, 2007 (6) |
| November, 2006 (3) |
| September, 2006 (1) |
| August, 2006 (2) |
| May, 2006 (2) |
| April, 2006 (2) |
| March, 2006 (2) |
| February, 2006 (4) |
| January, 2006 (4) |
| December, 2005 (3) |
| November, 2005 (4) |
| October, 2005 (5) |
| September, 2005 (8) |
| August, 2005 (6) |
| July, 2005 (10) |
| June, 2005 (2) |
| May, 2005 (6) |
| April, 2005 (12) |
| March, 2005 (8) |
| February, 2005 (12) |
| January, 2005 (19) |
| December, 2004 (17) |
| November, 2004 (9) |
| October, 2004 (8) |
| September, 2004 (9) |
| |
Navigation
Categories
Microsoft Weblogs
Web 2.0 / AJAX
Local Atlanta Bloggers
SharePoint / MOSS
WPF
Other Weblogs
MSDN Monitoring
My Blogmap
About
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in anyway.
Sign In
|