Skip to content

Commit 9304fbf

Browse files
committed
Fix inverse viewing matrix caching bug in Camera class
- add method dirtyViewCaches() to dirty both viewing and inverse viewing matrix caches whenever the camera transform is modified.
1 parent bb15730 commit 9304fbf

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/cinder/Camera.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class CI_API Camera {
153153
virtual Ray calcRay( float u, float v, float imagePlaneAspectRatio ) const = 0;
154154

155155
void getClipCoordinates( float clipDist, float ratio, vec3* topLeft, vec3* topRight, vec3* bottomLeft, vec3* bottomRight ) const;
156+
void dirtyViewCaches() { mModelViewCached = mInverseModelViewCached = false; }
156157

157158
vec3 mEyePoint;
158159
vec3 mViewDirection;

src/cinder/Camera.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ namespace cinder {
4343
void Camera::setEyePoint( const vec3 &eyePoint )
4444
{
4545
mEyePoint = eyePoint;
46-
mModelViewCached = false;
46+
dirtyViewCaches();
4747
}
4848

4949
void Camera::setViewDirection( const vec3 &viewDirection )
5050
{
5151
mViewDirection = normalize( viewDirection );
5252
mOrientation = glm::rotation( mViewDirection, glm::vec3( 0, 0, -1 ) );
53-
mModelViewCached = false;
53+
dirtyViewCaches();
5454
}
5555

5656
void Camera::setOrientation( const quat &orientation )
5757
{
5858
mOrientation = glm::normalize( orientation );
5959
mViewDirection = glm::rotate( mOrientation, glm::vec3( 0, 0, -1 ) );
60-
mModelViewCached = false;
60+
dirtyViewCaches();
6161
}
6262

6363
// Derived from math presented in http://paulbourke.net/miscellaneous/lens/
@@ -70,15 +70,15 @@ void Camera::setWorldUp( const vec3 &worldUp )
7070
{
7171
mWorldUp = normalize( worldUp );
7272
mOrientation = glm::toQuat( alignZAxisWithTarget( -mViewDirection, worldUp ) );
73-
mModelViewCached = false;
73+
dirtyViewCaches();
7474
}
7575

7676
void Camera::lookAt( const vec3 &target )
7777
{
7878
mViewDirection = normalize( target - mEyePoint );
7979
mOrientation = glm::toQuat( alignZAxisWithTarget( -mViewDirection, mWorldUp ) );
8080
mPivotDistance = distance( target, mEyePoint );
81-
mModelViewCached = false;
81+
dirtyViewCaches();
8282
}
8383

8484
void Camera::lookAt( const vec3 &eyePoint, const vec3 &target )
@@ -87,7 +87,7 @@ void Camera::lookAt( const vec3 &eyePoint, const vec3 &target )
8787
mViewDirection = normalize( target - mEyePoint );
8888
mOrientation = quat( glm::toQuat( alignZAxisWithTarget( -mViewDirection, mWorldUp ) ) );
8989
mPivotDistance = distance( target, mEyePoint );
90-
mModelViewCached = false;
90+
dirtyViewCaches();
9191
}
9292

9393
void Camera::lookAt( const vec3 &eyePoint, const vec3 &target, const vec3 &aWorldUp )
@@ -97,7 +97,7 @@ void Camera::lookAt( const vec3 &eyePoint, const vec3 &target, const vec3 &aWorl
9797
mViewDirection = normalize( target - mEyePoint );
9898
mOrientation = glm::toQuat( alignZAxisWithTarget( -mViewDirection, mWorldUp ) );
9999
mPivotDistance = distance( target, mEyePoint );
100-
mModelViewCached = false;
100+
dirtyViewCaches();
101101
}
102102

103103
void Camera::getFrustum( float *left, float *top, float *right, float *bottom, float *near, float *far ) const

0 commit comments

Comments
 (0)