Friday, March 30, 2007

A Fresh Start

Alright, now that I have this stupid problem with the glColor command worked out, I can get back on track and write up the rest of the code. When I finished writing it up, I did a Debug and got a strange result, below is an image of what I was seeing on my screen.



As you can see, it seems that the colours from all of the polygons are blending together, which suggests to me that its not culling the back faces. So delved into some demo source examples and picked out the command to cull faces (gl.glEnable(GL.GL_CULL_FACE)), YAY now it looks like it should and is working as expected.



Now that I have one of the most basic 3D things down pat, I can move onto a more complex tutorial I did in OGL, working with vectors. In the tutorial we wrote up a vector class that involved all the methods of finding different angles and multiplying or subtracting vectors, so I quickly wrote the class up using the C++ code as a guide. When I was done, I did a quick debug and found everything working as expected.

Here I thought I would take it one step further and see if I could get the vector to bounce off the walls. I tried using a few different techniques like, inversing the direction of the vector and trying to get it shift according to an angle, but nothing I was doing was working as expected, it was then that I remembered an old tutorial that I had looked at a while back when I was doing some coding in SDL.NET

SDL.NET Home
SDL.NET Pong tutorial

I remembered this tutorial had an object bouncing off the walls, and from memory it worked quite well. After looking at the section that deals with the collision and motion it revealed how basic it was! how embarrassing.

if(ball.Right > Video.Screen.Width)
ballSpeedX *= -1;
if(ball.Left <> Video.Screen.Height)
ballSpeedY *= -1;

It was a simple matter of multiplying the speed by minus 1, duhhhhh. When I applied this to my code, it worked as expected and my moral was rekindled. Now I thought I would get adventurous and see if I could get the ball bouncing off a brick (just like in the classic Breakout). I coded up a quick brick class that would draw a 20x20 pixel box on the screen and made use of a collision detection method. After a little while of playing around with the collision detection I discovered that I could get the ball to bounce off either plane, x or y, but not both at the same time. I'm going to have to look into more advanced ways of detecting collisions and dealing with them, because simple if's don't seem to cut it.



At this stage, I went hunting around the web for some tutorials and information on collision detection. Ill bookmark the good ones now and read them a little later down the track.

No comments: