zoukankan      html  css  js  c++  java
  • opengl笔记—— glMultMatrixf() 区别 glLoadMatrixf()

    能找到最好的解释来自:http://www.gamedev.net/topic/489879-glpushmatrixglpopmatrix--glloadmatrixf/

    原理:

    glPushMatrix didn't fail to push onto the stack; it's job is to push a copy of the current matrix onto a stack of matrices. Those matrices on the stack don't interact at all. You only manipulate the current, top-most, matrix at any given time.

    Example 1:

       command                 result
    
    glLoadMatrixf(A)       stack = [A]
    glPushMatrix()         stack = [A, A]
    glLoadMatrixf(B)       stack = [B, A]
    glPopMatrix()          stack = [A]


    Example 2:

       command                 result
    
    glLoadMatrixf(A)       stack = [A]
    glPushMatrix()         stack = [A, A]
    glMultMatrixf(B)       stack = [AB, A]
    glPopMatrix()          stack = [A]


    注意: glTranslate* 等都是实际调用的是glMultMatrixf

    实例:

    看下面的代码:

    743     glPushMatrix();
    744 
    745     // tramsform camera
    746     matrixView.identity();
    747     matrixView.rotate(cameraAngleY, 0, 1, 0);
    748     matrixView.rotate(cameraAngleX, 1, 0, 0);
    749     matrixView.translate(0, 0, -cameraDistance);
    750     //@@ the equivalent code for using OpenGL routine is:
    751     //@@ glTranslatef(0, 0, -cameraDistance);
    752     //@@ glRotatef(cameraAngleX, 1, 0, 0);   // pitch
    753     //@@ glRotatef(cameraAngleY, 0, 1, 0);   // heading
    754 
    755     // copy view matrix to OpenGL
    756     glLoadMatrixf(matrixView.getTranspose());
    757 
    758     drawGrid();                         // draw XZ-grid with default size
    759 
    760     // compute model matrix
    761     matrixModel.identity();
    762     //matrixModel.rotateZ(45);        // rotate 45 degree on Z-axis
    763     matrixModel.rotateY(10);        // rotate 45 degree on Y-axis
    764     matrixModel.translate(0, 1, 0); // move 2 unit up
    765 
    766     // compute modelview matrix
    767     matrixModelView = matrixView * matrixModel;
    768 
    769     // copy modelview matrix to OpenGL
    770     glLoadMatrixf(matrixModelView.getTranspose());
    771 
    772     drawAxis();
                                  
    770     glLoadMatrixf(matrixModelView.getTranspose());
    
    不能是glMultMatrixf
  • 相关阅读:
    使用_Capistrano_进行自动化部署(2)
    使用 Capistrano 进行自动化部署
    Zend_Framework_1 框架是如何被启动的?
    PHP新版本变化
    Phpstorm 无法自动断点 Exception
    理解希尔排序
    C# Thread 线程
    Unity 依赖注入容器的AOP扩展
    C# 面向切面编程 AOP
    C# 表达式树 Expression
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3310640.html
Copyright © 2011-2022 走看看