Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Matt J <mjo...@gm...> - 2009-02-27 16:03:04
|
Hmm, I fail to see how this works: If (y > x) == 0 then that means x <= y. So, If x <= y and z < y then 0 << 0 = 0 If x <= y and z >= y then 0 << 1 = 0 In the first case, y is the greatest component In the second case, z is the greatest component. Both are encoded as 0. Something I'm missing? Hi, > > I need to compute the index (not the actual value) of the largest > coordinate of a normal, for some space hashing. > > I'm not sure how fast you guys usually find this index, but I've just > created the following trick which I think is quite fast: > > > inline uint LargestCoordinate(const Vector3d &v) > > { > > const float x = fabs(v.x); > > const float z = fabs(v.z); > > const float y = Maths::max( fabs(v.y), z ); > > return uint(fabs(y)>fabs(x)) << uint(fabs(z)>=fabs(y)); > > } > |