Question: Can anyone tell me how can we achieve the functionality of SQL join in **sphinx search**?
I want to index few columns from table1 and few from table2.

Tables are in MySQL.

Answer: 
The trick is to reuse the spheres that are behind the camera and put them in front of it. Look at how it is done in [this example](http://www.airtightinteractive.com/2015/01/building-a-60fps-webgl-game-on-mobile/). Here the programmer knows that the user will continue in the same direction so he removes the trees that come at a certain position.

If you use something like the example you quoted, you cannot know which direction the user will take. And so, you can use the same trick, but have to code it an other way. The most obvious is to check the distances with all the spheres regularly, if the user moves. If one sphere is too far behind the camera, you mirror it so it faces the camera, behind the fog.

'Regularly' can mean two things depending on your real number of spheres in your scene : 

* If you have a small scene and few spheres you can check those distances in your render loop. Neither cheap nor useful, 60 per seconds, but that can be the first coding step
* Then the best way would be to use a web worker : you send the positions of the camera and those of the spheres, you let the worker compute all the stuff in its thread, and send instructions back : 'move those spheres to those positions'. Every seconds is more reasonable in the threejs example, but up to you to decide that depending on your scene.

NOTE : if you have a lot of spheres, or any meshes you use instead, like more than 20-30, having a mesh for each of them will slower performances. With few trees on the examples i linked it is ok, but with more objects and/or a heavier scene, 

* think about merging them all in a single geometry. You can check which sphere is where by deducing from the vertices indices, or adding an attribute that defines each sphere.
* this will also impact the worker delay : it will have more to compute so it will need more time.

NOTE 2 : Note 1 would of course delete the level of details that the example aims to illustrate :) (Unless you also implement your own while checking the distances of the spheres....)
If you want to have an illusion of infinite world then you could:

1. Break your world space into regions (for example cubes).
2. Detect which region you are currently in.
3. Make sure you have objects (spheres) in neighbour regions. If some of regions are empty - fix it.
4. Clear regions which are not needed anymore.

For this you might want to have some class like this:

```
Class Region {
    bool isEmpty = true;
    Vector3 center;
    float radius; // or 'range'
    Array<Sphere> = null; // storage of your objects

    // constructors / destructor

    generateObjects(params); // perlin noise might be helpful there
    removeObjects();
}

```

and do something like this periodically:

```
void updateRegions() {
    computeClosestGridCoord(myPosition); // which is center of your current region
    lookForNeighbourRegions(regionsArray); // and add new Region if needed
    deleteOldRegionsStuff(regionsArray);
}

```