The vector from the eye to the centre of the cube is (ViewMatrix * Model)[3], or ViewMatrix*Model*vec4(0,0,0,1). So you just need the length of that vector. E.g.


float distance =...