Jim's Blog Ramblings about novels, comics, programming, and other geek topics

28Feb/088

How to create a heightmap and skydome using Terragen for XNA

Google AdSense

In this example, I'm going to use the Generated Geometry Sample provided by the XNA Creators Club as the code base, so we can just focus on creating heightmaps and the skydome.

Terragen is a great scenery generator and best of all, it's free for personal (non-commercial) use. However, the unregistered version has some limitations such as the image dimensions that you can generate. There's a great gallery of Terragen graphics showcasing it's abilities. Terragen also has numerous plug-ins for other 3D software packages such as Blender, 3D Studio MAX, LightWave 3D, Maya, etc.

The heightmap used by the sample is named "terrain.bmp" and it's dimensions are 257x257. The sky image used by the sample is named "sky.bmp" and it's dimensions are 2048x1024. Both of these images are found in the root Content folder.

Generating the heightmap

When Terragen opens, you will find the Landscape dialog at the foreground. To generate a random terrain, click the Generate button. On the Terrain Genesis dialog, you can play with the various options for a bit. Finally, click the Generate Terrain button and then the Close button.

To preview the terrain, click the Render Preview button on the Rendering Control dialog. Without a texture applied, you probably won't see much.

Exporting the heightmap

To change the file dimensions, click on the Size button of the Landscape dialog (located in the Terrain panel). You can increase the size to 513x513 with the unregistered version of Terragen. Registering the software will allow you to export to higher resolutions.

You can export the surface to a RAW image format and then convert it to an image format such as BMP, JPG, etc. that is more friendly with the XNA environment. Alternatively, you can download the FEO (For Export Only) plug-in that enables you to save your terrains to BMP, DXF, RIB, and OBJ formats (once you follow the install instructions for FEO, you can click on Accessories and Export to BMP).

Once you get the image into a BMP format (or other XNA compatible format), just copy the file into your Content folder. We'll get back to that after we finish the skybox.

Generating the skydome

Now that we have the heightmap finished, we can move on to the skydome. In this sample, the skydome is just one image that wraps around the terrain. We can create this by taking four images (North, East, South, West) from the center of our scene and stitching them together.

First, we need to setup our scene.

Uncheck the Fixed Height Above Surface for camera and target (2 checkboxes) in the Camera panel.

Find a good spot to use as the center point. I chose the center of my surface (x=128, y=128 terrain units). I played around a bit with the altitude (z) until I wasn't below the surface.

Increase your detail slider to the max (rightmost) in the Image panel.

We need to apply some texture to the surface so our image will look nice. Click the Open button in the Surface Map panel of the Landscape dialog. Terragen comes with a handful of surface maps that you can use (you'll may need to browse to your Terragen install directory). I'll chose GrassAndSnow2.srf for my surface.

Exporting the skydome

Set your Image Width and Height to 960 and 960 (the best resolution you can export with unregistered is 1280x960).

The next few steps will take the longest time. You'll need to change your camera settings, render an image, and save the image for each of our four directions.

Alternatively, you can download the script at the end of this article to automate the process. It will still take a while to render each of the images, but at least you can walk away for a few minutes.

View Name Camera Heading Camera Pitch Camera Bank
North 0 0 0
East 90 0 0
South 180 0 0
West 270 0 0

Change the camera orientation to the above parameters, render the image, and then export the image. Once all 4 images are done, stitch the images together in a clockwise manner (N->E->S->W or S->W->N->E, etc.).

You may need to reduce the combined width of the image to 2048 to run on your PC.

Testing the scene

Open the GeneratedGeometryWindows solution.

Note: If you overwrote the files from the sample using the same filenames, then you can skip this part and just start the sample application to view your work. You will need to rebuild the solution, so that the XNB files are updated via the pipeline otherwise, it will load the old XNB files.

Adding the files to the project

In the Solution Explorer, make sure you enable the Show All Files option by clicking the button above the solution tree. Expand the Content folder (you may need to refresh the file list).

Select the terrain heightmap image from the previous steps, right click, and choose Include In Project. View the heightmap image properties and change the Content Processor to TerrainProcessor.

Select the sky image from the previous steps, right click, and choose Include In Project. View the sky image properties and change the Content Processor to SkyProcessor

Make code changes

Update the code in the function called GeneratedGeometry.LoadContent. The model loaded for the terrain object should be the filename that you created (do not include the file extension). The sky file loaded for the sky object should be the skybox image that you created (do not include the file extension).

Run the application

Build your solution and then click Start Debugging (or just press F5) to see your newly created heightmap and skydome. You may also want to turn off the Fog effects drawn on the terrain (in the GeneratedGeometry.DrawTerrain function).

Notes on the Generated Geometry sample

The sample code uses a tiled texture for the terrain surfaces, so unless you replace "rocks.bmp" with a more fitting texture, your landscape scene might look a bit out of place.

Skybox Script for Terragen

Copy the following script into Notepad and save as "SkyboxScript.tgs". Execute this script in the above steps. The below script will generate 4 images in your C:temp directory by changing the camera orientation to the same parameters as listed in the table above. The frend (frame render) command renders the image and saves to your temp folder. The images will be named skydome0001, skydome0002, skydome0003, and skydome0004. So just stitch them together in the same order.

initanim "C:tempskydome", 1 

;_north
Zoom 1.0
CamH 0
CamP 0
CamB 0
frend 

;_east
Zoom 1.0
CamH 90
CamP 0
CamB 0
frend 

;_south
Zoom 1.0
CamH 180
CamP 0
CamB 0
frend 

;_west
Zoom 1.0
CamH 270
CamP 0
CamB 0
frend
 

Update 1 (3/4/2008): Some of my friends remarked that this post was useless without pics. With 3G of upload space remaining here, I might as well upload a few.

Scene example - generated from Terragen, default parameters
Terragen Scene Render

Heightmap example - generated from Terragen, default parameters
Terragen Heightmap Example

Skydome image example - generated from Terragen, default parameters using script above
Terragen Skydome Landscape render

22Feb/084

Democratizing Game Development

Google AdSense

I've long been a fan of games and game development. I created my first game over 20 years ago and saved it to a cassette (remember those things we used to have in cars before CDs?) on my Coleco Adam computer.

I also remember creating numerous text driven games for my Apple IIc Plus using Applesoft BASIC and saving them to my 5 1/4 inch floppy disks. A few months ago, I found my first game development book (for SmartBASIC) and a stack of 5 1/4 inch floppy disks in my parents basement...

Well, that was a long time ago. Today, there's lots of great gaming libraries and 3D engines for the PC. I experimented with a few of these using C++, but I've rarely finished any of games before I got distracted on another project or something else came up.

A few years ago, Microsoft released the XNA framework for Visual Studio. This framework allowed developers to make games compatible with both PCs (Microsoft operating systems) and XBOX 360s. I participated in the version beta prior to it's release and I've worked with the 1.x and 2.x versions, but I still haven't finished any games so far.

I'm still pretty excited about the XNA framework and it's impact on the programming industry.  I've thought this was great for Microsoft since I heard the first rumors. I believe the XNA framework will bring young developers into the .NET world and even though very, very few will get into the game industry, they will take their .NET skills into the marketplace. Some colleges have even designed programming courses around the XNA framework.

At the Game Developers Conference this week, Microsoft announced their plans for the next version of XNA.  Version 3 will include "XBOX Live Community Games". They also announced support for game development on the Zune, which I think is a good direction also.

This provides developers the ability to upload their games to a community site where peers can download and review your games. If your game passes the peer reviews, then it will become available to all XBOX owners to download and play.

TalkingAboutGames provides a little more details stating:

Gamers will be able to rate user-created XBLA titles through XNA Creators Club once the service goes live... Once a game is submitted, it goes through a peer review process (which eliminates copyrighted material and/or prohibited content), and if it passes, it's made available for download over Creators Club, which will be located on the Xbox Live dashboard. If that's not enough, XNA games can now be played on your Zune as well.

Gamasutra has a lengthy article titled, "Democratizing Game Distribution". The article provides general instructions on the game submission process. The submission form will contain options for the developer to rate violence, sex, and mature content on a scale of 0 to 5, upload screenshots and movie trailers, and upload the game package (.ccgame file).  Next, fellow XNA Creator Club members can submit reviews and game defects (bugs) for the game. Once enough positive reviews have been submitted, XBOX users can download the game via the XNA Game Launcher.

There is a special preview of this ability available until mid-March. You can download the XNA games of The Dishwasher: Dead Samurai, JellyCar, Little Gamers, Proximity HD, Rocketball, TriLinea, and Culture.

Maybe it's about time that I get back to work on my own game!

20Feb/0812

Reinstalling Internet Information Server (IIS)

Yesterday, I installed the required automatic updates from Microsoft and rebooted my work laptop and rebooted. When I started work this morning, I noticed that my Visual Studio projects weren't loading the web site projects.

Upon further investigation, I found that IIS Admin service wasn't running and would not start. The error provided by the service was "The IIS Admin service terminated with service-specific error 2147549183 (0x8000FFFF)."

When I clicked on Internet Information Service (via the Management Console), it would prompt me with a dialog stating "The username/password you used to connect to this machine does not have administrator privileges, or you entered an incorrect password."

My account was in the local administrators group, but when I entered my username and password, I was greeted with a message of "You have been denied access to this machine." (Sounds scary, huh?)

In addition, a DCOM error of "The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. ' attempting to start the service IISADMIN with arguments '' in order to run the server:" is logged in the System Event Viewer.

Collecting Service Status Error Message

Specific error information about the service can be found using the "sc" command. The "sc" command is used to interact with the NT Service Controller. Using this command, you can also stop and start services. The query argument will return service status and hopefully the reason why it couldn't be started.

C:>sc query IISAdmin
SERVICE_NAME: IISAdmin
        TYPE               : 20  WIN32_SHARE_PROCESS
        STATE              : 1 STOPPED
                            (NOT_STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 1066       (0x42a)
        SERVICE_EXIT_CODE  : -2147418113        (0x8000ffff)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

After spending about an hour trying everything to avoid re-installing IIS, I found a few Microsoft knowledge base articles relating to this error code. However, none of these articles seemed to help or make any difference. I was still unable to start IIS.

Uninstalling IIS

  1. Go to the Control Panel->Add or Remove Programs->Add/Remove Windows Components
  2. Unchecked "Internet Information Server (IIS)"
  3. Click "Next"

Installing IIS

  1. Go to the Control Panel->Add or Remove Programs->Add/Remove Windows Components
  2. Checked "Internet Information Server (IIS)"
  3. Click "Next"

Installing ASP.NET version 2.0

  1. Open command prompt
  2. Browse to "%WINDOWS%Microsoft.NETFrameworkv2.0.50727" directory
  3. Enter the command "aspnet_regiis -i"

Resolution

This seemed to have fix my problem and the "IIS Admin" and "World Wide Web Publishing" services were started. I lost all of my IIS configurations such as virtual directories, web sites, etc. And I needed to re-install ASP.NET 2.0.

Addendum

As soon as I re-installed IIS, 3 more Microsoft automatic updates were downloaded and waiting for me to install: KB939373, KB942830, KB942831. I took the chance and installed these updates, rebooted, and everything seems to be working after the updates.

Update 1 (the next morning): After a reboot, IIS could not be started again. Same problems as above. Re-installed IIS for second time. I'm thinking that MS08-006 is causing the problem, more details to come as I try to get this working.

Update 2 (the next morning 2): I rebooted after uninstalling some software and IIS refused to start up again. The service was once again disabled and it appears that I need to re-install IIS again.

Update 3 (2 years later): I think I found a fix for it. By changing the "Remote Procedure Call (RPC)" Windows service account from "NT Authority/Network Service" to log on as "Local System Account". After a reboot, my IIS finally works.

 

20Feb/080

RIP GotDotNet.com

As a ASP.NET programmer, I've visited GotDotNet.com many times since it's launch in November 2000. The site has gone through some problems and a couple facelifts since then and now it has officially been closed. It was the first ASP.NET community web site and my first ASP.NET reference web site.

There are other great ASP.NET web sites including:

I never understood why Microsoft develops so many web sites that are so similar in nature (providing code samples, documentation, user uploaded controls, forums, etc.).

I'd love to see a single .NET portal that includes ASP.NET (which I like a little better than GotDotNet.com), .NET 3.0 web sites (NetFx3.com, WindowsClient.net, IIS.net, etc.), and the other framework web sites.

[Via Betsy Aoki's WebLog]

My Related Posts: , ,
12Feb/080

XBOX 360 DRM issues

So far, I haven't needed to return my XBOX 360, but with the high failure rate, I expect that I'll probably be shipping it back sometime this year. With the new announcement of the Mass Effect downloadable content (DLC), I'll be purchasing some DRM (digital rights management) XBOX 360 content for the first time.

Unfortunately, BioWare isn't planning on releasing the content on CD at storefront or from their own online store. This means that when my XBOX gets the "red rings of death" (RRoD), I'll be stuck with the DRM glitch.

I'm a new owner of the XBOX, so I first learned about the problem while reading the Official XBOX Magazine's article titled "Six Resolutions for Microsoft in 2008."

If your console breaks ... the digital-rights management doesn’t detach from the old hardware, and it doesn’t know how to mate with the new machine. The only way to play the XBLA games you’ve bought, then, is to be logged in. That’s a problem for any users who don’t have a home network, who find themselves stuck with trial versions of the games they “own” until Mom’s done surfing the internet on the PC and surrenders the Ethernet cable.

It’s also a pain in the ass for two-gamertag households. Consider this very common scenario: Gamer A and Gamer B live together. (They might even be married — the ultimate multiplayer experience!) Gamer A bought Puzzle Quest, knowing Gamer B would love it — and she did. So they each played independently, until the three red lights showed up. After the console came back from Microsoft’s repair lab, suddenly, Gamer B couldn’t play Puzzle Quest — or any of the games Gamer A bought on his account. Part of the “fix” was to (accidentally? intentionally?) lock out anyone but the purchaser.

I was asking a couple questions on some of the XBOX related forums about this and then a few hours later, I noticed that Jeff Atwood of Coding horror wrote a nice write up explaining that DRM ignorance is expensive.

I foolishly assumed all along that it would be no big deal to transfer that purchased content if I ever purchased an Xbox 360 for my home.

Big mistake.

I didn't realize how precarious my understanding was of Xbox 360 digital rights management was.

Jeff's big mistake ended up costing him about $140 to repurchase all of his content for a second time. Jeff proposes a couple solutions and I really like the method that iTunes uses to manage DRM content where a limited number of machines are registered through your profile to access the content.  Hopefully, Microsoft will come out with a solution this year.

My Related Posts: , , ,
11Feb/080

G.I. Joe movie coming in 2009!

Growing up in the eighties, there were only two cartoons that I religiously watched: Transformers and G.I. Joe. Although, my favorite has always been G.I. Joe. I also think that somehow my favorite G.I. Joe character (Gung Ho) somehow subconsciously pushed me in the direction of joining the Marine Corps after high school.

Two Hasbro-related live-action movies are scheduled to be released in 2009 — Transformers 2 and G.I. Joe

ComingSoon.net states a release date of August 7, 2009.

Stephen Sommers-directed action-adventure written by Stuart Beattie. Dennis Quaid, Channing Tatum, Sienna Miller, Ray Park, Rachel Nichols, Adewale Akinnuoye-Agbaje, Said Taghmaoui, Marlon Wayans, Joseph Gordon-Levitt, Arnold Vosloo and David Murray star.

Ray Park, who played Darth Maul in Star Wars I, will be playing Snake Eyes. Adewale Akinnuoye-Agbaje, who played Mr. Eko from Lost, will be playing Heavy Duty. Dennis Quaid, who's been in tons of movies, will be playing General Hawk. The movie will also include Storm Shadow, Zartan, Duke, Baroness, and Destro. IMDB has a good list of actors and roles.

And knowing is half the battle!

References:

My Related Posts: , , ,
11Feb/080

Good bye, Netflix

I've just decided to cancel my Netflix membership. I've been a member for about 3 years now and I've probably rented over 200 movies from Netflix over that time.

After 3+ years, I had seen nearly every non-new release that I've ever wanted to see along with a few that I really didn't want to see. Now, my queue is mostly empty with the exception of one or two new/upcoming releases.

I used to think of Netflix as being a pioneer in the web development area. I think Netflix was the first time I had seen AJAX powered mouse-overs that worked as it should. I did like the minimalist approach to web design and their pages seemed to follow that without all of the annoying ad banners or distractions. Now, with their latest debacle of hiding information from users in hopes to deceive them into forgetting about new releases, I started having doubts about the entire enterprise.

So there's very few movies that remain for me to watch and now there's two new reasons that solidified my decision:

  • No games
  • No new HD-DVDs

Although, I don't play enough video games to get a GameFly membership (think of that as Netflix but with video games), I had been hoping that Netflix was going to enter that business since it is the exact same business model. The only difference is the manufacturer of the media being shipped, the envelops, and shipping & returning processes are all the same.

I did a little research and found a couple articles at fool.com.

In last month's presentation at the CSFB technology conference, Netflix CEO Reed Hastings had a few things to say ... about the business of renting games online. ... for a company like Netflix, a focus on the core DVD rental business is much wiser.

I just received this email this morning from Netflix stating:

In order to provide the best selection of high-definition titles for our members, we have decided to go exclusively with Blu-ray as well.

-- Netflix

Good bye & good luck Netflix.

 

Update 1 (February 15, 2008):

There's a rumor going around that Netflix will be coming to consoles. So even though, the money invested in my HD-DVD player will be wasted, maybe I'll be able to download HD movies through the XBOX Live Marketplace. If so, then I'm thinking that it will make up for the fact of dropping support for HD-DVDs (at least for me). For now, I've just put my account on a 3 month hold. Hopefully, something can be announced before May 2008.

For a limited time, you can take part in the Netflix survey.

References:

4Feb/081

Don’t forget to vote

Tomorrow is "Super Tuesday" and if you're living in one of the twenty-four states (and Samoa), then it's your chance to help guide the democratic process.

Here's a few trivia notes about voting.

Why do we vote on Tuesday?

The first Tuesday after the first Monday in November was picked to accommodate male farmers in the largely farming society of the early 1800s.

It was a good day after the harvest when farmers would have plenty of time to go to the polls. After observing Sunday as a day of rest, farmers used Monday to travel to often far away voting sites for the Tuesday vote.

When exactly did Tuesday become the official election day?

In 1845, by proclamation of President John Tyler.

(from "Why we vote on Tuesday", massvote.org)

If you're still a bit unsure, MSNBC has a nice interactive issue matrix at "Candidates + issue matrix".

Just remember that this round of voting is restricted based on your party selection. For some, like me, who are not declared as either Democratic or Republican, some states will allow you to vote on a Democratic or Republican ballot. In California as a non-declared voter, you can vote on the Independent ballot or Democratic ballot but not the Republican ballot.