Forum Navigation
suggestion: tango.math.vector/matrix
Moderators:
kris
Posted: 05/10/08 14:35:39Today I looked at some of my projects code and wondered if it could be useful included in tango. I'm using it for OpenGL graphics (for colors as well as for vertices) but I think it might me useful for other things too. Following an overview of the functionality (incomplete, but you see what the idea is):
struct Vector3(T) // 2D/4D alike... { T x,y,z; // component wise and scalar arithmetic like Vector3 opAdd/Sub/Mul/Div[Assign] (in Vector3); Vector3 opMul/Div[Assign] (in T); // useful stuff T length(); void Normalize(); // rescales to length=1 } Vector3!(T) Normalize(T)(in Vector3!(T) v); // rescales without modifying original vector // cross product Vector3!(T) cross(T)(in Vector3!(T) a, in Vector3!(T) b); // dot product T dot(T)(in Vector2!(T) a, in Vector2!(T) b);struct Matrix4(T) // 3D alike { Vector4!(T) V0, V1, V2, V3; // scalar mul/div Matrix4 opMul/Div (in T s); // real matrix multiplication Vector4!(T) opMul (in Vector4!(T) v); Vector4!(T) opMul (in Matrix4!(T) m); // pseudo constructors for rotation/translation/scale matrix static Matrix4 Rotation (Vector3!(T) axis, T angle); static Matrix4 Translation(T x, T y, T z); static Matrix4 Scale(T x, T y, T z); // useful stuff Matrix4 Transpose(); Matrix4 Inverse(); }So... as I said, the code is done. Only a little cleanup and upload is needed. But of course I don't know if Tango wants to have that stuff... ideas, comments?