Skip to content

Commit be321c2

Browse files
committed
Added convenience constructors to Scoped*Matrix classes.
Allows users to directly set the desired matrices. Old: ``` gl::ScopedMatrices scpMatrices; gl::setMatrices( mCam ); gl::ScopedModelMatrix scpModel; gl::setModelMatrix( mModelMatrix ); ``` New: ``` gl::ScopedMatrices scpMatrices( mCam ); gl::ScopedModelMatrix scpModel( mModelMatrix ); ```
1 parent 26c958b commit be321c2

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

include/cinder/gl/scoped.h

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,24 +208,44 @@ struct CI_API ScopedViewport : private Noncopyable {
208208
};
209209

210210
struct CI_API ScopedModelMatrix : private Noncopyable {
211-
ScopedModelMatrix() { gl::pushModelMatrix(); }
212-
~ScopedModelMatrix() { gl::popModelMatrix(); }
211+
ScopedModelMatrix() { gl::pushModelMatrix(); }
212+
explicit ScopedModelMatrix( const mat4 &m )
213+
{
214+
gl::pushModelMatrix();
215+
gl::setModelMatrix( m );
216+
}
217+
~ScopedModelMatrix() { gl::popModelMatrix(); }
213218
};
214219

215220
struct CI_API ScopedViewMatrix : private Noncopyable {
216-
ScopedViewMatrix() { gl::pushViewMatrix(); }
217-
~ScopedViewMatrix() { gl::popViewMatrix(); }
221+
ScopedViewMatrix() { gl::pushViewMatrix(); }
222+
explicit ScopedViewMatrix( const mat4 &m )
223+
{
224+
gl::pushViewMatrix();
225+
gl::setViewMatrix( m );
226+
}
227+
~ScopedViewMatrix() { gl::popViewMatrix(); }
218228
};
219229

220230
struct CI_API ScopedProjectionMatrix : private Noncopyable {
221-
ScopedProjectionMatrix() { gl::pushProjectionMatrix(); }
222-
~ScopedProjectionMatrix() { gl::popProjectionMatrix(); }
231+
ScopedProjectionMatrix() { gl::pushProjectionMatrix(); }
232+
explicit ScopedProjectionMatrix( const mat4 &m )
233+
{
234+
gl::pushProjectionMatrix();
235+
gl::setProjectionMatrix( m );
236+
}
237+
~ScopedProjectionMatrix() { gl::popProjectionMatrix(); }
223238
};
224239

225240
//! Preserves all matrices
226241
struct CI_API ScopedMatrices : private Noncopyable {
227-
ScopedMatrices() { gl::pushMatrices(); }
228-
~ScopedMatrices() { gl::popMatrices(); }
242+
ScopedMatrices() { gl::pushMatrices(); }
243+
explicit ScopedMatrices( const Camera &cam )
244+
{
245+
gl::pushMatrices();
246+
gl::setMatrices( cam );
247+
}
248+
~ScopedMatrices() { gl::popMatrices(); }
229249
};
230250

231251
//! Scopes state of face culling.

0 commit comments

Comments
 (0)