MCPcopy Create free account
hub / github.com/cinder/Cinder / draw

Method draw

samples/CameraPersp/src/CameraPerspApp.cpp:186–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

184}
185
186void CameraPerspApp::draw()
187{
188 gl::clear( Color( 0.2, 0.2, 0.2 ) );
189 gl::ScopedGlslProg shaderScp( gl::getStockShader( gl::ShaderDef().color() ) );
190
191 gl::setMatrices( mViewCam );
192 gl::viewport( getWindowWidth() / 2, 0.0f, getWindowWidth() / 2, getWindowHeight() );
193
194 vec3 wTopLeft;
195 vec3 wTopRight;
196 vec3 wBottomLeft;
197 vec3 wBottomRight;
198
199 // Draw the far plane rect
200 mObjectCam.getFarClipCoordinates( &wTopLeft, &wTopRight, &wBottomLeft, &wBottomRight );
201 auto farPlane = gl::VertBatch( GL_TRIANGLE_STRIP );
202 farPlane.color( ColorA ( 0.0f, 0.0f, 0.0f, 0.7f ) );
203 farPlane.vertex( wTopLeft );
204 farPlane.vertex( wBottomLeft );
205 farPlane.vertex( wTopRight );
206 farPlane.vertex( wBottomRight );
207 farPlane.draw();
208
209 // Draw a ray from the camera to the lookAt Point
210 auto ray = gl::VertBatch( GL_LINES );
211 ray.color( Color( 0.0f, 1.0f, 0.0f ) );
212 ray.vertex( mEyePoint );
213 ray.vertex( mLookAt );
214 ray.draw();
215
216 // Draw a ray from mouse to the far plane
217 vec2 sTopLeft = mObjectCam.worldToScreen( wTopLeft, getWindowWidth() / 2, getWindowHeight() );
218 vec2 sBottomRight = mObjectCam.worldToScreen( wBottomRight, getWindowWidth() / 2, getWindowHeight() );
219 Rectf r = Rectf( sTopLeft, sBottomRight );
220
221 if ( r.contains( mLastMousePos ) ) {
222 Ray clickRay = mObjectCam.generateRay( mLastMousePos, ivec2( getWindowWidth() / 2, getWindowHeight() ) );
223 auto rayLine = gl::VertBatch( GL_LINES );
224 rayLine.color( Color( 0.8f, 0.0f, 0.0f ) );
225 rayLine.vertex( mEyePoint );
226 rayLine.vertex( mEyePoint + clickRay.getDirection() * mObjectCam.getFarClip() );
227 rayLine.draw();
228 }
229
230 // Draw camera frustrum
231 gl::color( ColorA( 0.8f, 0.8f, 0.8f, 0.5f ) );
232 gl::drawFrustum( mObjectCam );
233
234 // Draw the object in the scene
235 mObjectFbo->bindTexture();
236 gl::color( Color( 1.0f, 1.0f, 1.0f ) );
237 mObjects.at( mCurrObject )->draw();
238
239 // Draw the near plane with projection
240 gl::ScopedGlslProg shaderScp2( gl::getStockShader( gl::ShaderDef().texture().color() ) );
241 mObjectCam.getNearClipCoordinates( &wTopLeft, &wTopRight, &wBottomLeft, &wBottomRight );
242 mObjectFbo->bindTexture();
243

Callers 1

renderObjectToFboMethod · 0.45

Calls 15

setMatricesFunction · 0.85
getWindowWidthFunction · 0.85
getWindowHeightFunction · 0.85
drawFrustumFunction · 0.85
setMatricesWindowFunction · 0.85
drawSolidRectFunction · 0.85
colorMethod · 0.80
vertexMethod · 0.80
worldToScreenMethod · 0.80
atMethod · 0.80
clearFunction · 0.50
ColorFunction · 0.50

Tested by

no test coverage detected