Restricting camera movement in order to stop maths crashing application


In my cinder application, the user can drag and zoom the camera out similar to Blender style. (and based on the CameraUI class).

However, I’ve got a bit of a problem with my camera in that the user is free to mouse wheel zoom way back until the numbers overflow and the application crashed with a cinder::PlaneExc exception, which I think is caused by some NaNs being used maybe due to overflow, but this is where I’m struggling to understand whats going on and how this problem is generally solved.

I declare in the main app:

cinder::Frustumf            mVisibleWorldFrustrum;

then in my camera update I am doing:


which, when zooming way out triggers:

I assume this problem is due to a particular set of conditions (v1 == v2?) such that normal = 0 which is problem for the maths here, but I’m not sure how to get around this. I’d be grateful if anyone could steer me in the right direction - I would like to limit the users camera limit such that I don’t get maths oddities and overflows, to limit the camera movement in a graceful way.

ps. would the bigger solution for this be to come up with some sort of offset based “infinite” coordinate system (not even sure where to start with that one!), such that the world space numbers don’t just keep incrementing endlessly until overflow?

Cheers! :+1:

Do you really want users to zoom out that much? Would anything still be visible at all? Maybe all you have to do is set a limit on the distance.

Also, you may want to use if( length2( normal ) < FLT_EPSILON ) to prevent problems caused by floating point precision.


Hi Paul,
I have a level of detail thing so things are not lost. I can set a limit, but I’m not even sure how to determine the best (best = highest without application exploding) limit, so any limit I set seems a bit arbitrary.

Will update code with FLT_EPSILON, thanks.


Can you check the frustum when this happens? Can you also rotate the camera? Is it possible that the view direction and the world up become parallel?