Originally Posted by
Musah
but even a puny one as me knows that the more tasks you give to the processor the slower it runs
Oh, realy? Didn't knew that :3 my CPU doesn't run slower, the more it needs to do :P It's always running at 2.6 GHz...
ok, back to topic:
well, there are alot of ways to get the nearest object compared to another object. I've done some benchmarks some weeks ago, and you SHOULD implement a getDistance()-Method, which returns the non-sqrt value of the distance. It's around 100% faster, then calculating the "real" distance.. well, at least when using the loop version and a very high amount of objects :P
Code:
Nearest object - Objectcount int posList: 1000000
Nearest via LinqFind - with square root: 731ms
Nearest via LinqFind - without square root: 687ms
Nearest via LoopFind - with square root: 75ms
Nearest via LoopFind - without square root: 37ms
Using Microsoft Linq may not be the fastest, but the easiest to change and understand:
Code:
Vector3D nearest =
(from v in posList
orderby v.getDistance(me)
select v).First();