OpenGL学习(七) 矩阵学习
来源:互联网 发布:舞美设计用什么软件 编辑:程序博客网 时间:2024/06/05 04:19
// ModelviewProjection.cpp// OpenGL SuperBible// Demonstrates OpenGL the ModelviewProjection matrix// Program by Richard S. Wright Jr.#include <GLTools.h>// OpenGL toolkit#include <GLMatrixStack.h>#include <GLFrame.h>#include <GLFrustum.h>#include <GLGeometryTransform.h>#include <GLBatch.h>#include <StopWatch.h>#include <math.h>#ifdef __APPLE__#include <glut/glut.h>#else#define FREEGLUT_STATIC#include <GL/glut.h>#endif// Global view frustum classGLFrustum viewFrustum;// The shader managerGLShaderManager shaderManager;// The torusGLTriangleBatch torusBatch;// Set up the viewport and the projection matrixvoid ChangeSize(int w, int h) {// Prevent a divide by zeroif(h == 0)h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 1000.0f); }// Called to draw scenevoid RenderScene(void){ // Set up time based animation static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; // Clear the window and the depth bufferglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Matrix Variables M3DMatrix44f mTranslate, mRotate, mModelview, mModelViewProjection; // Create a translation matrix to move the torus back and into sight m3dTranslationMatrix44(mTranslate, 0.0f, 0.0f, -2.5f); // Create a rotation matrix based on the current value of yRot m3dRotationMatrix44(mRotate, m3dDegToRad(yRot), 0.0f, 1.0f, 0.0f); // Add the rotation to the translation, store the result in mModelView m3dMatrixMultiply44(mModelview, mTranslate, mRotate); // Add the modelview matrix to the projection matrix, // the final matrix is the ModelViewProjection matrix. m3dMatrixMultiply44(mModelViewProjection, viewFrustum.GetProjectionMatrix(),mModelview); // Pass this completed matrix to the shader, and render the torus GLfloat vBlack[] = { 0.0f, 0.0f, 0.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_FLAT, mModelViewProjection, vBlack); torusBatch.Draw(); // Swap buffers, and immediately refresh glutSwapBuffers(); glutPostRedisplay();}// This function does any needed initialization on the rendering// context. void SetupRC(){// Black backgroundglClearColor(0.8f, 0.8f, 0.8f, 1.0f ); glEnable(GL_DEPTH_TEST); shaderManager.InitializeStockShaders(); // This makes a torus gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);}///////////////////////////////////////////////////////////////////////////////// Main entry point for GLUT based programsint main(int argc, char* argv[]) {gltSetWorkingDirectory(argv[0]);glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);glutInitWindowSize(800, 600);glutCreateWindow("ModelViewProjection Example"); glutReshapeFunc(ChangeSize); glutDisplayFunc(RenderScene); GLenum err = glewInit();if (GLEW_OK != err) {fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));return 1; }SetupRC(); glutMainLoop();return 0; }
2 0
- OpenGL学习(七) 矩阵学习
- OpenGL入门学习(七)
- OpenGL入门学习(七)
- OpenGL入门学习(七)
- OpenGL入门学习(七)
- OPENGL视频学习(七)
- OpenGL学习总结(七)
- OpenGL学习笔记(七)
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- 从零开始学习OpenGL ES之七 – 变换和矩阵
- OpenGL学习笔记(七)
- OpenGL入门学习[七]
- codeforces日记371d
- git 使用
- Widows触发一个断点,其原因可能是堆被损坏
- Ubuntu中vim无法使用 提示:apt-get install时
- 从零开始-边学边做-塔防游戏-七彩三国(五)--SDL项目
- OpenGL学习(七) 矩阵学习
- 印刷电路板(PCB)的电磁兼容设计
- Makefile中的常用函数
- python,numpy等的安装方式以及Theano的安装、vim的python开发环境配置总结
- c++ STL之 copy(权哥)
- 有向网的各种功能实现
- 【九度】题目1001:A+B for Matrices
- ASP.NET 中的内置对象
- 用PROTEL DXP电路板设计的一般原则