hrydgard/ppsspp — pull request #2986 by neobrain (2013-07-29 21:13:24+00:00)
Title: Math3d extensions2

Build tested on linux (gcc 4.7.2) and windows (msvc2010).

Enhances the feature set of the existing utility Math3D code by:
- supporting arbitrary base types in vectors (e.g. Vec3\, Vec3\) (CHANGED: Not possible to have different types for each component anymore)
- supporting two-component and four-component vectors
- supporting access of individual vector components as a subvector (e.g Vec4::rgb() returns a Vec3 consisting of values equal to the r, g, and b components of the Vec4 object) (CHANGED: It's not fast anymore because it's not using references anymore)
- supporting more flexible component naming (e.g. "rgba" or "xyzw") in vectors
- supporting 3x3 and 4x4 matrix classes (NEW)
- REMOVED: supporting vectors acting purely on references, thus being effective on memory usage (although I guess the compiler should've done this before already)

Additionally, this patch
- cleanly abstracts using Vec3 as a color or as an actual position vector.
- fixes some confusing oddities of the Vec3 API.
- might fix bugs caused by incorrect constructor usage (see below for details).
- doesn't use templates as extensively as the old, unmerged math3d-extensions code so that this also compiles on crappy compilers (NEW)

Changes for other people who used the code before:
- The star operator (*) refers to per-component product now (i.e. Vec2(v1.x*v1.x,v2.y*v2.y)) instead of the dot product. This is more consistent with what other APIs are doing (most notably GLSL/HLSL). For the dot product, a new Dot() function has been introduced. Additionally, Lerp has been made a global function instead of a VecXRef method. Existing code has been fixed to respect these changes.
- The % operator has been removed because it's not clear what it means. The new Cross() function should be used instead. There was no code using this functionality.
- The Vec3(u32 rgb) constructor has been removed due to its ambiguity. There have been some cases where the wrong constructor has been actually used, so this might even fix a bug. Anyway, instead the new static member functions Vec3::FromRGB and Vec4::FromRGBA should be used instead.
- What used to be Vec3 (i.e. a three-component vector acting on floats) is now Vec3f.