Continued on post iOS Vector and Matrix Math: Part 2.

For the past week or two I’ve been trying to reproduce the water effect of PixelJunk Shooter on the iPhone, however I seem to have reached a bottleneck with the collision detection used for repulsion when compressing.

I tried changing from Length to Length Squared, to Manhattan Distance, but it still grinded my framerate to 1FPS.

I decided to see if the Accelerate Framework in the iOS SDK had the vector math added to it yet, and to my surprise it had. It may have been added a while ago and I missed it. So I began to replace my math functions with the vector ones.

The strides are for the single precision functions are the number of floats. So for a stride of 8 bytes, you need to use 2.

float vec[2];
vDSP_vclr( &vec[0], 1, 2 );

This function sets the contents of a vector to zero. The equivalent function would be this

void vDSP_vclr( float * inVec, const int inStride, const unsigned int inCount )
{
for( unsigned int idx = 0; idx < inCount; ++idx )
{
*inVec = 0.0f;
inVec += inStride;
}
}

I haven’t used the double precision version of the vector library yet so I don’t know if the stride is the count of doubles, or of floats.

I have managed to go from 17 FPS for 650 particles to 30 FPS (I originally had it at 300 particles at 30FPS but it turned out I was profiling in debug). A definite improvement from using the Accelerate library functions for 2d vector math. One of my main issues for getting 1FPS originally was I was island producer was hit testing each particle with itself so it always had the maximum number of particles on each island.

The next couple of pages on this post cover some of the functions (vector and matrix) and their equivalent C++ function.

Pages: Page 1, Page 2, Page 3, Page 4, Page 5, Page 6, Page 7, Page 8, Page 9, Page 10, Page 11, Page 12, Page 13, Page 14, Page 15, Page 16, Page 17