I created an openGL camera class that uses lazy estimation to provide finite projection matrices or model prediction matrices through getter functions. The user provides various camera parameters throughout the entire life cycle of the instance (FOV, position, etc.), but instead of the projection matrix and / or the MVP matrix being recalculated each time the parameter is changed, the βchangedβ flag was set (t .e. the old cached matrix is ββnow invalid). Whenever a user requests an updated final matrix, it is recalculated, the result is cached, and a const link is returned.
Everything sounds fine until I call:
const QMatrix4x4& oE_GLCamera::getModelViewProjection() const;
from a const instance oE_GLCamera ... I use const references in my entire application to extract camera data from CAD viewports without changing the camera, but my getter function performs lazy evaluation of member variables if they are invalid - therefore breaking const -correctness.
Is there a language feature or design paradigm that I don't know about to help with this? Or is it a lazy assessment, fundamentally incompatible with const-correctness? I know that const_cast <>, I never used it myself, but I had a few information about it, which boils down to the following: if you use it, you already made a mistake. Or will it be my savior?
Any advice would be greatly appreciated, Cam
source
share