Very fast 3D distance check?

后端 未结 13 2014
南方客
南方客 2021-01-31 15:40

Is there a way to do a quick and dirty 3D distance check where the results are rough, but it is very very fast? I need to do depth sorting. I use STL sort like this

13条回答
  •  甜味超标
    2021-01-31 16:28

    You may want to consider caching the distance between the player and the object as you calculate it, and then use that in your sortfunc. This would depend upon how many times your sort function looks at each object, so you might have to profile to be sure.

    What I'm getting at is that your sort function might do something like this:

    compare(a,b);
    compare(a,c);
    compare(a,d);
    

    and you would calculate the distance between the player and 'a' every time.

    As others have mentioned, you can leave out the sqrt in this case.

提交回复
热议问题