My 3D Vector class

This is a discussion on My 3D Vector class within the C++ Programming forums, part of the General Programming Boards category; Lurker, clearly efficiency will be important for this class. For the most part, it looks good in that respect. In ...

Lurker, clearly efficiency will be important for this class. For the most part, it looks good in that respect. In your normalize function though, you may want to consider one call to length(), and storing the value in a temporary variable... It might be more efficient, might be less, I'm not entirely sure, but three function calls seems like a lot in that case.

post the source to your 3D game engine and show me where the info you posted was 100% necessary and most useful to solve a particular problem, because I can post mine and show you that the info you posted (which I went through and read) wasn't used at all (and, I might add, it's a pretty big engine at the moment). I know i came across as an ass, but for christ's sake do you think someone just writing their first vector class needs to be shown that stuff

Originally posted by Zach L. Lurker, clearly efficiency will be important for this class. For the most part, it looks good in that respect. In your normalize function though, you may want to consider one call to length(), and storing the value in a temporary variable... It might be more efficient, might be less, I'm not entirely sure, but three function calls seems like a lot in that case.

I don't know, I have been into 3D programming for a while, read/done lots of stuff, and I hardly remember seeing something that used double for its calculations instead of float.
Why not making it a template class? this way you can choose the type you need.

float is accurate enough except in one case with collision detection, and even then i don't think double is accurate enough because i've never seen anybody effectively solve the problem by using double.

i think using a template class for something as basic as this is a bad idea.

a template class won't have any effect on performance, when compiling, the compiler generates different versions of the class depending on the types you used, but it won't affect the class performance.

if you use doubles you have to use doubles for everything, you can't use doubles and float and have them rely on each other.

i.e
for collision detection if you want super high precision using doubles then you absolutely have to have your position be represented by doubles, not floats, otherwise if you use doubles for the collision detection but then floats for your position then everything just gets casted to a float anyway and that precision would be lost.