update method

void update(
  1. Camera camera
)

Set the visibility of each level's object based on distance from the camera.

Implementation

void update(Camera camera){
		final levels = this.levels;

		if ( levels.length > 1 ) {

			_v1.setFromMatrixPosition(camera.matrixWorld);
			_v2.setFromMatrixPosition(matrixWorld);

			final distance = _v1.distanceTo( _v2 ) / camera.zoom;

			levels[0].object?.visible = true;

			int i = 1;
    int l = levels.length;

			for(i = 1; i < l; i ++ ) {
				if ( distance >= levels[ i ].distance ) {
					levels[ i - 1 ].object?.visible = false;
					levels[ i ].object?.visible = true;
				}
      else {
					break;
				}
			}

			currentLevel = i - 1;

			for (;i < l;i++) {
				levels[i].object?.visible = false;
			}
		}
	}