0

私は opengl の研究を始めたばかりです。コードの一部を投稿し、私の理解を説明します。私の説明に従って問題点を指摘していただけますか?

glMatrixMode(GL_MODELVIEW); 
glLoadIdentity();   //start with an identity matrix

glPushMatrix();  
//push the current identity matrix onto the stack, and start with a new identity matrix as 
  the transformation matrix

    glPushMatrix();  
    //copy the current matrix which is the identity as the new transformation matrix and then push the current transformation matrix onto stack

        glScalef(10, 10, 1.0);
        **Question 1**
        //I feels like the order which the image is built is kinda reversed
        //It's like drawSquare happens first, then color, then scale
        //can anyone clarify?
        //Second, the drawsquare defines the 4 vertices around the origin(+/-0.5,+/-0.5)
        //is the origin located at the center of the window by default?
        //what happen when it is scaled? does point (0.5,0.5) scaled to (5,5)?
        glColor3f(0.0, 1.0, 0.0);
        drawSquare(1.0);
    glPopMatrix(); 
    //forget the current transformation matrix, pop out the one on top of the stack
    //which is the identity matrix

    //In the code below:
    //my understanding is 4 vertices is defined around origin, but is this the same origin?
    //then the unit square is moved just below the X-axis
    //and the 4 vertices are scaled one by one?
    //ex: (0.5,0) -> (1,0)  (0.5,-1) -> (1,-2)
    glScalef(2, 2, 1.0);
    glTranslatef(0.0, -0.5, 0.0);
    glColor3f(1.0, 0.0, 0.0);
    drawSquare(1.0);
    //last question, if I want to make the second square rotate at a point along z-axis
    //do I have to specify it here? 
    //for example: add glRotatef(rotate_degree, 0.0, 0.0, 1.0); above the glScalef(2, 2, 1.0);
    //such that later i can change the value in the rotate_degree?

glPopMatrix(); //forget about the current transformation matrix, pop out the top matrix on the stack.
4

1 に答える 1

1

演算の順序が逆になっているように見えるのは、列ベクトルを乗算すると行列が非可換で右結合になるという事実から来ています。モデル空間に位置列ベクトル↑pがあるとします。それをワールド空間に持ち込むには、行列Mで乗算します。つまり、

↑p _world = M · ↑p

操作の順序は変更できないことに注意してください。列ベクトルはキーのようにマトリックスに一致し、キーは右からマトリックス ロックに適合します。

次のステップでは、行列Vを使用してビュー空間に変換するので、次のように記述します

↑p _view = V · ↑p _world

しかし、これはあなたが置き換えることができます

↑p _view = VM↑p

しかしもちろん、多くの↑p -s がある場合は、計算を節約したいので、これら 2 つの行列MVをモデル ビューと呼ばれる 1 つの行列に縮小します。そして、OpenGL でモデルビューをビルドするときは、次のようにビルドします:

MV = 1
MV = MV · V
MV = MV · M

列順の行列乗算の正しい結合性により、ベクトルに適用される最初の変換は、スタックに乗算される最後の変換になります。


順行列演算を使用すると、左結合になることに注意してください。つまり、記述した順序で処理が行われます。しかし、列順の右結合性は非常に便利です。分岐変換階層の構築がはるかに簡単になるからです。

于 2013-01-29T01:20:52.500 に答える