Game Development Community

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

by Rob Evans · 07/09/2007 (5:39 pm) · 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:

v2.wastedwebspace.co.uk/gamedev/spacesim_screen1.png
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!

v2.wastedwebspace.co.uk/gamedev/spacesim_screen2.png
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.

v2.wastedwebspace.co.uk/gamedev/spacesim_screen3.png
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.

v2.wastedwebspace.co.uk/gamedev/spacesim_screen4.png
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.

v2.wastedwebspace.co.uk/gamedev/spacesim_screen5.png
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.

v2.wastedwebspace.co.uk/gamedev/spacesim_screen6.png
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:

v2.wastedwebspace.co.uk/gamedev/spacesim_screen7.png
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)
Page«First 1 2 Next»
#21
07/10/2008 (11:44 am)
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!
#22
07/10/2008 (11:54 am)
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!
#23
07/10/2008 (11:55 am)
The sky.cc and sky.h zip direct link is: http://www.garagegames.com/uploaded/code/15051.sky.zip
#24
07/11/2008 (10:27 am)
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.
#25
07/12/2008 (12:18 pm)
@Zac - Cool, how far have you managed to get in the development? Do you have any screen-shots?
#26
07/13/2008 (2:10 pm)
Not yet, I'm still in the planning phase XD
#27
07/14/2008 (12:08 pm)
@Rob - When I start making the mission, how do I make the spherical mission, as opposed to the normal skybox?
#28
07/14/2008 (12:15 pm)
@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.
#29
07/14/2008 (12:50 pm)
@Zac - File is 13mb and not easy to upload... any ideas?
#30
07/14/2008 (7:35 pm)
@Rob - Try box.net- it lets you upload all kinds of stuff for free.
#31
07/17/2008 (1:14 am)
@Rob - Are you gonna upload the files? I want to start work on my game but I can't proceed without your help.
#32
07/17/2008 (12:07 pm)
@Zac - Do you have skype?
#33
07/17/2008 (7:08 pm)
@Rob - No, why?
#34
07/17/2008 (7:11 pm)
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.
#35
07/17/2008 (8:39 pm)
OK, I downloaded Skype. My Skype name is ShadowyCore. Now what?
#36
07/17/2008 (8:41 pm)
I'll send you the file... hold on...
#37
10/22/2009 (8:21 am)
This breaks the cloud layer I presume, is that correct?
#38
10/22/2009 (11:22 am)
Yep. Should be easy to add it in again though.
Page«First 1 2 Next»