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());
opengl笔记—— glMultMatrixf() 区别 glLoadMatrixf()的更多相关文章
- opengl笔记——旋转,一段代码的理解
重看:opengl笔记——OpenGL好资料备忘 在找到这段代码,对理解opengl旋转很有帮助 ... glPushMatrix(); // initialze ModelView matrix g ...
- OpenGL 笔记 <2> Compiling and Linking a shader program
Preface 这一节所有的主要内容都在一个OpenGL库文件中<LoadShaders.h> ,只需要用LoadShader()函数进行加载即可.但是由于老是出错,所以自己实现了一下,也 ...
- OpenGL笔记(一) 绘制三角形
GLTools: 一些有用且可复用的函数 GLEW: OpenGL API的一些扩展机制 GLUT: OpenGL Utility toolkit, OpenGL跨平台相关,隐藏平台相关细节 RC代表 ...
- opengl笔记——OpenGL好资料备忘
Plane Equation 注:面可理解为:连接面上的点与原点,投影相同(为:a*x1+b*x2+c*x3) OpenGL Matrix Class (C++) Overview OpenGL fi ...
- opengl 笔记(2)
/*- * Opengl Demo Test * * Fredric : 2016-7-10 */ #include <GLUT/GLUT.h> #include <stdlib.h ...
- opengl 笔记(1)
参考<opengl入门教程>.<OpenGL之坐标转换>.<OpenGL绘制管线操作细节>等资料. 复习下留个备忘:) /*- * Opengl Demo Test ...
- opengl笔记
GL_ARRAY_BUFFER(表示顶点数据) GL_ELEMENT_ARRAY_BUFFER(表示索引数据) GL_PIXEL_UNPACK_BUFEER( 表示传递给O p e n G L 的像素 ...
- OpenGL笔记(五) 着色器渲染(以Android为例)
一.Android平台上下文环境的创建及初始化 1. 首先实例化Android上下文环境,即EGL的初始化. bool EGLCore::init(EGLContext sharedContext) ...
- OpenGL笔记(四) API参考
常见API glActiveTexture 选择活动纹理单元 glAttachShader 将一个着色器对象绑定到一个程序对象 void glAttachShader(GLuint program, ...
随机推荐
- 使用Canvas实现动画效果 | DKlogs -- 设计 | 生活
使用Canvas实现动画效果 | DKlogs -- 设计 | 生活 使用Canvas实现动画效果
- poj 1986 Distance Queries(LCA)
Description Farmer John's cows refused to run in his marathon since he chose a path much too long fo ...
- 了解Serialization
对象的串行化(Serialization) 一.串行化的概念和目的 1.什么是串行化 对象的寿命通常随着生成该对象的程序的终止而终止.有时候,可能需要将对象的状态保存下来,在需要时再将对象恢复.我们把 ...
- JS~delegate与live
在jquery里有两个方法可以用来绑定自动追加出来的DOM对象,它们是live和delegate,事实上,这两个方法是bind方法的一个变体,在对于固定DOM对象时,我们通常使用bind就可以了,而对 ...
- 所闻所获6:meditashayne项目总结
项目源码下载地址: https://github.com/ShayneYeorg/Meditashayne 1.首先一开始设计这个App的时候,我就希望它能比系统自带的备忘录更方便:比如备忘录需要手动 ...
- asp.net关于Repeater控件中的全选,批量操作
今天在Repeater控件中碰到一个全选的操作,于是上网查了一下,找到一个觉得比较好,便记录下来, 界面代码简化之后(全选操作): <script type="text/javascr ...
- mvc 客户端验证
@model MvcApplication1.Models.ViewClass @{ ViewBag.Title = "View2"; } @******引用这两个js实现客户端的 ...
- Spring 注入数据源
一.在项目中添加dataSource所用到的包 dbcp数据源所需包: commons-dbcp.jar commons-pool.jar C3P0数据源所需包: c3p0-0 ...
- 获取设备、APP的一些信息
获取设备的一些信息: UIDevice *device = [UIDevice currentDevice]; @property(nonatomic,readonly,strong) NSStrin ...
- G - Reduced ID Numbers(第二季水)
Description T. Chur teaches various groups of students at university U. Every U-student has a unique ...