Faster distance measurement

I am currently working on a game and I need to send packets from the server to the client to create certain particle effects on the client, however clients can only display these particles if they are within a 64 cube radius of the game.

To avoid sending packets to all clients, I will measure the distance between the client and the point at which the particles occur, but the distance will be calculated for each client and should work less than a game tick (50ms).

The particles will be played by the player's movement and will be sent to all clients at a distance, so performance is a bit important (considering multiple players).

The game API provides this formula (no square root) for the distance between two locations:

square(x1 - x2) + square(y1 - y2) + square(z1 - z2);

My idea was to create a "square" of length 128 on each axis, using the particle as the center point, the disadvantage of which is that clients at the corner will not display the particle but will receive a packet, a bit of bandwidth.

The question is, would measuring distance using Euclidean distance be faster than just creating a "square" around the particles and comparing if clients are inside it? Are there any other methods for measuring distance faster?

+3


source to share


1 answer


A very efficient way to do this, especially with a lot of points, is to use an Oct-tree (3D Quad-tree) as the data structure.

Read more about publishing an article on Wikipedia .



It is a 3D spatial index that allows you to quickly extract points within a specific 3D (rectangular) range.

If you want to decrease the score further, you can use the distance formula to filter out the remaining scores; but the number of points should be significantly reduced by using the Oct-tree spatial index, which does not deduct much from performance.

+2


source







All Articles