Vec normalize() Author Message
fatcoder
Member

 Post: #1 Vec normalize() If possible, can you add a normalize() method to the Vec classes (in addition to the existing normalize method) that returns the normalized vector. This would allow the method to be chained with other operations. Therefore code like this: Code: ```Vec d = matrix.pos-Cam.matrix.pos; d.normalize(); if(Dot(Cam.matrix.z,d) > 0) { }``` Could be shortened to this: Code: ```if(Dot(Cam.matrix.z,Vec(matrix.pos-Cam.matrix.pos).normalize()) > 0) { }```
11-16-2011 09:23 AM
Driklyn
Member

 Post: #2 RE: Vec normalize() You can do this: Code: `if(Dot(Cam.matrix.z, !(matrix.pos-Cam.matrix.pos)) > 0)`
11-16-2011 09:36 AM
rndbit
Member

 Post: #3 RE: Vec normalize() (11-16-2011 09:36 AM)Driklyn Wrote:  You can do this: Code: `if(Dot(Cam.matrix.z, !(matrix.pos-Cam.matrix.pos)) > 0)` thats cool, but one of the main rules for writing easiliy maintainable code is "write stupid code". your example is sure short and sweet, but if someone else came across it - would make person stop and think 'oww whats that??', where suggested example with chained .normalize() is plain and simple, no mysterious symbols and all. so yeah normalize() returning a Vec& would be very fair addition.
11-16-2011 09:50 AM
Esenthel

 Post: #4 RE: Vec normalize() there can't be a 2nd normalize function with the same name, which differs only in return type
11-16-2011 12:20 PM
fatcoder
Member

 Post: #5 RE: Vec normalize() Yes, what was I thinking!!! Having a very "dumb" day.
11-16-2011 01:02 PM
rndbit
Member

 Post: #6 RE: Vec normalize() there can be normalize2() /shrug
11-16-2011 05:24 PM
 « Next Oldest | Next Newest »