Although I had concepted what my game was going to be, it was now time to make it all happen. I needed to play a video from any point to any point, overlay my own sounds on the video, plot text on the screen (to keep track of score, level, player instructions, etc) and most importantly, I needed to plot a soccer ball in flight.
I had some experience with, and knew I could create an accurate ball flight in Irrlicht. Irrlicht
is a cross platform open source 3D engine, and the people on the forum are absolutely wonderful at helping users from newbies to gurus. Irrlicht fit my needs because:
It's open source and cross platform, and I need to develop for Linux (my downstairs media center is Mythbuntu)
The folks on the forum are incredibly patient and helpful
I had experience with it
The problem I had was creating a full screen video! I thought I might create a series of "Animated Billboards." This is a method by which you preload a series of pictures into memory, and specify the rate at which they flip. Well, it turns out that even my fastest clip was going to be a few hundred frames at 720p, and the animated billboard system was not designed to accommodate this. I was advised against this on the forums, but I tried anyway. Now I can say definitely that method does not work.
So I went on the Irrlicht forums in search of a solution. What I found was perfect: Irrlicht VideoMaster
. Turns out Bate, from the Irrlicht forums, had written an Irrlicht implementation of the Theora Playback Library.
This is a nice stable way to play back Ogg Theora
video. This meant that all I had to do was convert my video (h.264) to ogg, and I could play it back full screen or any size that I choose- even as a texture! Even better, I can instantly jump to any time period (within 0.1 seconds) on the video, as well as play, pause, rewind, etc.
As you can see from the Irrlicht VideoMaster
Thread, I had very little trouble porting it to Linux. I then used ffmpeg
to convert my video to OGG. From there it was easy to put in the soccer ball I had modeled in step 3, play some custom game sounds (referee whistles, Vuvuzelas, a 'boot' sound, and crowd noise) and some standard text on the screen to instruct and inform the player.
All I needed besides that was a method for the arduino and my application to talk. So I had the goal (ardiuno) send a signal when the ball was teed up for 1/2 second, and a different signal if the ball was unteed without getting through the goal. When there is a successful kick, the arduino sends 3 bytes- x coordinate, y coordinate, and time of flight.
For ball flight, I basically used the Irrlicht coordinate system (cartesian) to simulate ball flight. I knew the direction the ball was travelling, and I knew the speed. All I had to do was implement gravity, simulate some spin based on where the ball was kicked, and provide a coefficient of bounce when it hit the ground. It worked great! All source code is available on the last step.
I did discover one bug- if a player was kicking the ball, and someone was standing IN the goal (a likely event at the birthday party) the ball would travel at nearly infinite speed, and disappear from the universe. Everything still worked, just the ball on screen was invisible until you restart the game. The ball wasn't really necessary for play, but it did add a cool factor. The kids didn't mind. I have a video of this on the next step.