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

Method draw

test/WindowToWorldTest/src/WindowToWorldTestApp.cpp:74–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void WindowToWorldTestApp::draw()
75{
76 gl::clear();
77
78 // Create a list of (object space) corners, so we can easily draw them.
79 vec2 corners[] = { mRectangle.area.getUpperLeft(), mRectangle.area.getUpperRight(),
80 mRectangle.area.getLowerRight(), mRectangle.area.getLowerLeft() };
81
82 // Either use setMatricesWindow() or setMatricesWindowPersp() to enable 2D rendering.
83 gl::setMatricesWindow( getWindowSize(), false );
84
85 // Draw the transformed rectangle.
86 gl::pushModelMatrix();
87 gl::multModelMatrix( mRectangle.matrix() );
88
89 // Draw a stroked rect in magenta (if mouse inside) or white (if mouse outside).
90 if( mIsOver )
91 gl::color( 1, 0, 1 );
92 else
93 gl::color( 1, 1, 1 );
94 gl::drawStrokedRect( mRectangle.area );
95
96 // Draw the same rect as line segments.
97 gl::drawLine( corners[0], corners[1] );
98 gl::drawLine( corners[1], corners[2] );
99 gl::drawLine( corners[2], corners[3] );
100 gl::drawLine( corners[3], corners[0] );
101
102 // Draw the 4 corners as yellow crosses.
103 for( vec2 &corner : corners ) {
104 gl::color( 1, 1, 0 );
105 gl::drawLine( vec2( corner.x, corner.y - 5 ), vec2( corner.x, corner.y + 5 ) );
106 gl::drawLine( vec2( corner.x - 5, corner.y ), vec2( corner.x + 5, corner.y ) );
107 }
108
109 gl::popModelMatrix();
110
111 // To test worldToWindowCoord, let's draw the 4 corners again,
112 // this time as red crosses without changing the model matrix. [ Excercising gl::worldToWindowCoord() ].
113 for( vec2 &corner : corners ) {
114 vec4 world = mRectangle.matrix() * vec4( corner, 0, 1 );
115 vec2 window = gl::worldToWindowCoord( vec3( world ) );
116 vec2 scale = mRectangle.scale;
117
118 gl::color( 1, 0, 0 );
119 gl::drawLine( vec2( window.x, window.y - 5 * scale.y ), vec2( window.x, window.y + 5 * scale.y ) );
120 gl::drawLine( vec2( window.x - 5 * scale.x, window.y ), vec2( window.x + 5 * scale.x, window.y ) );
121 }
122}
123
124void WindowToWorldTestApp::mouseMove( MouseEvent event )
125{

Callers

nothing calls this directly

Calls 11

setMatricesWindowFunction · 0.85
pushModelMatrixFunction · 0.85
multModelMatrixFunction · 0.85
drawStrokedRectFunction · 0.85
popModelMatrixFunction · 0.85
worldToWindowCoordFunction · 0.85
matrixMethod · 0.80
clearFunction · 0.50
getWindowSizeFunction · 0.50
colorFunction · 0.50
drawLineFunction · 0.50

Tested by

no test coverage detected