Programming (18)

Programming information.

Parsing Colors in a TGA File

Having just written a parser for TGA image files, I had the pleasure of learning that the storage method for color data was not clearly defined by the documentation and that the few pieces of example code I could find all contained bugs. In an attempt to rectify the issue, let's walk through the different ways color data can be packed into a TGA file and how to read it back. 

Optimizing atof and strtod in MSVC 2008

I recently wrote a text parser for Wavefront OBJ files and once I got it all up and running, I was surprised by the performance. I tend to be somewhat performance conscious when writing code so after realizing I had somehow created the slowest OBJ parser known to man, I was perplexed. It was taking 20 seconds to load the Stanford Bunny (4.83MB as an OBJ file with exported normals).

When parsing a 3d mesh from an OBJ file, it is optimal to collapse equal vertices into an indexed list. This is one of the more complicated steps so my suspicion was that something went wrong there. I was using a hash table to do the comparisons so it should have been fast. I disabled that section of code, and timed the load again. It barely affected the result.

Another common pitfall when parsing files is getting stalls from seeking through the file itself. I had already taken that into consideration and just loaded the whole thing into memory for processing. I was out of ideas and decided to profile the load and see what I had done wrong. I learned that almost all of my time was spent in strlen which was a big red flag considering I never even called strlen during my entire load.

Continue reading...

Loading the Stanford Bunny

I decided to get a little framework set up that would let me play around with some graphics code. As a result, I decided that step one would be to get everyone's favorite test model, the Stanford Bunny, loaded and rendering. I'd never actually used the bunny or any of the other Stanford models before so after a little research into where to access them and what format they were in, I came up with a "pipeline" for loading them into my application. I wouldn't call it a great solution, but it worked pretty well for getting something up and running to play with.

Continue reading...

Constraint Relaxation IK in 2D

titleInverse kinematics (IK) solvers often become mathematically intensive or computationally expensive with long kinematic chains or when functioning in higher dimensions. I am going to cover an approach to solving IK that is easy to understand, handles any number of joints, and is easy to implement in any dimension. We will walk through a two dimensional example and I'll present sample code to perform the algorithm.

Continue reading...

Cyclic Coordinate Descent in 2D

title
When performing inverse kinematics (IK) on a complicated bone chain, it can become too complex for an analytical solution. Cyclic Coordinate Descent (CCD) is an alternative that is both easy to implement and efficient to process. We will discuss the algorithm works at a high level, followed by a two-dimensional example and sample code.

CCD solves the IK problem through optimization. Looping through the joints from end to root, we optimize each joint to get the end effector (tip of the final joint) as close to our target as possible. This loop is then repeated until we find a solution or we reach an iteration limit. You can download the RJ_Demo_IK application and source code to see an interactive implementation.

You might also be interested in the following articles on different IK solvers:

Continue reading...