Gl::translate() limits


Are there limits to how far you can translate the screen?
I’ve encountered a strange issue where the screen begins to drift off before disappearing (within the program window).

I have some draw functions that use gl::translate to move the screen to a calculated point and then back again (i.e. gl::translate(5, 5); {some code}; gl::translate(-5, -5); ), and when I have a large amount of things being drawn that need to be drawn far off from the screen (i.e. 2,000,000,000 pixels off) it begins to drift. (Normally the shapes aren’t supposed to be drawn so far away, but that’s a separate bug I have to fix). I’m trying to figure out if the screen-drift error is caused by this.

Sorry if this is badly written or has any gaps in it, I know I haven’t done the best job of explaining it, but I don’t know how to explain it better. I can link code examples or provide more info if necessary, thanks in advance.



Instead of translating back manually, can you try using gl::ScopedMatrices? That should prevent floating point errors.


I wasn’t aware of them, how would I use them? The documentation just says “Preserves all matrices.”


The cinder samples are a great place to learn the usage of different features. Checkout FrustumCulling in samples for ScopedModelMatrix and ScopedMatrices.

The scoped variables capture the state at construction and restores it on destruction. So you can store your model matrix, translate/rotate/scale to the required postion, draw your model, and then restore the original matrix. This way, you don’t run the risk of accumulating floating point errors, when you do forward and reverse transformations repeatedly. I am not very positive that you are facing this issue, it is just a hunch. At the very least, you can rule out one source of errors.


Thanks, I’ll try that.

Is the documentation for cinder stored anywhere besides on ?
The descriptions there are usually very minimal (see the example earlier in the thread).


I don’t believe there is any other doc besides that one. I usually grep the samples :slight_smile: .