|
As I have always wanted to make my own pool game and needed a project to sharpen my C++ skills before my work starts, it seemed logical to make an OpenGL pool game. This will serve as an account of my progress on this project, and hopefully will be a source to draw inspiration from when I need it most. Remember, this is still a work in progress and I am doing it during my spare time, so this might stretch for a long time.
Drawing in IllustratorThe first thing I need to do is to get some graphics going. I choose to use illustrator because I want to be able to create higher resolution images if needed, in addition I might make it into a flash game at some point. I started by taking a simple reference picture of a pool table I found online and traced it. The reference image helps to keep things in proportion, so that the balls do not look too big or too small in relation to the table for example, without getting all sort of measurements. After I finished doing that, I made changes where I believed was necessary.
The final result can be seen in figure 1.
 |
Figure 1 - Pool Table Illustration
|
The next step would be to draw user control indicators such as: the score, the strength of hitting the cue ball, etc. But instead I will try getting some of these graphics into OpenGL and get some controls working, then I will come back and revisit the indicator graphics issue. OpenGL ProgrammingLoading Images and Helper ClassesAfter read a lot about OpenGL and how to do things, I found out that in OpenGL there are no free meals. By that I mean that you have to code a lot of what I would consider basic functionality yourself for no good reason. The first thing I had to do is to write my own bitmap file reader (*.BMP) which was quite a chore due to some badly written tutorials and a few things I did not know about how the compiler tends to optimize code. But it was worth it. I feel I have learned a lot by doing it myself and even-though I may replace it with a library like Magick++ so I can support more file formats, it has its uses. My code is much smaller and more suitable for my needs than a library can ever be. It is also a lot simpler, which makes it easy to use. The next thing I had to do was create a sprite class, because OpenGL does not offer one (unlike Direct3D which does). The class has to support basic operations like loading an image, scaling, rotating, moving and changing the pivot point. Although it was a lot of fun creating this class, I found it incredibly annoying the lack of documentation on how to do things like that. Therefore, I decided to release the code for both the bitmap loader and sprite class as a separate release to help others as soon as the code stabilizes a little more. I wrote a short article which explains how these classes came to be, and how you too can use them. ControlsFinally, after getting all that to work was time to get some basic controls to work. It should work as follow, a user is given the option to place the cue ball anywhere between the left edge and the second marker to position the ball for the break. This is simple enough, just set the ball to use the (x, y) of the mouse to follow the mouse cursor. A mouse click will place the ball at the chosen location and now we grab the cue stick. The stick would point to (or aim at) where the mouse cursor is. This means setting the pivot point of the cue stick to the cue ball and rotating it the appropriate number of degrees. Here a little trigeometry knowledge was needed and a few special cases examined to get it right. And no, I did not get it right the first time, it took a few tries. But remember, a pencil and paper are your best friends in these situations. I would even suggest keeping a notebook so that you can go back to previous notes you took and reflect on them. RackingNext, I needed to rack all the game balls so we can break. I needed to create a triangle for that, so a little bit more math. This was not too hard, but non the less an important step. Here is a screen shot of what it looks like so far on my 64-bit Ubuntu :  | | Figure 2 - The game so far as seen on a 64-bit Ubuntu |
To be continued...
ReferencesFoobillard Open Source 3D pool game: http://foobillard.sourceforge.net/
Add this page to your favorite Social Bookmarking websites
|