Blog | Tom Ward
A while back I was teaching myself various basic data structures and algorithms,
as well as writing my own allocator classes, when I came to a point where I
needed a simple way to unit test all my workings. I’ve used a couple of unit
tests systems in the past
(boost
for instance) but always found that they didn’t include a nice pretty printer,
nor a simple way to write the tests.
Completely separately I’ve also been working on using
protocol buffers at work for dynamic
messaging between applications (more on this in the future) and noticed they
used a thing called googletest. Long story short, after 30mins (maybe less) I
had created my first unit test and was very happy with just how simple it is! It
also has some really cool floating point test macros, which makes float
comparisons a breeze.
In my spare time I’ve started working on making my own little model viewer in
OpenGL (more on this later) and I’ve recently been working on creating some nice
camera controls. Although I’ve had to delve into cameras a few times over the
years, this is the first time I’d had to create one from scratch and was quite
an experience! I also found the help online to be a bit sparse, with various
ways of doing it but none I really liked.
Here’s what I learnt and snippets of my final solution, I haven’t gone into the
nitty gritty of all the math functions, but there’s plenty of places to find
that stuff.
So Last year I posted about triple booting a 2011 MBP, which I can now reveal
was to do with me porting
MODO to Linux
(which was pretty cool!). I have since moved to doing all of my development at
work to Ubuntu 12.04 so had to compile and install the GCC 4.1.2 compiler, as
this is the official compiler for all Foundry applications. This wasn’t as
straight forward as I hoped, so to save me (and anyone else) going through the
same pain, here’s a guide for doing just this.
In my limited spare time, I’ve been trying to teach myself some basic
SIMD programming in order to optimize my 3D
math library I’ve been work on. Whilst at EA, we had the idea of having an “FPU”
(Floating-point Processing Unit) math library, alongside a “VPU” (vector
processing unit) optimized class. I decided to do the same thing in my math
library for a few reasons:
- It allows me to write a simpler, much more basic math library that I could
use in unit tests to validate the VPU version
- It gives me a way to accurately benchmark my SIMD optimized code path
- Finally there are cases where it’s actually better to use a floating point
class version, which I’ll briefly explain later
As I wanted to guarantee backwards compatibility, I decided to just use SSE2
instructions and not anything more fancy, which means it’ll work on every 64-bit
desktop processor* as well as hopefully port quite nicely to
neon for ARM
(more on that in a future post!)
Rather than go through everything, I’ll instead just explain what I did for dot
and cross products, which will show most of the simple ways of doing things.
Just a quick one today, spent today automating the creation of a VS project for
the product I’m working on (which uses a custom build system) and found myself
needing to detect if a directory is a symlink on Windows. Python does provide a
function os.path.islink(dirPath)
but annoyingly on Python 2.x this always
returns false for Windows symlinks. Great!
So here’s a working version of the function that I put together using ctypes:
import os, ctypes
def IsSymlink(path):
FILE_ATTRIBUTE_REPARSE_POINT = 0x0400
if os.path.isdir(path) and \
(ctypes.windll.kernel32.GetFileAttributesW(unicode(path)) & FILE_ATTRIBUTE_REPARSE_POINT):
return True
else:
return False
Hopefully that saves someone the hassle of finding how to do this