diff --git a/cocos/base/CCCamera.cpp b/cocos/base/CCCamera.cpp index 7a2e00936d..f903249962 100644 --- a/cocos/base/CCCamera.cpp +++ b/cocos/base/CCCamera.cpp @@ -134,7 +134,7 @@ const Mat4& Camera::getProjectionMatrix() const { return _projection; } -const Mat4& Camera::getViewMatrix() +const Mat4& Camera::getViewMatrix() const { Mat4 viewInv(getNodeToWorldTransform()); static int count = sizeof(float) * 16; @@ -183,7 +183,7 @@ void Camera::lookAt(const Vec3& lookAtPos, const Vec3& up) setRotation3D(Vec3(CC_RADIANS_TO_DEGREES(fPitch),CC_RADIANS_TO_DEGREES(fYaw),CC_RADIANS_TO_DEGREES(fRoll))); } -const Mat4& Camera::getViewProjectionMatrix() +const Mat4& Camera::getViewProjectionMatrix() const { getViewMatrix(); if (_viewProjectionDirty) @@ -201,7 +201,7 @@ void Camera::setAdditionalProjection(const Mat4& mat) getViewProjectionMatrix(); } -void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) +void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) const { assert(dst); Vec4 screen(src->x / viewport.width, ((viewport.height - src->y)) / viewport.height, src->z, 1.0f); diff --git a/cocos/base/CCCamera.h b/cocos/base/CCCamera.h index e0de3da16c..5beeffa734 100644 --- a/cocos/base/CCCamera.h +++ b/cocos/base/CCCamera.h @@ -118,15 +118,15 @@ public: * * @return The camera view matrix. */ - const Mat4& getViewMatrix(); + const Mat4& getViewMatrix() const; /**get view projection matrix*/ - const Mat4& getViewProjectionMatrix(); + const Mat4& getViewProjectionMatrix() const; /** * Convert the specified point of viewport from screenspace coordinate into the worldspace coordinate. */ - void unproject(const Size& viewport, Vec3* src, Vec3* dst); + void unproject(const Size& viewport, Vec3* src, Vec3* dst) const; //override virtual void onEnter() override; @@ -145,9 +145,9 @@ protected: Scene* _scene; //Scene camera belongs to Mat4 _projection; - Mat4 _view; - Mat4 _viewInv; - Mat4 _viewProjection; + mutable Mat4 _view; + mutable Mat4 _viewInv; + mutable Mat4 _viewProjection; Vec3 _up; Camera::Type _type; float _fieldOfView; @@ -155,7 +155,7 @@ protected: float _aspectRatio; float _nearPlane; float _farPlane; - bool _viewProjectionDirty; + mutable bool _viewProjectionDirty; unsigned short _cameraFlag; // camera flag };