fatcoder
Member
|
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
|
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
|
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
Administrator
|
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
|
RE: Vec normalize()
Yes, what was I thinking!!! Having a very "dumb" day.
|
|
11-16-2011 01:02 PM |
|
rndbit
Member
|
RE: Vec normalize()
there can be normalize2() /shrug
|
|
11-16-2011 05:24 PM |
|