unary operator "-" for vector3d

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
calimero
Posts: 45
Joined: Sun Aug 08, 2004 4:31 pm
Location: Nice, France

unary operator "-" for vector3d

Post by calimero »

the template class vector3d lacks for the unary operator -

so you can't write code like this :

Code: Select all

vector3df v1 = vector3df(0.0f,0.1f,0.0f);
vector3df v2 = -v1;
to have this operator just add

Code: Select all

vector3d<T> operator-() const { return vector3d<T>(-X, -Y, -Z);	}
in the public area of vector3d.h.
I test it for float and it works OK. And I think it's more interesting than the legacy "invert" method because it doesn't use 3 <T>multiplications but just 3 <T> change of sign.
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Thanks, should be useful.
Post Reply