Wednesday, June 30, 2010

Day Three: First obstacles run into, yet overcome

Well, today I set off at 9:01 a.m. with one goal: get the accelerometer working within the OpenGL ES framework given by xcode. Something I honestly thought 'How hard could this be?' I started off the day watching two segments from the lecture videos regarding 3D programming on the iPhone, with an in-depth look at the hardware being used on the device. It was all fairly interesting, but I'm not too sure a whole lot of it will concern me for my first game, as I my plan is for top-down 2D-style gameplay.

I started to look at a few sample code examples of implementations of the Accelerometer, specifically one that used openGL as well. To make a long story short, the sample code and the template are not on the same page. The iPhone uses a view manager, with different views building the program. In an openGL game, the openGL rendering surface is applied to one of these views and than sent to core animation to be prepared for display. The accelerometer is implemented through an Objective-C/XCode setup known as a 'delegate' which I'm not really all that familiar with yet. This delegate needs to be attached to a view. Now, in the sample code all the rendering was done within the view, so the accelerometer values were already in the correct class. However, in the template the view handling the rendering surface passes off rendering duties to one of two seperate classes, depending on whether the app is running OpenGL 1.1 or 2.0. This led me to attaching the delegate to the view, but not having the values in the right class. I ended up adding variables and setter methods in the rendering class for view controller to pass the accelerometer data to it. It's ugly, but all of the work I'm doing now is to familiarize me with the technologies and the development environment. When it comes time to structuring the actual game there will be classes and methods in place for stitching all these different parts of the engine together so hacks like I used today won't be necessary.

I wanted to get some more openGL work done today, but I pretty much ran out of time. As I said in an earlier post the method of using openGL on the iPhone is quite unlike that which I'm used to, so I have quite a bit to figure out. Tomorrow I would like to get some basic objects drawn to the screen, and tie the accelerometer data into those objects. I did some basic color changing in the built-in openGL example with the data as proof of concept today, but what I plan to use the accelerometer for requires a "balance board", where the accelerometer controls an aspect of the game. Once I have a stronger handle on the openGL objects and parsing the accelerometer data I don't think this will be a problem, but that is tomorrow's job.

No comments:

Post a Comment