I use a lot of 2D vectors in my Flash games - basically all velocities, positions etc I store in this way. My Vector2D class has lots of built in functions for rotation, dotproduct, projectOnto etc. The native Vector2 class doesn't seem to have half of this stuff, but it is used in a lot of places. The Vector3 has all this stuff, but has an extra dimension I don't need. So should I use either of the built in ones or port my AS3 class? Or should I try to extend Vector2 and add the extra functionality I need. Could that cause any problems?
The native Vector2 class doesn't seem to have half of this stuff, but it is used in a lot of places. The Vector3 has all this stuff, but has an extra dimension I don't need.
I believe you're mistaken; Vector2 and Vector3 both have extensive functionality. Note that this functionality is exposed as static methods to the Vector2/Vector3 class, rather than of the form
someVector.operationOn(otherVector). So for example, for the dot product of two
Vector2s, you simply write
Vector2.Dot(firstVector, secondVector). In addition, the same set of methods has existed since XNA 2.0, so I'm certain we are not talking about different versions.
Here is the list of Vector2 Members and Vector3 Members from Microsoft. The pages default to the latest XNA version, but you can view prior versions by clicking on the "Other Versions" dropdown at the top of the page, right under the title.
You will see, though, that the class does not implement rotation and projection. Of course, the projection operation is simply
Vector2.Multiply(vecB, Vector2.Dot(vecA, vecB)) so you can write a small function for that if you use it often. For rotation, you should make use of Vector2.Transform and feed it a rotation matrix; I definitely recommend writing a function for that.
Overall, I recommend using the built-in Vector2 class, and I think you'll find it suits most of your needs. The rest, like I said, are very short functions which you can port. But no need to duplicate the entire class, right? But if you feel the need to rewrite it, I don't see a strong reason why you shouldn't, as I can't see how XNA may somehow implement it better than you can.