Re: [Algorithms] How to get 3dvector largest coordinate index?
Brought to you by:
vexxed72
From: Sylvain G. V. <vi...@ii...> - 2009-02-27 16:23:29
|
Test is: uint(y>x) << uint(z>=y) - don't know why I let all these useless fabs in the previous email. If largest is: * X: 0 << ? = 0 as y<x (and we don't care about the second test) * Y: 1 << 0 = 1 as y>x and z<y * Z: 1 << 1 = 2 as y is replaced with z, so the tests are z>x and z>=z From: Matt J <mjo...@gm...> > Hmm, I fail to see how this works: > > If (y > x) == 0 then that means x <= y. !!!WRONG!!! it means that 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)); > > > } > > > |