opengl笔记——旋转,一段代码的理解
在找到这段代码,对理解opengl旋转很有帮助
...
glPushMatrix(); // initialze ModelView matrix
glLoadIdentity(); // First, transform the camera (viewing matrix) from world space to eye space
// Notice all values are negated, because we move the whole scene with the
// inverse of camera transform
//要理解这段代码:opengl 没有提供操作相机的函数,移动相机就是反向移动模型坐标
//可以理解为:把物体移到视野中去
glRotatef(-cameraAngle[2], 0, 0, 1); // roll
glRotatef(-cameraAngle[1], 0, 1, 0); // heading
glRotatef(-cameraAngle[0], 1, 0, 0); // pitch
glTranslatef(-cameraPosition[0], -cameraPosition[1], -cameraPosition[2]); // draw the grid at origin before model transform
// 注意:表示
drawGrid(); // transform the object (model matrix)
// The result of GL_MODELVIEW matrix will be:
// ModelView_M = View_M * Model_M
glTranslatef(modelPosition[0], modelPosition[1], modelPosition[2]);
glRotatef(modelAngle[0], 1, 0, 0);
glRotatef(modelAngle[1], 0, 1, 0);
glRotatef(modelAngle[2], 0, 0, 1); // draw a teapot with model and view transform together
drawTeapot(); glPopMatrix();
...
比较:
// transform the object (model matrix)
// The result of GL_MODELVIEW matrix will be:
// ModelView_M = View_M * Model_M
glTranslatef(modelPosition[0], modelPosition[1], modelPosition[2]);
glRotatef(modelAngle[0], 1, 0, 0);
glRotatef(modelAngle[1], 0, 1, 0);
glRotatef(modelAngle[2], 0, 0, 1);
//放在这,区别:网格随物体移动(当改变modelPosition时)
drawGrid();
// draw a teapot with model and view transform togetherdrawTeapot();
http://www.songho.ca/opengl/gl_transform.html#overview
opengl笔记——旋转,一段代码的理解的更多相关文章
- if __name__ == '__main__' 这段代码怎么理解???
__name__是内置变量,可用于表示当前模块的名字,而“__main__”等于当前执行文件的名称. 两个名称搞不清没关系,往下看待会解释 对很多编程语言来说,程序都需要一个入口,例如C系列.Java ...
- 一段代码看 Java 引用类型
Java 中的操作数(不知道叫什么,相对于 bytecode 而言,类似 CPU 的操作码和操作数)分为值类型和引用类型: 值类型就是直接存储最终数值的,如 char, int, float, dou ...
- 关于阮一峰老师es6(第三版)中管道机制代码的理解浅析
最近正在学习阮一峰老师的es6(第三版)教材,在学到第七章<函数的扩展>中的箭头函数嵌套时,文中提到了一个关于“管道机制”的示例,文中源代码如下: //es6(第三版)教材中的管道机制源代 ...
- JVM学习笔记 -- 从一段几乎所有人代码都会犯错的代码开始
废话不多说 看看这段代码.告诉我结果: import java.io.*; class Test { public static Test t = new Test(); public Test(){ ...
- shell编程学习笔记(一):编写我的第一段代码
目前在学习Shell编程,我会把我的学习笔记记录在这里.大神可以直接略过~ 嗯,第一段代码,肯定是要输出Hello World了~ 以下蓝色字体的内容为linux命令,红色字体的内容为输出的内容: # ...
- Android菜鸟的成长笔记(4)——你真的理解了吗?
原文:Android菜鸟的成长笔记(4)--你真的理解了吗? 在上一篇中我们查看了QQ的apk源文件中的布局结构,并仿照QQ完成了我们第一个应用的界面,详细请看<Android菜鸟的成长笔记&g ...
- 【转】 BSS段 数据段 代码段 堆栈 指针 vs 引用
原文:http://blog.csdn.net/godspirits/article/details/2953721 BSS段 数据段 代码段 堆栈 (转+) 声明:大部分来自于维基百科,自由的百科全 ...
- 为什么需要异步?why?来看一段代码。
为什么需要异步?why?来看一段代码. 问题1: for(var i=0;i<100000;i++){ } alert('hello world!!!'); 这段代码的意思是执行100...次后 ...
- tensorflow笔记:多层LSTM代码分析
tensorflow笔记:多层LSTM代码分析 标签(空格分隔): tensorflow笔记 tensorflow笔记系列: (一) tensorflow笔记:流程,概念和简单代码注释 (二) ten ...
随机推荐
- html中隐藏域hidden的作用
基本语法: <input type="hidden" name="field_name" value="value"> 作用: ...
- Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integ ...
- Ffmpeg和SDL创建线程(转)
Spawning Threads Overview Last time we added audio support by taking advantage of SDL's audio functi ...
- STL中的set集合容器进行集合运算:并、交、差实例
集合容器的集合运算:并.交.差: #include "stdafx.h" #include <iostream> #include <set> #inclu ...
- 使用 React和webpack开发和打包发布
建议在 React 中使用 CommonJS 模块系统,比如 browserify 或 webpack,本次使用 webpack. 第一步.安装全局包 $ npm install babel -g $ ...
- 终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions
3天硬是是把这个问题解决了 有时候突然上个厕所灵感就来了 第一次向用JSTL解析xml 然后我想遍历整个xml文档打印出来 居然不让我输入变量 那让我怎么办啊 在网上各种找答案 说什么<%@ t ...
- mapkit定位以及俯视视图
1.导入框架MapKit.framework,CoreGraphics.framework
- JavaScript面向对象,闭包内存图,闭包和作用域
var i = 10; function test(){ var j; i=20; //未定义 function test(){ j='hello'; } console.log(test()); / ...
- 统计字符 比如aaabbcca----3a2b1c1a
package Demo; import java.util.Scanner; /** * Created by chengpeng on 16/11/3. */ /* idea command+al ...
- Spring-----6、Spring3.0提供的Java配置管理
转载自:http://blog.csdn.net/hekewangzi/article/details/45646279