Posts

Showing posts from March, 2011
Looking for a portable 3D vector class for your game? Here's what I have pieced together over the years.  Still needs a little clean up. But solid and works great. // Usage Adding 2 vectors: Vector3Df v0(1,2,3); Vector3Df v1(4,5,6); Vector3D v2; v2 = v0 + v1; // Find angle between vectors v0 and v1 float angle = v0.angleInDegree(v1); // Normalize a vector (to unit length 1) Vector3Df v2n = v2.normalize(); // Vector3D is a template so feel free to use other types Vector3D&ltint&gt screen_pixels(10,10); // etc Also, it interfaces with a Matrix class. I'll post that soon so you can do some fun things there too! :) File Starts below...... //********************************************************************* /*  vim: set filetype=cpp.doxygen : */   #ifndef VECTOR3D_H_ #define VECTOR3D_H_ #include <vector> #include <cstdlib> #include <cstdio> #include <iostream> #include <sstream> #include <cmath>