《基于MFC的OpenGL编程》Part 5 Transformations - Rotations, Translations and Scaling

Transformations - Translation, Rotation and Scaling

Translation is nothing but moving along an arbitrary axis. Rotation is spinning about an arbitrary axis. Scaling is increase or decrease in size along an arbitrary axis. One important point to remember is that OpenGL uses a right hand coordinate system where Z-ve goes into the Screen. An object said to be undergoing a transformation could be undergoing a translation, rotation and/or scaling. Understanding how different types of transformations work together is very important.

本文将对地球进行建模,让其围绕着太阳,此外它还会有月球伴随,而在下文中将会加入对鼠标和键盘的事件响应机制。

绘制代码

复制代码
void CCY457OpenGLView::RenderScene ()
{
//绘制函数
        
//Draw Sun
    glTranslatef(0.0f,0.0f,-5.0f);
    glRotatef(
6,1.0f,0.0f,0.0f);
    glutWireSphere(
1.0f,20,20);
    
//Draw Planet
    glPushMatrix();
        glTranslatef(
-1.2f,-0.5f,-2.0f);
        glRotatef(
6,1.0f,0.0f,0.0f);
        glutWireSphere(
0.5f,20,20);
        
//Draw Moon
        glPushMatrix();
            glTranslatef(
-1.2f,-0.5f,-2.0f);
            glRotatef(
6,1.0f,0.0f,0.0f);
            glutWireSphere(
0.05f,20,20);
        glPopMatrix();
    glPopMatrix();
}
复制代码

 

posted on   Phinecos(洞庭散人)  阅读(6290)  评论(2编辑  收藏  举报

编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述

导航

统计

点击右上角即可分享
微信分享提示