<bdo id='UCShs'></bdo><ul id='UCShs'></ul>

      <tfoot id='UCShs'></tfoot>
    1. <small id='UCShs'></small><noframes id='UCShs'>

      <i id='UCShs'><tr id='UCShs'><dt id='UCShs'><q id='UCShs'><span id='UCShs'><b id='UCShs'><form id='UCShs'><ins id='UCShs'></ins><ul id='UCShs'></ul><sub id='UCShs'></sub></form><legend id='UCShs'></legend><bdo id='UCShs'><pre id='UCShs'><center id='UCShs'></center></pre></bdo></b><th id='UCShs'></th></span></q></dt></tr></i><div id='UCShs'><tfoot id='UCShs'></tfoot><dl id='UCShs'><fieldset id='UCShs'></fieldset></dl></div>
        <legend id='UCShs'><style id='UCShs'><dir id='UCShs'><q id='UCShs'></q></dir></style></legend>

        生成带有三角形条带的平面

        时间:2023-09-18
        • <i id='hTYWZ'><tr id='hTYWZ'><dt id='hTYWZ'><q id='hTYWZ'><span id='hTYWZ'><b id='hTYWZ'><form id='hTYWZ'><ins id='hTYWZ'></ins><ul id='hTYWZ'></ul><sub id='hTYWZ'></sub></form><legend id='hTYWZ'></legend><bdo id='hTYWZ'><pre id='hTYWZ'><center id='hTYWZ'></center></pre></bdo></b><th id='hTYWZ'></th></span></q></dt></tr></i><div id='hTYWZ'><tfoot id='hTYWZ'></tfoot><dl id='hTYWZ'><fieldset id='hTYWZ'></fieldset></dl></div>
          <legend id='hTYWZ'><style id='hTYWZ'><dir id='hTYWZ'><q id='hTYWZ'></q></dir></style></legend>

        • <small id='hTYWZ'></small><noframes id='hTYWZ'>

            <tfoot id='hTYWZ'></tfoot>
              <tbody id='hTYWZ'></tbody>
                <bdo id='hTYWZ'></bdo><ul id='hTYWZ'></ul>

                  本文介绍了生成带有三角形条带的平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  生成顶点列表以使用三角形条绘制平面的最佳算法是什么?

                  What would be the best algorithm to generate a list of vertices to draw a plane using triangle strips?

                  我正在寻找一个函数,它接收平面的宽度和高度并返回一个包含正确索引顶点的浮点数组.

                  I'm looking for a function which receives the plane's width and height and returns a float array containing correctly indexed vertices.

                  width 表示每行的顶点数.

                  width represents the number of vertices per row.

                  高度表示每列的顶点数.

                  height represents the number of vertices per column.

                  float* getVertices( int width, int height ) {
                      ...
                  }
                  
                  void render() {
                      glEnableClientState(GL_VERTEX_ARRAY);
                      glVertexPointer(3, GL_FLOAT, 0, getVertices(width,heigth));
                      glDrawArrays(GL_TRIANGLE_STRIP, 0, width*height);
                      glDisableClientState(GL_VERTEX_ARRAY);
                  }
                  

                  推荐答案

                  谢谢大家.我已经编码了这个.这是正确的吗?还是生成的条带有问题?

                  Thanks you all. I've coded this. Is it correct? Or is the generated strip somehow wrong?

                  int width;
                  int height;
                  float* vertices = 0;
                  int* indices = 0;
                  
                  int getVerticesCount( int width, int height ) {
                      return width * height * 3;
                  }
                  
                  int getIndicesCount( int width, int height ) {
                      return (width*height) + (width-1)*(height-2);
                  }
                  
                  float* getVertices( int width, int height ) {
                      if ( vertices ) return vertices;
                  
                      vertices = new float[ getVerticesCount( width, height ) ];
                      int i = 0;
                  
                      for ( int row=0; row<height; row++ ) {
                          for ( int col=0; col<width; col++ ) {
                              vertices[i++] = (float) col;
                              vertices[i++] = 0.0f;
                              vertices[i++] = (float) row;
                          }
                      }
                  
                      return vertices;
                  }
                  
                  int* getIndices( int width, int height ) {
                      if ( indices ) return indices;
                  
                      indices = new int[ iSize ];
                      int i = 0;
                  
                      for ( int row=0; row<height-1; row++ ) {
                          if ( (row&1)==0 ) { // even rows
                              for ( int col=0; col<width; col++ ) {
                                  indices[i++] = col + row * width;
                                  indices[i++] = col + (row+1) * width;
                              }
                          } else { // odd rows
                              for ( int col=width-1; col>0; col-- ) {
                                  indices[i++] = col + (row+1) * width;
                                  indices[i++] = col - 1 + + row * width;
                              }
                          }
                      }
                      if ( (mHeight&1) && mHeight>2 ) {
                          mpIndices[i++] = (mHeight-1) * mWidth;
                      }
                  
                      return indices;
                  }
                  
                  void render() {
                      glEnableClientState( GL_VERTEX_ARRAY );
                      glVertexPointer( 3, GL_FLOAT, 0, getVertices(width,height) );
                      glDrawElements( GL_TRIANGLE_STRIP, getIndicesCount(width,height), GL_UNSIGNED_INT, getIndices(width,height) );
                      glDisableClientState( GL_VERTEX_ARRAY );
                  }
                  

                  width=4 和 height=4 这就是我得到的:

                  With width=4 and height=4 this is what I got:

                  这里我修改了一些顶点高度:

                  And here I'm modifying some vertex height:

                  这篇关于生成带有三角形条带的平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:glBindVertexArrays 与 glBindBuffer 的作用是什么,它们 下一篇:glPixelStorei(GL_UNPACK_ALIGNMENT, 1) 缺点?

                  相关文章

                  最新文章

                    <bdo id='CTUZC'></bdo><ul id='CTUZC'></ul>
                  <legend id='CTUZC'><style id='CTUZC'><dir id='CTUZC'><q id='CTUZC'></q></dir></style></legend>

                  <small id='CTUZC'></small><noframes id='CTUZC'>

                  <tfoot id='CTUZC'></tfoot>
                    <i id='CTUZC'><tr id='CTUZC'><dt id='CTUZC'><q id='CTUZC'><span id='CTUZC'><b id='CTUZC'><form id='CTUZC'><ins id='CTUZC'></ins><ul id='CTUZC'></ul><sub id='CTUZC'></sub></form><legend id='CTUZC'></legend><bdo id='CTUZC'><pre id='CTUZC'><center id='CTUZC'></center></pre></bdo></b><th id='CTUZC'></th></span></q></dt></tr></i><div id='CTUZC'><tfoot id='CTUZC'></tfoot><dl id='CTUZC'><fieldset id='CTUZC'></fieldset></dl></div>