Thursday, May 3, 2007

Tweak Tweak Tweak

Today whilst at my studios tutorial I was doing some updates on my blog when I remembered the "Lost Garden" (the blog site for a game artist) and decided to take a look at his site a little closer. I hadn't looked at his website past the Sinister Clone graphics he posted but this time I discovered a whole bunch of free game art under his directory. All the art is very well drawn and designed exceptionally well with animations, etc. I skimmed over the many many pictures looking for something I could use as an asteroid and discovered this neat little set, I think their original purpose were to be rocks, but I don't see how they can't be used as asteroids. Check it out below.




I set about making a couple of them into textures while I was at university so I could test them out a little later tonight. After finding these graphic sets I'm really keen to do some more coding on the engine, but I have been holding off to give Pete an opportunity to do some coding. But if Pete isn't going to use the time I'm off doing other things its his own fault and it truly does reflect how much he is putting into the project. I do admit that the particle system is a great addition to the engine but I cant help but wonder if it was actually necessary at this point in time, I think we have bigger tasks to worry about at the moment like getting the game to a standard were we can present it and have it work effectively.

My asteroid set.

So when I got home from university I set about doing some coding, their have been a couple of issues on my mind and I asked Pete to take a look at them, notably the collision detection part which he coded, but nothing has been changed since, so I have taken the liberty. To start with I threaded the collision detection system so it runs parallel with the render loop to ensure maximum performance and frames per second. It wasn't an easy task, it required a lot of changes to be made over the whole engine and between the current games we have at the moment, for example the previous setup for collision detection was designed so that each game had their own list of objects that could collide and the developer would pass these two lists to the renderer telling it to check the collisions between them. This wasn't the ideal situation to me, essentially I don't want a developer to have direct access to the renderer and to be able to manipulate anything outside the scope of the engine. To resolve this I created a method that the developer can make use of titled "addObjectToRender(GameObject o)" which will pass the object straight into the renderer for processing. Now the more I kept at it, the more I found I needed to change elsewhere to make it fit in with what I was doing, so for now I'll leave the collision stuff and move onto some other things I added or updated and talk about all of that later.

Standing City.
Demolished City.

Soil Texture.

Most notably I added a Texture Manager, prior to this I was using the Loader to statically load each game object's texture and pass the object its texture id (a reference to the texture in memory). But what this meant was that the loader was holding onto the array of texture references forcing the objects to call back to the loader to retrieve that value, an example is below.

Loader:
public static int textures[] = new int[20];
...
int cityTexture = LoadTGATexture("images/city32.tga");
City.setTextureId(cityTexture);

LoadTGATexture:
gl.glBindTexture(GL.GL_TEXTURE_2D, textureArray[Count]);
return Count;

City Object:
public void render()
{
gl.glPushMatrix();
gl.glBindTexture(GL.GL_TEXTURE_2D, Loader.textures[textureId]);
gl.glTranslated(location.x, location.y, 0.0);
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex2d(-30.0, -30.0);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex2d(30.0, -30.0);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex2d(30.0, 30.0);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex2d(-30.0, 30.0);
gl.glEnd();
gl.glPopMatrix();
}

The line I want to pay attention to is "gl.glBindTexture( GL.GL_TEXTURE_2D, Loader.textures[textureId]);" and how it refers back to the Loader. This is why I created the Texture Manager. I have made it a public object inside the Game Engine, so a developer can make use of it to load new textures and any game object can reference it. I created a method that a game object can use to retrieve its texture for binding titled "getTextureForBinding(int i)", this will retrieve the reference to the texture in memory based on the index given for the array. When a new texture is made the index is returned so that the object can store it for later use.

Now one of the other issues I wanted to check out, was if I could render primitives and textured objects at the same time. I wrote up a quick method for game objects so that it would draw its bounding circle (for collision detection) in red, and made use of the glEnable and glDisable functions to turn texturing on and off. Surprisingly it worked and its actually pretty handy being able to see the collision bounds for debugging purposes. The main reason I wanted to look into this was because Pete's particle engine ran a lot faster when it was using points which is logical and I couldn't imagine the load on the pipeline having to render a whole lot of textured particles, if I had to estimate it would be extreme! Below is a screenshot of Asteroids with bounding circles being drawn. One thing I notice in that picture is that all the asteroids are facing the same way, eventually I want to make them rotate and spin in different directions and speeds to break it up, shouldn't be to hard.



I also found this picture of space somewhere on the net, its actually much larger than this but I cut a 512x512 piece out and have pasted it below. It looks pretty good when applied to the asteroids background, but I'll have to get Pete's opinion too.



I'll talk more about how I'm going with the collision detection in the next blog. Thats it for now.

No comments: