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
  • 相关阅读:
    Undefined symbols for architecture armv7: "CreateRSADataVerifier(NSString*)", referenced from:
    iOS 多线程研究11
    iOS 多线程研究
    iOS 中谓词的使用 NSPredicate
    ios 进程间通信
    GCD Block最简单的用法
    tabbar 获得对应的视图对象的方法
    网络请求
    iOS手势 规避同一界面上不同子界面同时响应多个手势
    20171107 几天考试总结
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3310640.html
Copyright © 2011-2022 走看看