Appendix A. C++ Vector Library
A decent vector library is useful in any 3D graphics application but doubly so when you’re using OpenGL ES 2.0, since it doesn’t provide functions for matrix math on its own. Review Vector Beautification with C++ for an overview of the library listed in this appendix. In brief, it’s template-based C++, and it’s composed solely of three simple header files. The library defines a set of types that are named after GLSL’s vector types.
Disclaimer Regarding Performance
This code herein is designed for readability and ease of use. It does not attempt to leverage the ARM’s special instructions for squeezing out maximum performance from your CPU.
First- and second-generation iPhones and iPod touches have dedicated hardware called the VFP unit, which can help with vector math. The iPhone 3GS has an extended instruction set for these operations called NEON. If you’re interested in using these special instruction sets, I suggest taking a look at the math portion of the excellent oolong library, available here:
| http://code.google.com/p/oolongengine |
The gcc compiler may be able to generate some vector-oriented ARM instructions when maximum optimizations are enabled, but there are no guarantees. In Xcode, select Project→Edit Project Settings, go to the Build tab, select Show All Settings, and look for the Optimization Level option under the Code Generation heading. Don’t assume anything until you look at the generated assembly code.
Vector.hpp
#pragma once #include <cmath> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access