Previous Blog Next Blog
Prev/Next Blog
by date

Space Sim in the Torque Game Engine - Setting up TGE and Using Sky Spheres

Space Sim in the Torque Game Engine - Setting up TGE and Using Sky Spheres
Name:Rob Evans
Date Posted:Jul 09, 2007
Rating:4.0 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Rob Evans

Blog post
This part of the guide uses resources submitted by Mike and the change-by-change details can be found here: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6644

I would like to take a quick moment to thank Mike for his insight and very useful resources on the space sim subject.

Now down to business...

----------------------------------------------------------------------------------------------------------------------------
SETTING UP TGE
----------------------------------------------------------------------------------------------------------------------------

During this guide it is important to remember that we are starting from scratch with a completely clean install of TGE 1.5.2.

I will be providing all of the altered files so that you don't need to make any manual changes because let's be honest, you want to get straight into making your game right? The reason I'm going to go through proper explanations of stuff rather than just complete the changes myself and then post the files in a big zip (which you can skip to if you really want) is so that whilst cutting all of the corners, you'll still have a firm understanding of what has changed within the engine and why we needed to change it.

Unpack TGE
So, let's unpack the TGE install to a new directory. I've chosen "c:\Torque\Clean1".

Make a Copy of tutorial.base
Once this is complete, you need to copy the directory "example\tutorial.base" and paste it in the same place "example\". Then rename the new directory to "SpaceSim1". So if you've done that correctly, you'll have a directory structure like this: "c:\Torque\Clean1\example\SpaceSim1".

Edit Tutorial Files
Now that we have our new game directory "SpaceSim1" we need to let the TorqueDemo.exe know we want to load files from there rather than the "tutorial.base" directory. All of these changes are explained in detail in the beginners tutorial that comes with TGE.

Open "example\main.cs" and change the line:

$defaultGame = "tutorial.base";

to

$defaultGame = "SpaceSim1";

Save the file and close it.

The rest of the changes are included in the zip for this part of the guide and will be included in the really big zip at the end, however, you MUST do this part (above) first as those changes will not be included in the zip package.

----------------------------------------------------------------------------------------------------------------------------
SKY SPHERES
----------------------------------------------------------------------------------------------------------------------------

In TGE (that's the Torque Game Engine you're probably using), the default sky setup allows the developer to create 6-sided sky boxes that display 6 individual textures to the player. Imagine a skybox like one giant cube that you as the player are floating inside, but wherever you go in the game, the skybox always stays centred around you. The problem with skyboxes is that if you imagine being inside one, the corners of the box will always be further away from you that the seams.

In contrast, imagine being inside a sphere. Wherever you look, the sphere is always the same distance away from you, so you end up with a much less distorted view of the sky. However, like Mike says in his post (link above), sky spheres often require polar mapped textures. This sounds complicated, but if you have Adobe Photoshop, it's TOTALLY easy! This part of the guide is a step-by-step tutorial on making polar-mapped textures from your normal square ones.

For our sim, we want to make the sky look like space so I'm going to refer to our sky-sphere as a space-sphere from now on (just to be different).

On top of the space-sphere, we also apply the patch mentioned in the link at the top (please read that link so you get an idea of the changes we're making) so that stars are generated on our space-sphere. This creates a nice background for us to use without too much work.

First, let's navigate to the correct folder for our clean installation of the TGE. I installed mine in C:\Torque\Clean1 and that is from where I will make all directory references. If I want you to look in C:\Torque\Clean1\engine\audio, I will simply say, "navigate to engine\audio". OK? Cool.

Your directory structure at this point will look like this:



For this part of the guide, the changed files are as follows:

engine\terrain\sky.cc
engine\terrain\sky.h
example\main.cs

You can simply unpack the zip and overwrite your current files and the changes will be applied!

So, now that we have the space-sphere code, lets go into Photoshop and make a sphere texture for our space-looking background. I'm not going to spend hours making amazing texture graphics, this will just show you how to make a spherical texture. Ready? OK...

Create a new file in Photoshop and set the width to 512 pixels and the height to 256 pixels. Make sure the colour mode is RGB and it's 8-bit too!



Next, select two colours in the colour picker. I've selected blue and black for a nice blue nebula effect, then click Filter -> Render -> Clouds.



You're almost done. Now we want our texture to wrap at all edges so that it doesn't have any seams. To do this, select Filter -> Other -> Offset. Then enter the value +15 for both horizontal and vertical. Make sure Wrap Around is selected. Click OK.



Next, we apply a spherical filter that turns our texture into one that looks cool when mapped to a sphere. Click Filter -> Distort -> Polar Coordinates. Then ensure that Polar to rectangle is selected.



Now, lastly we need to do a little editing. Select the top half of the image (0, 0 to 512, 128) and click Edit -> Copy. Then click Edit -> Paste. You should now have a second layer to play with. Move that layer to the bottom half of the image, then click Edit -> Transform -> Flip Vertical. This has basically mirrored the top half of our image to the bottom half.



Now that our texture has been created, save it as a png or jpeg - whatever works best for you (png is better).

Here's what it looks like in our game:



I imagine that this is not the best or most cool looking way to create this kind of texture, however, for our immediate needs, it will suffice. If anyone has a better way, please post the details!! :o)

Recent Blog Posts
List:07/10/07 - Space Sim in the Torque Game Engine - Setting up the Gravity Mod
07/09/07 - Space Sim in the Torque Game Engine - Setting up TGE and Using Sky Spheres
07/04/07 - Space Sim in the Torque Game Engine - Introduction
07/02/07 - Creating Portals (doorways etc) in Constructor

Submit ResourceSubmit your own resources!

Dave Young   (Jul 09, 2007 at 18:14 GMT)
cool! looks like Wing Commander :)

Jason Burch   (Jul 09, 2007 at 20:28 GMT)
Awesome!

Love the tutorial.

Rob Evans   (Jul 09, 2007 at 23:11 GMT)
Thanks :o) - Got lots of editing to do, I'm not happy with it... needs to be easier to read and more to the point... plus I haven't uploaded the zips yet! LOL... I'm my own worst critic!

Leroy Frederick   (Jul 10, 2007 at 00:29 GMT)   Resource Rating: 5
Yeah, it looks very good Rob, nice stuff! :0)

Andy Hawkins   (Jul 10, 2007 at 05:00 GMT)
Nice - me grab - now!!! What skin are you using or is that Vista?

Rob Evans   (Jul 10, 2007 at 10:30 GMT)
Yeah, that's Vista I'm ashamed to admit. It's a good upgrade for morons who don't know how to protect their computer from spyware etc but for the tech-savvy, it's a little annoying at times. I turned off user account control after a while. LOL. Other than that feature, it's basically XP with a face lift.

James Laker (BurNinG)   (Jul 10, 2007 at 11:16 GMT)
Sweet... Always wondered how to do polar textures properly.

What did you do for the stars, just dots?

Leroy Frederick   (Jul 10, 2007 at 11:17 GMT)   Resource Rating: 5
Quote:

I turned off user account control after a while.
Is that the annoying 'Do you want to do that/you must be administrator to process this action' constant message/question that keeps coming up every time you want to do anything of interest on vista? By the way, where do you turn that off?

Rob Evans   (Jul 10, 2007 at 11:22 GMT)
@Leroy - Yeah that's the one! You can turn it off in Control Panel -> User Accounts... see below:



James Laker (BurNinG)   (Jul 10, 2007 at 11:23 GMT)
Add these type of posts as resources. Blog really isn't the place. ;)

Rob Evans   (Jul 10, 2007 at 11:23 GMT)
@James - I used the star rendering mod from this page to do the stars. :o)

Rob Evans   (Jul 10, 2007 at 11:26 GMT)
Quote:

Add these type of posts as resources. Blog really isn't the place. ;)


It's all one big project that's supposed to be in order so I figured my blog was best...

Leroy Frederick   (Jul 10, 2007 at 11:36 GMT)   Resource Rating: 5
Thanks for that Rob
Quote:

add these type of posts as resources. Blog really isn't the place. ;)
I prefer this type of post in the blogs (mistakenly or otherwise) then some of the many stupid ones that have been posted recently, a better problem to have in my opinion! Besides, the resource section seems to only support one screenshot, which means this post may have been less effective as a step by step tute... ;)

Rob Evans   (Jul 10, 2007 at 11:41 GMT)
You can never have too many screenshots ;o)

Jacob Williams   (Jul 15, 2007 at 18:33 GMT)
Hey Rob, any chance of getting a copy of your sky.cc and sky.h files? I tried to apply the resource, and have done everything to the T, but Torque still crashes when trying to load a mission. Thanks in advance.

Torianaos   (Feb 06, 2008 at 15:37 GMT)
Well Rob, i get the same problem than Jacob, the game crashes in phase 2 : download ghost objects, then nothing except windows error message. Any way to get your sky.cc and sky.h? I thought it was a problem wuth torque version, but if you get it working on tge 1.5.2, then ....... Thanks.
Edited on Feb 06, 2008 17:36 GMT

Zac Crites   (Jul 07, 2008 at 23:20 GMT)
Hey Rob could you post your sky.cc and sky.h files? Possibly in the zip file you kept referring to?

Rob Evans   (Jul 09, 2008 at 12:16 GMT)
I'll put the zip together now... I haven't done anything on this in ages and can barely remember where anything is!

Rob Evans   (Jul 09, 2008 at 12:26 GMT)
Anyone know where I go to upload a zip to the site? I'm assuming that uploading it to my own server and making it available is in breach of GG copyright.

Zac Crites   (Jul 10, 2008 at 11:37 GMT)
I have no idea, but is there an "Upload a File" button or something? Maybe on the main directory for your blog here?

Rob Evans   (Jul 10, 2008 at 11:44 GMT)
I'm gonna submit a code resource with the file on it... this site needs a bit of a GUI rethink... I like it, don't get me wrong, but some of the stuff could do with a bit of a logic check!

Rob Evans   (Jul 10, 2008 at 11:54 GMT)
PS, Zac - did you want a copy of the work I have done so far? It may as well go to a good cause because I've lost interest for the moment. However, if you are working on something exciting, I would be interested in hearing your ideas and maybe helping out!

Rob Evans   (Jul 10, 2008 at 11:55 GMT)
The sky.cc and sky.h zip direct link is: http://www.garagegames.com/uploaded/code/15051.sky.zip

Zac Crites   (Jul 11, 2008 at 10:27 GMT)
I am working on on spaceship fighter game, but in a big Star Trek kinda way, as opposed to a Star Wars X-wing vs. Tie Fighter kinda way. I was gonna use your sky spheres idea to make the "map" with players able to jump in and out.

Rob Evans   (Jul 12, 2008 at 12:18 GMT)
@Zac - Cool, how far have you managed to get in the development? Do you have any screen-shots?

Zac Crites   (Jul 13, 2008 at 14:10 GMT)
Not yet, I'm still in the planning phase XD

Zac Crites   (Jul 14, 2008 at 12:08 GMT)
@Rob - When I start making the mission, how do I make the spherical mission, as opposed to the normal skybox?

Rob Evans   (Jul 14, 2008 at 12:15 GMT)
@Zac - Good question, I think it would be easier to drop you the whole directory so you can take a look at my code in full. Give me a minute to put the zip together.

Rob Evans   (Jul 14, 2008 at 12:50 GMT)
@Zac - File is 13mb and not easy to upload... any ideas?

Zac Crites   (Jul 14, 2008 at 19:35 GMT)
@Rob - Try box.net- it lets you upload all kinds of stuff for free.

Zac Crites   (Jul 17, 2008 at 01:14 GMT)
@Rob - Are you gonna upload the files? I want to start work on my game but I can't proceed without your help.

Rob Evans   (Jul 17, 2008 at 12:07 GMT)
@Zac - Do you have skype?

Zac Crites   (Jul 17, 2008 at 19:08 GMT)
@Rob - No, why?

Rob Evans   (Jul 17, 2008 at 19:11 GMT)
I can't upload the files to a public server because it contains GG code from their engine that is not my property and would break their copyright. If you have skype, I can transfer my files to you without uploading them to a public server.

Zac Crites   (Jul 17, 2008 at 20:39 GMT)
OK, I downloaded Skype. My Skype name is ShadowyCore. Now what?

Rob Evans   (Jul 17, 2008 at 20:41 GMT)
I'll send you the file... hold on...

You must be a member and be logged in to either append comments or rate this resource.