If you ever worked with bullet physics engine you know that in order to master it, several hours in front of a screen reading class diagrams are a requisite.
This was no different! Purposed by the school teacher, as a small project that used some sort of collision detection mechanism and a simple openGL functions that would draw some forms... However curiosity is a funny thing, usually bringing more work into the table than what was initially predicted!
This project was done with a collaboration of a colleague, that worked along side me from the app design to the final presentation.
Initially the idea was creating a Goldberg machine but soon we realised that a project like that was way to ambitious for the 2 Bullet newbies, hence the idea of creating a pool table, which included all the challenges proposed by the professor.
The Skybox and Objects
Naturally the project started with the creation of a skybox that would imitate a room, in this case one of the university rooms. For this I used my dear friend Fireworks to conceive the walls and the ceiling. The next step was to find some furniture, we managed to find some .OBJ files for this purpose, including a pool table a couch and some flowers...
Finding those objects was the easy part, using Blender to make sure they would match our requirements and also making some adjustments to the OBJ in terms of size, was a walk in a park...
Problems arrived while doing the import of object into memory, several libs and examples found online were tested but somehow they all seem inefficient or presented problems.
That being said, with bit of this and that, we finally managed to implement some code that successfully imported the objects.
The Bullet Physics Engine
We started to pay attention to the bullet engine and playing with their test cases.
Our main goal was to make the balls colliding with the table borders, bouncing back and naturally, collide between them...
One of the issues presented was the "re-coil" effect or making the ball bounce back using the appropriate rate for a pool ball, which we managed to bypass thanks to a function in Bullet that allows to fiddle with object properties.
Another issue was making the balls aware of the table floor, even thought bullet offers functions to detect OBJ forms we could not make it detect the pool table properly in a way that if one of the balls happen to be on top of one of the holes it would just fall into it.
In order to go around this problem we developed a class that created transparent static rigid forms, and we basically made a mould of the table. To make the ball fall into the holes we made a transparent box around the holes trying to approximate its dimensions to the table hole as much as we could. This way bullet engine was able to identify these forms and render physics accordingly.
Last but not least we imported a pool stick into the animation and made it follow the white ball, it does presents some glitches even thought we have tried some optimization but we got to a stage were we reckon that to make it better it would come as very time consuming, compromising the project schedule.
Applying text in OpenGL
One last bonus to us was the addition of writing into the application. Easier said than done! Not that we couldn't find any lib that would do that in C++ but the simple fact that most of them were not compatible with the system or the application.
It does presents some problems and its far from being perfect but in the 3 months given to us to make it happen and without any previous knowledge of any physics library I think we nailed it!
Categories: Application Development
Video Url: https://www.youtube.com/watch?v=DIAvDdmtcvs
Blender : http://www.blender.org/
Bullet : http://bulletphysics.org/wordpress/
Start: May, 2014
End: July, 2014