I've recently developed my own maths library for computer graphics. I have a very CPU intensive program that I used to do calculations component wise e.g:
GLdouble rx = particle[j].position[0] - particle.position[0];GLdouble ry = particle[j].position[0] - particle.position[0];GLdouble rz = particle[j].position[0] - particle.position[0];
However now that I've started using my own maths library my FPS goes from around 30 to around 11 FPS by changing the code above to:
Vector3d distance = particle[j].position - particle.position;
This makes me think that there's something wrong with my maths library. (The code above gets executed 1000^1000 times every iteration).
My vector constructors are:
// Constructs and sets the vector to (0, 0, 0)Vector3() : x(0), y(0), z(0) { }// Constructs and sets the vector to (vx, vy, vz)Vector3(T vx, T vy, T vz) : x(vx), y(vy), z(vz) { }// Constructs with data from another vectorVector3(const Vector3<T>& v) : x(v.x), y(v.y), z(v.z) { }
Equal and subtraction has the code:
Vector3<T> operator-(const Vector3<T>& v) const{ return Vector3<T>(x - v.x, y - v.y, z - v.z);}const Vector3<T>& operator=(const Vector3<T>& v){ x = v.x; y = v.y; z = v.z; return *this;}
What can I do to fix my horrible performance dip?
Regards