" /> Primordial Ooze: December 2006 Archives

« November 2006 | Main | January 2007 »

December 31, 2006

Oooh, and what Super Villain Are You?!

A short visit to the sister-site of What Superhero Are You? and viola!
I am Magneto
Magneto
69%
The Joker
67%
Dr. Doom
65%
Apocalypse
63%
Green Goblin
62%
Lex Luthor
62%
Riddler
61%
Mr. Freeze
57%
Dark Phoenix
48%
Venom
47%
Juggernaut
46%
Poison Ivy
42%
Mystique
38%
Two-Face
38%
Kingpin
37%
Catwoman
29%
You fear the persecution of those that are different or underprivileged so much that you are willing to fight and hurt others for your cause.
Click here to take the “Which Super Villain are you?” quiz...

What Superhero Are You... Redux

Oops, I was premature and forgot to *scroll down* and answer all of the questions. I have been downgraded from Superman to: Spider-Man
Spider-Man
75%
Iron Man
75%
Superman
65%
Robin
55%
Green Lantern
50%
Supergirl
50%
The Flash
50%
Hulk
45%
Batman
40%
Catwoman
35%
Wonder Woman
30%
You are intelligent, witty,
a bit geeky and have great
power and responsibility.
Click here to take the "Which Superhero are you?" quiz...

What Superhero Are you?

Me?

I am Superman

Superman 70%
Spider-Man 70%
Supergirl 23%
Batman 5%
Robin 3%
Wonder Woman 3%
Green Lantern 0%
The Flash 0%
Catwoman 0%
Hulk 0%
Iron Man 0%
You are mild-mannered, good, strong and you love to help others.
Click here to take the “Which Superhero am I?” quiz...

Imagery: Earth on a red carpet

Some ray tracing experiments. The first image is without ambient light, the second is with a little added in so you could make out the bottom of the globe.

Earth on a red carpet

Earth on a red carpet with ambience

December 30, 2006

Top 10 Primordial Ooze Blog Posts of 2006

Below is a list of the most popular posts I’ve made, as reported by Google Analytics. The results are probably off since I only started collecting results via GA in late July. My web hosting site only lists hits per month in the raw log results, so it would be somewhat tedious to get a true list even though it is technically possible.

  1. /blog/archives/2006/10/have_a_cylon_halloween.html
  2. /blog/archives/2006/10/google_unveils_code_search_dea.html
  3. /blog/archives/2006/09/shaded_glass_and_plastic_butto.html
  4. /blog/archives/2006/08/macbook_hdtv.html
  5. /blog/archives/2006/09/wantagh_in_1961.html
  6. /blog/archives/2006/08/pluto_cartoons.html
  7. /blog/archives/2006/01/more_on_hamachi.html
  8. /blog/archives/2006/10/cylons_why_debugging_matters.html
  9. /blog/archives/2006/10/highdefinition_video_on_my_mac.html
  10. /blog/archives/2006/09/reflections_in_adobe_illustrat.html

Next year, the results should be more consistent. By far, my most popular post is my piece done in 1995 post on how to create Easy Glass Buttons. I’m actually the number one result on Google for that search term.

By the way, that list should go from 10 to 1. I used a fancy-dancy CSS feature to get the list reverse-ordered using a standard OL tag. If you’re curious, I can blog about how I did it. It’s kind of a hack.

December 28, 2006

Joel on Bribing Bloggers

Long, long ago I stopped reading Robert Scoble’s blog because I felt something was off with what he wrote about. Well, in truth I thought he was a moral caveman when he tried to get his massive audience to get him a new phone.

(I say some crazy things on this blog, and perhaps I my self am a moral caveman, but this blog has been a good sounding board for me so I just roll with it. If I make mistakes, so be it.)

So now I see that Joel (on Software) has written a blog entry that ruminates on whether it’s ok for bloggers to accept gifts from vendors. The quotes Scoble, who seems to think that vendor gifts are, “an awesome idea.”

Joel eventually decides, for himself, that’s it’s just not worth the risk to his credibility. I feel somehow vindicated by this since I agree with his thinking.

Joel also quotes from my new favorite book, Influence by Dr. Robert Cialdini. Get it from Amazon and make sure that you click on this link!

Our poor dark skies

I just saw this picture come across over at the Astronomy Picture of the Day. Consider it for a moment:

M31abtpmoon_c720

Explanation: The Great Spiral Galaxy in Andromeda (aka M31), a mere 2.5 million light-years distant, is the closest large spiral to our own Milky Way. Andromeda is visible to the unaided eye as a small, faint, fuzzy patch, but because its surface brightness is so low, casual skygazers can't appreciate the galaxy's impressive extent in planet Earth's sky. This entertaining composite image compares the angular size of the nearby galaxy to a brighter, more familiar celestial sight. In it, a deep exposure of Andromeda, tracing beautiful blue star clusters in spiral arms far beyond the bright yellow core, is combined with a typical view of a nearly full Moon. Shown at the same angular scale, the Moon covers about 1/2 degree on the sky, while the galaxy is clearly several times that size. The deep Andromeda exposure also includes two bright satellite galaxies, M32 and M110 (bottom).

Even with the darkest skies, you would never see the Andromeda galaxy like this without a largish telescope and/or an extended exposure on film or a digital camera. Now, though, due to light pollution, most urban and suburban skygazers can’t even get these views with their telescopes.

Anyway, this image certainly put things into perspective for me.

December 19, 2006

Find by regular expression in Firefox: Revisited

I have done a very poor job at responding to feedback on my blog. On one hand, I get tons of blog spam that I simply haven’t controlled. As such, legitimate comments have gotten lost in the noise.

I just enabled a more strict comment policy for a little bit while I catch up with things. In going through some of the spam, I noticed a reader wondered if I had found a solution to my own question, Find by regular expression in Firefox?

Well, I found a solution in an AddOn called FindBarRX. When you hit Ctrl+F, you get an additional checkbox:

Find_regex_firefox

You need to use the JavaScript RegEx Syntax, but it seems to work.

 

 

Another Google hack - Track UPS packages

I tried this one on intuition and it worked. To track a UPS package, just go to google.com and type:

ups <tracking number>

For example:

ups 1Z71FEB1C2C82C8D66

Will bring up a link, “Track UPS package 1Z71FEB1C2C82C8D66”

If you type in ups <garbage> the functionality is not invoked. Evidently you need to enter either a valid tracking number or one that resembles a valid tracking number.

This also works for fedex, and possible other carriers:

fedex 900521226815

I’m sure this is in Google hacks or something, but it was simply pretty rewarding to just type it in expecting it to work and have it just work!

UPDATE: A friend wrote and said:

FYI, when you use Google to track packages, you don't need the "ups" or "FedEx" prefix. Just enter your tracking number. Google is smart enough it identify UPS, FedEx, USPS, and a whole bunch of other tracking numbers.

Thanks Derek!

 

 

73 readers?

Feedburner says I have 73 subscribers. Who are you people and what do I have to say that’s so interesting?

In any case, I’m very grateful for your readership and I find myself often wondering, “Am I writing this post to get more readers or because I’m excited about writing this post?”

Usually it’s a mix. So, this sounds like as good a time as any to ask you Primordial Oozers (oooh, that sounds pretty gross), to sign my Frappr Map!

Primordial Ooze Frappr Map!

 

1-800-My-Apple

Let me begin this post by stating that I am a weak-willed individual. I mainly rely on my wife to keep me in check. However, I recently read, Influence: The Psychology of Persuasion and I have become very dangerous. That book is ridiculous!

I wanted to get an iMac for my two older sons because they have been asking to get their own computers for a long time. Part of me is thinking, I should get one and they should share. I should be teaching them how to share. Sharing is good…

Then I think to myself, I frakking teach them about sharing all of the frakking time. Screw that, I’ll leave the sharing lessons to other things like the frakking slide out back.

So, we’re talking about two iMacs, not one. I’m clicking away at apple.com/store and this leads to that and I find myself with a shopping cart brimming with quantity two 20” iMacs with 2GB of memory, upgraded video, wireless kb/m and AppleCare (of course).

The cart came to like $4k. I chicken out. I save the cart and exit, ashamed.

The next day I get an e-mail from Apple. They saw the saved cart and thought he quantity two (2) was a mistake. How CLEVER. They also asked if there was anything they could do to move things along, so to speak.

I joked and wrote back, “Yes, convince my wife that I can click ‘place order.’”

The phone rang like 20 minutes later. [They are EVIL]

Apple: Hey Nick, this is Jason with Apple. Your e-mail made me laugh. Is there anything I can help you with? Do you have any questions I can answer to help you make a decision?”

Me: Um.

Apple: I think you made a mistake since I see quantity two on your iMac and the AppleCare.

Me: Um, no, that’s not a mistake. I need two.

Apple: OK, so who are these beautiful new iMacs for? I’m sure I can get you a discount.

Me [thinking]: What? A discount? How? Really?

Me [sounding cool]: Yeh, that would be cool. The computers are for my two sons.

Apple: OK, give me a minute.

[there is a pause]

Apple: Hey, Nick, you’re in luck! I was able to save you over $400 on you order.

What happened next was a blur. Since I have my credit card number memorized, I found myself spewing out numbers, addresses, and the color underwear in one long sentence. In two days two new iMacs will arrive at my doorstep.

This post could be considered advice to all of you buyers out there. Mainly it’s confession.

Call 1–800–My-Apple and see if you can get a discount! I mean, school kids are eligible for an education discount… right?! Or, maybe you can save a cart and wait for the money to roll in!

Google Maps Pedometer!

A while ago, I had used the Google Map API to figure out how far I had run. My first pathetic route was here:

http://primordia.com/test/permalink/running/route1.html.

Now, all of that Longitude/Latitude crap I did was all pointless. Someone came out with a google map pedometer application.

You just click around a google map and your route is plotted and the distance recorded instantly! Check it out:

http://www.gmap-pedometer.com/

Just remember to “start recording” and “double-click” when you wan to record your runs.

Happy Exercise!

December 18, 2006

Multicore and applications, and reminiscing

626565A friend of mine at work sent an excellent writeup on the processor trend towards multi-cores and how it affects your operating system, your applications, and ultimately the time you spend doing CPU-intensive tasks

I knew just about everything that was described in there, but I was interested to read about some of the iMovie filter and Photoshop tests that failed to be multi-core aware.

This is an excellent writeup which I promise will really solidify the whole concept of multi-core and what it can do for you.

(Link)

Way back in 1996–1998 (or so) I spent $2500 on a two-CPU Pentium 3, I think, where each CPU ran at 400MHz. The reason I bought it was simple, I had a job to do ASP programming (not ASP.NET… this was a LONG time ago) and I had a theory. Debugging an ASP application would be faster if the debugger and the web server ran on separate processors. This was back in the days of NT4 SP3 and the Windows NT Server Option Pack. The results were that the system was usable and debugging worked. Beyond that I just don’t know.

I also recall John Carmack talking about multiple cpu’s a long time ago, back in 1996 when he was developing QuakeWorld:

It looks like I am going to split the QuakeWorld client into multiple threads to reduce the avg 1/2 frame latency between input and packet sending. This is also a step towards building a multi-threaded Quake renderer, which will let multi-cpu NT machines render twice as fast. Lets hope the windows thread scheduler is decent...

This brings up another point. Who’s thread sheduling is better? Windows or OSX or Linux? I’ve worked with a lot of middleware vendors at work and they all support Windows and Linux. It’s funny how each vendor swears that either Windows or Linux has faster thread scheduling. I think it’s really hard to say who’s better since different processing loads can behave in one of two ways on a specific thread sheduler. It can be handled efficiently or it will not be handled efficiently. Actually, it’s probably a gray-scale.

If anyone knows about any studies done where processing loads are categorized and compared on each of these platform thread schedules, I think that would be interesting.

Oh, and since I’m reminiscing about old John Carmack plan files, don’t forget to read my favorite: OpenGL vs Direct-3D on Dec 23, 1996. In that entry he has my favorite quote of all time:

I'm sure D3D will suck less with each forthcoming version…

This is basically the Microsoft rule that I live by. I quote this all the time, although I usually say thet MS software “sucks less over time.”

 

December 15, 2006

Funny comics

Saw this over at haha.nu:

0662

There are LOTS more funny ones, go check them out.

0666

Better yet, subscribe to the Bigger than Cheese RSS feed.

 

December 14, 2006

Wii, DS, all out of stock!

A few weeks ago, I picked up a Wii from Toys ‘R Us in New York City. It was a very hot item at the time and no matter how many they sold, they kept trucking shipments in. A week or two later, I went to get a unit for a few friends but I was limited to a single unit. Bummer for my #2 and #3 friends.

Now, I went back yesterday to pick up another one and  they are currently experiencing an extended shortage. The shortage seems to be nationwide. On December 17 (Sunday) a new shipment is due to arrive and I expect the madness to continue.

On a side note, my wife tried to get my son a Nintendo DS yesterday. She went to four stores and all of them were sold out. It seems like Nintendo products are simply on fire.

This WSJ online article has a nice quote:

“It may be because the PS3 is so scarce, consumers have given up looking for one and are going after the Wii with a vengeance,” theorizes John Taylor, a videogames analyst at Arcadia Investments Inc., in Portland, Ore.

From my perspective, Nintendo is doing really, really well. One report says that the Wii is outselling the PS3 by a 2–to-1 ratio. The gamespot article talks about how both Sony and Microsoft lose money on each PS3 and 360 sale since the hardware is so complex, while Nintendo makes a profit on every hardware sale.

Nintendo expects to sell 6 million Wiis through March of next year, but analysts expect even better numbers. Michael Pachter of Wedbush Morgan Securities told GameSpot, "I keep hearing that they will crush the 6 million unit number (by something like 2 to 3 million). That would be good for everyone."
(Link)

Another interesting quote from the gamespot article is that development of a Wii game is intrinsically a less-expensive proposition than developing a game for the PS3 and XBox 360:

It's not just the price of the hardware that gives Nintendo an edge in the money game. Development costs for the Wii are expected to be a fraction of development costs for the Xbox 360 and PS3.

The reason for this, I assume, is that all of that high-definition fidelity requires designers to produce a lot more detailed artwork and spend a lot longer on “level design.” If they don’t the high-definition display will be wasted on blocky army men blowing up blurry aliens.

At some point, I think Nintendo will get into the high-definition game but I suspect not until HD is ubiquitous and a veritable commodity.

 

 

 

December 13, 2006

LINQ to Web 2.0

My colleague Kevin Hoffman just told me that his Dr. Dobb’s article on Microsoft new language integrated query technology (known affectionately as LINQ) has been posted online.

Kevin is the author of numerous books, I think 14. Search for him on Amazon and pick up a few of his works <grin>.

Kevin_drdobbs

Go check it out!

Best Science Blog... Ever

Balogo_450x100I’ve linked to Phil Plait’s Bad Astronomy Blog a few times before. That’s how I was turned onto xkcd. I love his physics-oriented movie reviews, like this one of Superman Returns (and lots more). One day I’ll read his book, Bad Astronomy: Misconceptions and Misuses Revealed, from Astrology to the Moon Landing 'Hoax'.

Topper5For now, he’s asked for some support for a hokey Weblog Award that he really deserves. So, unles you have some other favorite science blog, make your way over to the voting page and vote for the BABlogger!

Oh, if you don’t believe that we landed on the moon then you can forget about all of this.

December 11, 2006

Find X - the "funniest" humor...

This is pretty funny. I came across this on xkcd, while doing some “funniest” comparisons. Go check it out and vote. There are a lot more there to laugh at.

TLbux4

(Link)

Here are a few more ticklers:

ML3keu[1]

Ok, it’s like 30 minutes and I need to do something else!

 

Map of the Internet - 2006

Holy moley, this is a cool illustration. Read the bottom text to figure out what’s going on. Check out XKCD!

Map_of_the_internet

December 7, 2006

Graphic Design and .NET Framework 3.0 Apps Part 2: Rich Graphic Design

This is the second post in a series on graphic design with Microsoft’s Expression Blend and Visual C# Express Edition. In my previous post, I talked about the rich integration between Microsoft’s Expression Blend and Microsoft Visual C# Express. I showed how you can code up a collection of Points and databind that to a graphical object and have that object appear in the Blend design environment.

In this post, I’ll explore some of the fun that’s to be had by playing around in Blend and realizing those rich graphics changes in your C# project.

If you recall, we started off with a simple spiral; part of the source code found in Petzold’s Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation.

Spiral0

I could tweak the XAML file by hand, say to thicken the stroke, like so:

<Grid>
    <Canvas x:Name="_canvas" HorizontalAlignment="Center" VerticalAlignment="Center">
        <src:SpiralData x:Name="data1"/>
        <Polyline x:Name="_poly" Stroke="Black" StrokeThickness="5" Points="{Binding ElementName=data1, Path=Points}"/>
    </Canvas>
</Grid>

Spiral0a

While this is completely possible, there is a better way. You can use Blend’s rich design tools to brighten up the spiral. First, I can load in my C# project into the Blend editor. Interestingly enough, I get to see the extent of the spiral beyond the edges of the window.

Spiral1

I can now click on the spiral in the visual tree to select it. Interestingly, I could not easily select it in the editor. In any case, I can select the StrokeThickness property and change it to 5:

SpiralTools1

Yielding this design-time view:

Spiral2

It gets better. How about I play around with some of the gradient settings. I save my changes and “run” the project as a regular .NET Framework 3.0 app:

Spiral3

Here I am having some more fun:

Spiral4

Nice dropshadow. That’s a trivial effect, by the way, and I have full control over the degree of blurring, the opacity, and the distance the shadow is from the object.

Spiral5

Dizzy yet? What’s even better is that the XAML generated by Blend is almost exactly what I would have done myself if I had memorized all of the property and effect names. It’s ultra-clean XAML:

<Grid>
     <Grid.Background>
      <RadialGradientBrush>
       <GradientStop Color="#FF3F4AB9" Offset="0"/>
       <GradientStop Color="#FFFFFFFF" Offset="0.774"/>
      </RadialGradientBrush>
     </Grid.Background>
  <Canvas x:Name="_canvas" HorizontalAlignment="Center" VerticalAlignment="Center" Background="#FF000000">
   <src:SpiralData x:Name="data1"/>
   <Polyline x:Name="_poly" Points="{Binding ElementName=data1, Path=Points}" RenderTransformOrigin="0.5,0.5" Fill="{x:Null}" StrokeThickness="12" Canvas.Left="-62" Canvas.Top="-61" TextElement.Foreground="{x:Null}">
    <Polyline.BitmapEffectInput>
     <BitmapEffectInput/>
    </Polyline.BitmapEffectInput>
    <Polyline.RenderTransform>
     <TransformGroup>
      <ScaleTransform ScaleX="0.55" ScaleY="0.55"/>
      <SkewTransform AngleX="0" AngleY="0"/>
      <RotateTransform Angle="0"/>
      <TranslateTransform X="0" Y="0"/>
     </TransformGroup>
    </Polyline.RenderTransform>
    <Polyline.Stroke>
     <RadialGradientBrush>
      <GradientStop Color="#FF001392" Offset="0"/>
      <GradientStop Color="#FFFFFFFF" Offset="0.928"/>
     </RadialGradientBrush>
    </Polyline.Stroke>
   </Polyline>
  </Canvas>
</Grid>

In my next post, I’ll play around with creating a “timeline” in Blend and activating it with a mouse click. This will realize a designer’s vision for how something should bounce around the screen, but allow the programmer the ability to activate it via application code. 

December 6, 2006

Graphic Design and .NET Framework 3.0 Apps Part 1: Code in the Designer

Starting Off, from Code to Markup

I'm reading the Petzold book on WPF  (part of the .NET Framework 3.0), Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation, and one of the exercises I put myself through was taking one of his code-centric samples and making it more declarative. I do most of my programming at home in Microsoft’s free Visual C# Express Edition. It’s a simple clean interface and I find that I don’t generally need all of the features of Visual Studio 2005 Professional.

Back to Petzold. In his book, he has a piece of sample code that declares a minimal display tree in the XML markup language XAML, and does the rest in code. The XAML looks like this:

<Grid>
</Grid>

He then adds a Canvas child and a Polyline object as children to the grid in code. Grid is defined in markup, and the children are defined at runtime in code. He has a C# method which loops through 20 revolutions of a spiral. Not rocket science.

Adding the canvas and polyline was done in code in Petzold's book, as follows:

// Make Canvas content of window.
Canvas canv = new Canvas();
canv.SizeChanged += CanvasOnSizeChanged;
Content = canv;

// Make Polyline child of Canvas.
poly = new Polyline();
poly.Stroke = SystemColors.WindowTextBrush;
canv.Children.Add(poly);

While I'll be the first to admit that I love code, this is the kind of thing that separates the "old" way (Win32, OSX) of constructing UI's from the new way (XAML). I wanted to do more delaratively, so I added as much as I could into the XAML, like so:

<Grid>
    <Canvas x:Name="_canvas" HorizontalAlignment="Center" VerticalAlignment="Center">
        <src:SpiralData x:Name="data1"/>
        <Polyline x:Name="_poly" Stroke="Black" Points="{Binding ElementName=data1, Path=Points}"/>
    </Canvas>
</Grid>

Now, notice that the points of the spiral are defined elsewhere, via databinding. Consider the "SpiralData" markup; this instantiates a C# class I wrote which supplies the points needed for the spiral as a PointCollection (Path=Points).  Now *that* is what code is for.

So fine, no big deal. Here is the running app:

Spiral0

Programming XAML by hand in this way feels like programming HTML by hand. It’s easy and precise, but can get time consuming. It also can get tedious and downright impossible to manage as the complexity of the scene increases. Ideally, you would set properties like stroke, fills, and alignment in a visual editor of some kind.

The Awesome Part

Now comes the AWESOME part. Yes, I said that already. Microsoft has a tool called Expression Blend, which used to be called the Expression Interactive Designer. It’s free now, but I guess that it will cost between $150 and $250 bucks when it’s released. Blend is a tool like Shockwave/Flash, allowing you to build vector assets and animate them. Microsoft is also coming out with a tool called Expression Designer which will be analogous to Adobe Illustrator; concentrating on providing an optimal toolset for vector art creation, leaving animation workflows to Blend.

Blend is tightly integrated with C# project files. You can even load a C# project, build it and even launch it as an EXE (just like you would build and run in VS).

However, ...I'm giddy here so bear with me, the visual designer was able to honor my databinding and showed me the spiral in the designer!

Read that again, Blend showed me the spiral in the designer! It looked like this:

Spiral_blend

I could click on the spiral, which was immutable and read-only in it's shape, but I could translate it, scale it, and modify the presentation (like the stroke), all using the designer! There is a complete integration between arbitrarily complex object shapes defined in code and the rich design user interface!

The Designer / Developer Work in Harmony

This is truly the holy grail of app development. Designers can work directly with the code and hopefully a much more rapid feedback loop will be possible.

What About Illustrator?

If I wanted to accomplish a similar feat in Adobe Illustrator, I’d have to learn their complex plugin API and be able to manipulate their internal data structures. Granted, Adobe provides a nice automation interface to do this, an interface exploited by my colleague Pavan Podila in his XAML Exporter for Illustrator. However, it’s not THIS simple. I can’t use C#, my preferred programming language, and I absolutely can’t get this kind of tight intergration between the development and design tools.

I must admit, I can’t imagine that Microsoft will ever (and I mean ever) create a tool as powerful and intuitive as Adobe Illustrator and I can’t see any serious designer using anything but Illustrator. Perhaps Microsoft’s Expression tools will become “good enough” over time to bring some designers on board. Perhaps not. What I think is most likely is that tools like Pavan’s XAML Exporter will mature and get backed by real companies that will provide very robust integration between Illustrator and XAML, Illustrator and Expression, or some other combination.

So, What’s Possible Now?

In a later post, I’ll explore some of the editing features of Blend and how changes in Blend can be realized within your running C# projects based on the .NET Framework 3.0.

December 4, 2006

Fig tree all wrapped up for the winter

Fig Tree for the winter

Here is my fig tree, as taken on Saturday December 2. We’re experiencing an unusually warm December (not that I have a Farmer’s Almanac by my side or anything!) and the tree is in no immediate danger, but I’m a bit late to be taking care of this so I’m glad that I’m done.

Or so I thought.

I wrote to a friend, very proud of my bubble wrap protection. In my head, bubble wrap will serve as a good insulator. It’s waterproof and has plenty of air pockets to help regulate the temperature. My friend told me that the plastic will harm the tree!

He had another suggestion:

That might work better but maybe you might want to try to buy 4 2x4's and drive them into the dirt then slap on some plywood around it and fill the interior with leaves.  Then you could but some tar paper on top somehow to seal it from water.  It's alot of work which is why i don't have a fig tree.  Prune it back so that it fits into the house you would build. I forgot to ask, have you wraped it in the past?

Oy.

I’ll attempt his solution next weekend, but if I don’t get to it I’m hoping that my bubble wrap will at least be better than the raw elements.

The fresh figs at the Italian store by me are pretty good. Maybe I should just resign to eating those.

December 3, 2006

Bouncing Ball - Source Code

GreenBackground

.NET Framework 2.0A while ago, I offered the source code to my simple physics (gravity) demo I made using Microsoft’s XNA Game Studio Beta. This was a simple change to the default Microsoft XNA Game Studio demo program. Don’t get too excited because the code is pretty basic.

The Trouble Begins

I was all ready to post the code when I thought it would be nice to include the binaries for your immediate gratification. It was then when I fired up fresh copy of XP SP2 running in virtual machine using Microsoft’s free Virtual PC software.

This is when the trouble started. The executable didn’t run. I immediately figured I needed some kind of XNA runtime and sure enough I did. However, the game still didn’t run after I installed the runtime. It looks as if I had compiled by binaries with the first public beta of XNA, but the latest redistributable was for Beta 2.

So, I uninstalled Beta 1 on my desktop and re-installed Beta 2. Then my project didn’t compile. You would not believe the amount of framework changes made between these two betas. At this point, I had to completely rewrite my code just so it would work on Beta 2.

Ok, I thought I was ready so I tried the new binaries on my clean XP virtual machijne. No dice! I had everything installed:

  • .NET Framework 2.0
  • DirectX 9.0c
  • XNA Game Studio Redistributable Beta 2

At this point, I plain give up. I’ll NEVER post this code if I try and figure this out. I can’t believe that I’m that stupid so I’ll just assume it’s a problem with the SDK. In short, you’ll need to install the full XNA Game Studio SDK if you want to run this code.

Code Overview

I basically tweaked these variables until the bouncing looked realistic:

//coordinates to draw the sprite at
double gravityAccel = 3.0;
double frictionDecelY = 1.003;
double frictionDecelX = 1.0075;

Then, we have the UpdateSprite function, which does all of the motion calculations:

        void UpdateSprite()
        {
            //move the sprite by speed
            spriteX += m_dSpriteHorizSpeed;
            spriteY += m_dSpriteVertSpeed;

            double MaxX = Window.ClientWidth - myTexture.Width;
            double MinX = 0.0;
            double MaxY = Window.ClientHeight - myTexture.Height;
            double MinY = 0.0;

            //check for bounce
            if (spriteX >= MaxX)
            {
                m_dSpriteHorizSpeed = -m_dSpriteHorizSpeed;
                spriteX = MaxX;
            }
            else if (spriteX <= MinX)
            {
                m_dSpriteHorizSpeed = -m_dSpriteHorizSpeed;
                spriteX = MinX;
            }

            if (spriteY >= MaxY)
            {
                m_dSpriteVertSpeed = -m_dSpriteVertSpeed;
                spriteY = MaxY;
            }
            else if (spriteY <= MinY)
            {
                m_dSpriteVertSpeed = -m_dSpriteVertSpeed;
                spriteY = MinY;
            }

            m_dSpriteVertSpeed += gravityAccel - 1.0;
            m_dSpriteVertSpeed /= frictionDecelY;
            m_dSpriteHorizSpeed /= frictionDecelX;
        }

Please find the attached zip file which contains the entire source tree, with all temporary and final binaries.

Enjoy!

UPDATE: This code drop seems to work with the released version of the SDK.