# Thread: My 3D Vector class

1. 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.

Anyways, nice class.

Cheers

2. 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

3. I was rambling... I've got a test on that stuff tommorow, and I've been studying it for hours, hence the comment I made, "Anyways, not that any of that matters... I was just a bit bored."

Edit: I've done very little graphics, but I can see that such info would not be useful (especially as efficiency is extremely important).

My apologies... Truce?

4. wish i was where you are, im taking freaking my first calculus class in high school, it's SO LAME

5. Yeah, I can understand that. If you ever get a chance, you might want to look into an abstract algebra course. Its not the most practical of math, but it certainly is fun.

6. I'd honestly love to

7. 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.

Anyways, nice class.

Cheers
Thanks . So you mean something as simple as this:

Code:
```void Vector3D::normalize() {
double temp = length();
x /= temp;
y /= temp;
z /= temp;
}```

8. why double? I guess float would be more efficient for a 3D engine.

9. If accuracy is needed, not necessarily.

10. 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.

11. Cause someone could put in string .

12. 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.

floats are processed faster too

13. 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.

14. ohh i wasn't getting at performance, it's just a retarded idea

15. 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.