OpenGL:什么是MatrixMode? [英] OpenGL: What is MatrixMode?

查看:124
本文介绍了OpenGL:什么是MatrixMode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几种可用的模式:

Modelview
Projection
Texture
Color

它们是什么意思?最常用的是哪一种?您对初学者了解任何简单的阅读内容吗?

What do they mean? What one is most commonly used? Any easy readings you know for the beginners?

推荐答案

OpenGL使用多个矩阵来转换几何图形和相关数据.这些矩阵是:

OpenGL uses several matrices to transform geometry and associated data. Those matrices are:

  • Modelview –将对象几何放置在全局的未投影空间中
  • 投影 –将全局坐标投影到剪辑空间中;您可能会认为它像镜头一样
  • 纹理 –之前调整纹理坐标;主要用于实现纹理投影(即,将纹理像投影机中的幻灯片一样投影)
  • 颜色 –调整顶点颜色.很少碰到
  • Modelview – places object geometry in the global, unprojected space
  • Projection – projects global coordinates into clip space; you may think of it as kind of a lens
  • Texture – adjusts texture coordinates before; mostly used to implement texture projection (i.e. projecting a texture as if it was a slide in a projector)
  • Color – adjusts the vertex colors. Seldomly touched at all

所有这些矩阵始终使用.由于它们遵循所有相同的规则,因此OpenGL仅具有一组矩阵操纵函数:glPushMatrixglPopMatrixglLoadIdentityglLoadMatrixglMultMatrixglTranslateglRotateglScaleglOrthoglFrustum.

All these matrices are used all the time. Since they follow all the same rules OpenGL has only one set of matrix manipulation functions: glPushMatrix, glPopMatrix, glLoadIdentity, glLoadMatrix, glMultMatrix, glTranslate, glRotate, glScale, glOrtho, glFrustum.

glMatrixMode选择这些操作作用于哪个矩阵.假设您想编写一些C ++名称空间包装器,它看起来可能像这样:

glMatrixMode selects on which matrix those operations act upon. Say you wanted to write some C++ namespacing wrapper, it could look like this:

namespace OpenGL {
  // A single template class for easy OpenGL matrix mode association
  template<GLenum mat> class Matrix
  {
  public:
    void LoadIdentity() const 
        { glMatrixMode(mat); glLoadIdentity(); }

    void Translate(GLfloat x, GLfloat y, GLfloat z) const
        { glMatrixMode(mat); glTranslatef(x,y,z); }
    void Translate(GLdouble x, GLdouble y, GLdouble z) const
        { glMatrixMode(mat); glTranslated(x,y,z); }

    void Rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) const
        { glMatrixMode(mat); glRotatef(angle, x, y, z); }
    void Rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) const
        { glMatrixMode(mat); glRotated(angle, x, y, z); }

    // And all the other matrix manipulation functions
    // using overloading to select proper OpenGL variant depending on
    // function parameters, and all the other C++ whiz.
    // ...
  };

  // 
  const Matrix<GL_MODELVIEW>  Modelview;
  const Matrix<GL_PROJECTION> Projection;
  const Matrix<GL_TEXTURE>    Texture;
  const Matrix<GL_COLOR>      Color;
}

稍后您可以编写C ++程序

Later on in a C++ program you could write then

void draw_something()
{
    OpenGL::Projection::LoadIdentity();
    OpenGL::Projection::Frustum(...);

    OpenGL::Modelview::LoadIdentity();
    OpenGL::Modelview::Translate(...);

    // drawing commands
}

不幸的是,C ++无法模板化名称空间,或无法在实例上应用using(或with)(其他语言具有此功能),否则我会编写类似(无效的C ++)的内容

Unfortunately C++ can't template namespaces, or apply using (or with) on instances (other languages have this), otherwise I'd had written something like (invalid C++)

void draw_something_else()
{
    using namespace OpenGL;

    with(Projection) {    // glMatrixMode(GL_PROJECTION);
        LoadIdentity();   // glLoadIdentity();
        Frustum(...);     // glFrustum(...);
    }

    with(Modelview) {     // glMatrixMode(GL_MODELVIEW);
        LoadIdentity();   // glLoadIdentity();
        Translate(...);   // glTranslatef(...);
    }

}

我想这最后的(伪)代码片段清楚了:glMatrixMode是OpenGL的with语句.

I think this last snipped of (pseudo-)code makes it clear: glMatrixMode is kind of a with statement of OpenGL.

这篇关于OpenGL:什么是MatrixMode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆