Space Sim in the Torque Game Engine - Setting up TGE and Using Sky Spheres
by Rob Evans · 07/09/2007 (10:39 am) · 38 comments
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)
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)
About the author
Recent Blogs
• Space Sim in the Torque Game Engine - Setting up TGE and Using Sky Spheres - ZIP of sky.cc and sky.h• How to create space nebula backgrounds in photoshop
• Space Sim in the Torque Game Engine - Setting up the Gravity Mod
• Space Sim in the Torque Game Engine - Introduction
• Creating Portals (doorways etc) in Constructor
#3
07/09/2007 (4:11 pm)
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!
#4
07/09/2007 (5:29 pm)
Yeah, it looks very good Rob, nice stuff! :0)
#5
07/09/2007 (10:00 pm)
Nice - me grab - now!!! What skin are you using or is that Vista?
#6
07/10/2007 (3:30 am)
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.
#7
What did you do for the stars, just dots?
07/10/2007 (4:16 am)
Sweet... Always wondered how to do polar textures properly. What did you do for the stars, just dots?
#8
07/10/2007 (4:17 am)
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?
#9
07/10/2007 (4:22 am)
@Leroy - Yeah that's the one! You can turn it off in Control Panel -> User Accounts... see below:
#10
07/10/2007 (4:23 am)
Add these type of posts as resources. Blog really isn't the place. ;)
#12
It's all one big project that's supposed to be in order so I figured my blog was best...
07/10/2007 (4:26 am)
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...
#13
07/10/2007 (4:36 am)
Thanks for that RobQuote: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... ;)
#14
07/10/2007 (4:41 am)
You can never have too many screenshots ;o)
#15
07/15/2007 (11:33 am)
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.
#16
02/06/2008 (7:37 am)
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.
#17
07/07/2008 (4:20 pm)
Hey Rob could you post your sky.cc and sky.h files? Possibly in the zip file you kept referring to?
#18
07/09/2008 (5:16 am)
I'll put the zip together now... I haven't done anything on this in ages and can barely remember where anything is!
#19
07/09/2008 (5:26 am)
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.
#20
07/10/2008 (4:37 am)
I have no idea, but is there an "Upload a File" button or something? Maybe on the main directory for your blog here? 
Torque 3D Owner Dave Young
Dave Young Games