I think a great many people seem to be ignoring his actual question/issue in order to add completely irrelevant details and digressions, or to defend Valve's coding practices against some perceived criticism that just isn't there. The suggestion that *every* use of Vector::Normalize() was a reassignment of the result back to the original vector is silly; just do a search of the 2.3 SDK and you'll find plenty of counter-examples.
The member function from HL1 he's referring to, Vector::Normalize(), was a simple inline constant member function that has *no effect* on the vector it is called with. It has nothing to do with code speed and everything to do with reducing the quantity of code verbiage that needed to be written for quick, one-off uses of normalized vectors. Basically, it's a question of: Vector vecTempNormalized = vecUseful; VectorNormalize(vecTempNormalized); // can also use NormalizeInPlace() FunctionUsingNormalVector(vecTempNormalized, [...]); // Additional code requiring vecUseful in its original form versus FunctionUsingNormalVector(vecUseful->Normalize(), [...]); // Additional code requiring vecUseful in its original form With regards to speed, I did a quick test run using two stripped-down vector classes, with allocation being done before starting the time count and the test vector being kept constant to avoid the square-root causing a bias. The net result was that the global function method was only about 7% faster after 50000000 loops of each. Given the amount of other stuff happening in the game, and the fact that the engine can use whatever method it wants, I suspect that the occasional call to a member function of this kind for expediency from the game DLL would have an utterly negligible effect on game performance. The advantage increases to about 11% if the vector is reassigned to itself instead of a separate variable, but [a] you can still (and should!) use NormalizeInPlace() for that, and [b] once again, it is overwhelmed by the amount of other stuff going on in the game. If you consider the direct passing as a function argument (i.e. the example I suggested above), the member function method is actually about 22% faster, and a bit lighter on memory. Adding a nonvirtual Normalize() function to the Vector class should not affect the vtables -- the function will have a valid address defined for any pointer to the class regardless of the object it points to (you can even call the function from a NULL pointer, with predictably undefined results), and its presence should not require additional storage. So yes, as Tony said you can probably add it without any problems. ==================== Ryan Desgroseilliers Project Director, Half-Life: Nightwatch On 3/24/06, Tony omega Sergi <[EMAIL PROTECTED]> wrote: > Adding to that.. VectorNormalize was there as well, to do the same thing as > NormalizeInPlace. > Ie: > > Vector blah = Vector(x,y,z); > VectorNormalize(blah); > > > Oh and you can add functions to vector in hl2 and no problems persist. > One of the things I added back into vector a while back was copying back and > forth between float pointers. > > > > -----Original Message----- > From: Tony "omega" Sergi [mailto:[EMAIL PROTECTED] > Sent: March 24, 2006 8:08 AM > To: [email protected] > Subject: RE: [hlcoders] Why VectorNormalize? > > Looking back at all the posts, the only thing I can glean is simply this; > If you look at hl1, everywhere that valve used CVEctor->Normalize(); it was > like this: > > Vector blah = Vector(x,y,z); > blah = blah.Normalize(); > > so you're copying the vector around. > They simply replaced that with > Vector blah = Vector(x,y,z); > blah->NormalizeInPlace(); > > > > _______________________________________________ > To unsubscribe, edit your list preferences, or view the list archives, please > visit: > http://list.valvesoftware.com/mailman/listinfo/hlcoders > > -- Ryan Desgroseilliers [EMAIL PROTECTED] _______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders

