• 题目:三维随机分形地形生成(续十一)
  • 作者:佚名
  • 发表日期:十月 02, 2007
  • 浏览:108次
  • 收藏本文
  • 编者导读:4、地形排列的边界拼接算法 z = -1.f * (float) (tile-1); for (i=0; i<tile; i++) {     x = -1.f * (float) (tile-1);     for (j=0; j<tile; j++) {         glPushMatrix ();         glTranslatef (x, 0.f, z);         draw2DFractArra
  • 4、地形排列的边界拼接算法
    z = -1.f * (float) (tile-1);
    for (i=0; i<tile; i++) {
        x = -1.f * (float) (tile-1);
        for (j=0; j<tile; j++) {
            glPushMatrix ();
            glTranslatef (x, 0.f, z);
            draw2DFractArrayAsLines (surfFA, size);
            glPopMatrix ();
            x += 2.f;
        }
        z += 2.f;
    }

    5、地形绘制
    bool RenderScene()
    {
        int size = 1 << iterations;
     GLfloat black[4] = {0.f, 0.f, 0.f, 1.f};
     GLfloat white[4] = {1.f, 1.f, 1.f, 1.f};

     // Handle inverted colors.
     if (colorInvert)
         glClearColor (black[0], black[1], black[2], black[3]);
     else
         glClearColor (white[0], white[1], white[2], white[3]);

     // Handle non line mode renderMode settings.
     if (renderMode == twoDR_clouds)
      return (renderCloudMap ());
     else if (renderMode == twoDR_teximage)
      return (renderTeximageMap ());
     else if (renderMode == twoDR_rendered)
      return (renderFullImage ());

     // Shouldn''''''''''''''''''''''''''''''''t take too long, unless drawing huge
     // AA scenes, but what the heck...
     CWaitCursor hourglass;

     glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
     if (arrayIs2D)
      // Needs to be identical to the same call in renderFullScene.
         gluPerspective (60., aspectRatio, .1, 15.0);
     else
      glOrtho (-aspectRatio, aspectRatio, -1., 1., 1., -1.);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity ();
     if (arrayIs2D) {
         glTranslatef (0.f, yTrans, zTrans);
      glRotatef (yRot, 0.f, 1.f, 0.f);
     }

     glPushAttrib (0xffffffff);

     glDisable (GL_DEPTH_TEST);
     glDisable (GL_LIGHTING);
     if (colorInvert)
      glColor4fv (white);
     else
      glColor4fv (black);

     if (aaLines) {
      glEnable (GL_LINE_SMOOTH);
      glEnable (GL_BLEND);
      glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     }
     else {
      glDisable (GL_LINE_SMOOTH);
      glDisable (GL_BLEND);
     }
        
     glClear (GL_COLOR_BUFFER_BIT |
      GL_DEPTH_BUFFER_BIT);

     if (arrayIs2D) {
      float x, z;
      UINT i, j;

      // validate surface
      if (surfFA && surfFAdirty) {
       freeFractArray (surfFA);
       surfFA = NULL;
      }
      if (!surfFA) {
       surfFA = alloc2DFractArray (size);
       if (surfFA==NULL) return (FALSE);
       fill2DFractArray (surfFA, size, randomSeed,
        DEF_HEIGHT_SCALE, surfaceH);
       surfFAdirty = FALSE;
      }

      z = -1.f * (float) (tile-1);
      for (i=0; i<tile; i++) {
       x = -1.f * (float) (tile-1);
       for (j=0; j<tile; j++) {
        glPushMatrix ();
        glTranslatef (x, 0.f, z);

        draw2DFractArrayAsLines (surfFA, size);

        glPopMatrix ();
        x += 2.f;
       }
       z += 2.f;
      }
     }
     else {
      float x;
      UINT i;
         float *fa;

      // Always validate and free 1D array.
      // We won''''''''''''''''''''''''''''''''t be doing any realtime transformations on it.
      fa = alloc1DFractArray (size);
      if (fa==NULL) return (FALSE);
      fill1DFractArray (fa, size, randomSeed,
       DEF_HEIGHT_SCALE, surfaceH);

      x = -1.f * (float) (tile-1);
      for (i=0; i<tile; i++) {

       glPushMatrix ();
       glTranslatef (x, 0.f, 0.f);

       draw1DFractArrayAsLines (fa, size);

       glPopMatrix ();
       x += 2.f;
      }

      freeFractArray (fa);
     }

     glFlush();
     glPopAttrib ();
     
     return (TRUE);
    }

  • 前一篇:题目:三维随机分形地形生成(续十...下一篇:题目:三维随机分形地形生成(续九...
  • 【引用地址】http://www.suanshu.net/list/5047.aspx
  • 【关键字】题目:三维随机分形地形生成(续十一)
版权申明:非特殊申明,本站文章均系转载自互联网,如果侵犯了你的合法权益,请告知我们,我们会第一时间处理. 要点评这篇文章,请在下面留言
针对这篇文章的评论
  • 评论载入中
    评论载入中...请稍后...

发表您的评论您的评论

用户名: 验证码: 说明:评论并不需要注册.如果您不是本站会员,你可以注册为本站会员. 注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
  • 不良评论请用报告管理员,以利管理员及时删除。
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规。
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任。
  • 本站评论管理人员有权保留或删除其管辖评论中的任意内容。
  • 您在本站发表的作品,本站有权在网站内转载或引用。
  • 参与本评论即表明您已经阅读并接受上述条款。
  • 赞助商链接