本文整理汇总了C++中Arcball::createModelRotationMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ Arcball::createModelRotationMatrix方法的具体用法?C++ Arcball::createModelRotationMatrix怎么用?C++ Arcball::createModelRotationMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arcball
的用法示例。
在下文中一共展示了Arcball::createModelRotationMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
glm::mat4 model = glm::mat4(1.0);
glm::mat4 view = glm::lookAt( glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0., 0., 0.), glm::vec3(0., 1., 0.) );
glm::mat4 projection = glm::perspective(70.0f, 4.0f/3.0f, 0.1f, 100.0f );
glm::vec3 light_position = glm::vec3( 4, 4, 4 );
shader.bind();
shader.setUniform( "light_position_w", light_position );
while( !glfwWindowShouldClose( window )){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
{ /* Draw on 1st viewport, show rotation of the camera */
glViewport( 0, 0, WINDOW_WIDTH / 2, WINDOW_HEIGHT );
glm::mat4 rotated_view = view * arcball.createViewRotationMatrix();
glm::mat4 mvp = projection * rotated_view * model;
shader.setUniform( "light_color", glm::vec3(1.0, 1.0, 0.0) );
shader.setUniform( "v", rotated_view );
shader.setUniform( "m", model );
shader.setUniform( "mvp", mvp );
/* Draw cube */
glEnableVertexAttribArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, cube_buffers[0] );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnableVertexAttribArray( 1 );
glBindBuffer( GL_ARRAY_BUFFER, cube_buffers[1] );
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnable( GL_CULL_FACE );
glDrawArrays( GL_TRIANGLE_STRIP, 0, static_cast<int>(cube_buffer_data.size()) );
/* Draw the floor, with different color */
shader.setUniform( "light_color", glm::vec3(0.0, 1.0, 1.0) );
glEnableVertexAttribArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, floor_buffers[0] );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnableVertexAttribArray( 1 );
glBindBuffer( GL_ARRAY_BUFFER, floor_buffers[1] );
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glDisable( GL_CULL_FACE );
glDrawArrays( GL_TRIANGLE_STRIP, 0, static_cast<int>(floor_buffer_data.size()) );
}
{ /* Draw on 2nd viewport, show rotation of the model */
glViewport( WINDOW_WIDTH / 2, 0, WINDOW_WIDTH / 2, WINDOW_HEIGHT );
glm::mat4 rotated_model = model * arcball.createModelRotationMatrix( view );
glm::mat4 mvp = projection * view * rotated_model;
shader.setUniform( "light_color", glm::vec3(1.0, 1.0, 0.0) );
shader.setUniform( "v", view );
shader.setUniform( "m", rotated_model );
shader.setUniform( "mvp", mvp );
/* Draw cube */
glEnableVertexAttribArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, cube_buffers[0] );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnableVertexAttribArray( 1 );
glBindBuffer( GL_ARRAY_BUFFER, cube_buffers[1] );
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnable( GL_CULL_FACE );
glDrawArrays( GL_TRIANGLE_STRIP, 0, static_cast<int>(cube_buffer_data.size()) );
/* Draw the floor, with different color */
shader.setUniform( "light_color", glm::vec3(0.0, 1.0, 1.0) );
glEnableVertexAttribArray( 0 );
glBindBuffer( GL_ARRAY_BUFFER, floor_buffers[0] );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glEnableVertexAttribArray( 1 );
glBindBuffer( GL_ARRAY_BUFFER, floor_buffers[1] );
glVertexAttribPointer( 1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
glDisable( GL_CULL_FACE );
glDrawArrays( GL_TRIANGLE_STRIP, 0, static_cast<int>(floor_buffer_data.size()) );
}
glfwSwapBuffers( window );
glfwPollEvents();
}
shader.unbind();
glDeleteBuffers( 2, cube_buffers );
glDeleteBuffers( 2, floor_buffers );
glDeleteVertexArrays( 1, &vertex_array_id );
return 0;
}