NeHe OpenGL Lesson04 - Rotation

screen_shot2-300x237 This program shows how to make the objects rotated.  OpenGL API is kind of so low level graphic API that allows the user create some separate matrix components.  Here this sample just give some basic idea how the rotation happened, but I guess in the real time rendering module they never use such kind of 3D api calls. Most of time, they will compute a final one world matrix  for one objects and submit it to GPU, they won’t let the 3D API to collect the separate information, such as the rotations, translates, scale, and let them pass from root to the children and repeat the process until the leaf scene node. Then ask the 3D API themselves to calculate the final matrix. Obviously, this method is very un efficient.

Most of time, we will keep a matrix variable for each scene node. Some one told me that such matrixes update loop also very un efficient. A much better way to improve that is you should build your matrix pool or matrix array. Every frame you will update the whole matrix array, because the data storage is continues, they will be less CPU stall happen here, that means we always process those data that we only need to be updated. Such optimization is kind of very advanced technique.

In 3D graphics, the matrix is a very important concept. The order is very important, that means you could not re-order them as you wish. Most of time, you should not translate first equal to the rotation first. And be careful which space you are currently working on.

复制代码
glTranslatef(-1.5f, 0.0f, -6.0f);
glRotatef(mRotateTri, 0.0f, 1.0f, 0.0f);
glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);

    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);

    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
复制代码

 

The whole program coded under Ubuntu 10.4 OS. You need to install gcc, cmake, opengl to compile and run it.

 

The full source code could be found here.

posted @   opencoder  阅读(195)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示