当前位置: 首页>>代码示例>>C++>>正文


C++ Arcball::createModelRotationMatrix方法代码示例

本文整理汇总了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;
}
开发者ID:cirocosta,项目名称:Arcball,代码行数:101,代码来源:main.cpp


注:本文中的Arcball::createModelRotationMatrix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。