• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            逛奔的蝸牛

            我不聰明,但我會(huì)很努力

               ::  :: 新隨筆 ::  ::  :: 管理 ::
            一、
            在寫風(fēng)吹旗幟效果的時(shí)候,注意的是上一個(gè)點(diǎn)與下一個(gè)點(diǎn)的如Z坐標(biāo)的關(guān)系,下一個(gè)點(diǎn)的Z坐標(biāo)是上一個(gè)點(diǎn)的此時(shí)的Z坐標(biāo),其實(shí)就是按波的傳遞性來(lái)計(jì)算,Z坐標(biāo)可以按任何曲線的函數(shù)來(lái)計(jì)算,如sin, cos,這只是最基本的思想,要做得真實(shí),就看算法的了,但動(dòng)態(tài)實(shí)現(xiàn)就是用坐標(biāo)傳遞。
             
            如把旗幟分成44行,44列,只計(jì)算Z坐標(biāo)的傳遞,不考試X與Y,
            那么,一共有45 * 45個(gè)點(diǎn),每個(gè)點(diǎn)三個(gè)坐標(biāo)值
             
                    const float PI = 3.1415;
                    const int row = 44;    //要分成的行數(shù)
                    const int column = 44;   // 要分成的列數(shù)
                    const float length = 9;  //旗幟的長(zhǎng)度
                    const disx = length / (float)column;
                    const disy = length / (float)row;
                    float coord[row][column][3];
             
                    // 按行逐行計(jì)算坐標(biāo)值
                    for (int i=0; i < row; i++) {
                            float y = i * disy - length / 2.0;
                            for (int j=0; j < column; j++) {
                                    coord[i][j][0] = j * disx - length / 2.0; //是為了保證旗幟處于正中間
                                    coord[i][j][1] = y;
                                    coord[i][j][2] = sin((float)j / (float)colum * 2.0 * PI);
                                    // 注意除法時(shí)要不要把兩個(gè)數(shù)都是整數(shù)
                            }
                    }
             
            傳遞Z坐標(biāo)
                    for (int i=0; i < row; i++) {
                            float hold = coord[i][0][2]; //保存第一個(gè)點(diǎn)的Z坐標(biāo),最后一個(gè)點(diǎn)要使用
                            for (int j=0; j < column-1; j++) {
                                    coord[i][j][2] = coord[i][j+1][2];
                            }
                            coord[i][column-1] = hold;
                    }
             
            這是最簡(jiǎn)單的計(jì)算,每一列的Z坐標(biāo)都相同,重復(fù)了最后一個(gè)點(diǎn)的Z坐標(biāo)與第一個(gè)點(diǎn)的Z坐標(biāo),還可以把列點(diǎn)的Z坐標(biāo)按照一定的曲線方程來(lái)計(jì)算,然后把它傳遞給下一個(gè)點(diǎn),還有X與Z坐標(biāo)也有可能會(huì)變化,這里都是最簡(jiǎn)單的形式。

            二、
            為了能使Z軸即能在垂直方向運(yùn)動(dòng),又能在水平方向運(yùn)動(dòng),則需要兩個(gè)數(shù)組來(lái)保存水平方向和垂直方向的Z坐標(biāo)值。然后Z坐標(biāo)為這兩個(gè)坐標(biāo)值的合成:
                    const int row = 45;
                    const int column = 45;
                    const float width= 9.0f;
                    const float height = 9.0f;
             
                    float coord[row][column][3];  // Flag的坐標(biāo)
                    float hzcoord[row][column];   // Flag的Z坐標(biāo)水平分量
                    float vzcoord[column][row];   // Flag的Z坐標(biāo)垂直分量
             
                   
                    //計(jì)算Z坐標(biāo)的水平分量
                    for (int i = 0; i < row; i++) {
                            for (int j = 0; j < column; j++) {
                                    hzcoord[i][j] = sin((float)j / (float)column * 360 * 3.1415 / 180);
                            }
                    }
             
                    //計(jì)算Z坐標(biāo)的垂直分量
                    for (int i = 0; i < column; i++) {
                            for (int j = 0; j < row; j++) {
                                    vzcoord[i][j] = sin((float)j / (float)column * 360 * 3.1415 / 180);
                            }
                    }
             
                     float disx = width / column;
                     float disy = height /row;
                    //計(jì)算每個(gè)點(diǎn)的坐標(biāo)
                    for (int i = 0; i < row; i++) {
                            for (int j = 0; j < column; j++) {
                                    coord[i][j][0] = j * disx - width / 2.0;
                                    coord[i][j][1] = i * disy - height / 2.0;
                                    coord[i][j][2] = hzcoord[i][j] + vzoord[j][i];
                            }
                    }
             
            上面已經(jīng)完成初始化每個(gè)點(diǎn)的坐標(biāo),下面就到了動(dòng)態(tài)的每一幀時(shí)Z坐標(biāo)的傳遞了:
             
                    //水平坐標(biāo)分量的傳遞
                    for (int i = 0; i < row; i++) {
                            float hold = hzcoord[i][0];
                            for (int j = 0; j < column - 1; j++) {
                                    hzcoord[i][j] = hzcoord[i][j+1];
                            }
                            hzcoord[i][column-1] = hold;
                    }
             
                    //垂直坐標(biāo)分量的傳遞
                    for (int i = 0; i < column; i++) {
                            float hold = vzcoord[i][0];
                            for (int j = 0; j < row - 1; j++) {
                                    vzcoord[i][j] = vzcoord[i][j+1];
                            }
                            vzcoord[i][row-1] = hold;
                    }
                   
                    //每一幀時(shí)要計(jì)算的每個(gè)點(diǎn)的坐標(biāo)
                    for (int i = 0; i < row; i++) {
                            for (int j = 0; j < column; j++) {
                                    //X與Y坐標(biāo)我們不用去變換,因?yàn)橹豢紤]了Z坐標(biāo)的變化
                                    //coord[i][j][0] = j * disx - width / 2.0;
                                    //coord[i][j][1] = i * disy - height / 2.0;
                                    coord[i][j][2] = hzcoord[i][j] + vzoord[j][i];
                            }
                    }
            posted on 2010-12-17 17:45 逛奔的蝸牛 閱讀(1116) 評(píng)論(0)  編輯 收藏 引用 所屬分類: OpenGL
            久久久精品人妻一区二区三区四| 久久国产热这里只有精品| 久久这里只精品99re66| 伊人久久大香线蕉AV一区二区 | 精品久久久久久综合日本| 狠色狠色狠狠色综合久久| 久久精品国产亚洲AV不卡| 色婷婷综合久久久久中文字幕| 亚洲综合熟女久久久30p| 青青草国产精品久久久久| 久久久黄色大片| 国产精品久久久久aaaa| 亚洲人成无码www久久久| 精品国际久久久久999波多野| 色综合色天天久久婷婷基地| 亚洲а∨天堂久久精品| 国内精品久久久久久野外| 久久青青色综合| 国产精品伦理久久久久久| 亚洲国产精品无码久久久秋霞2 | 久久久久久久精品成人热色戒| 久久午夜无码鲁丝片| 久久亚洲精品无码观看不卡| 久久久久久久人妻无码中文字幕爆| 久久久久免费视频| 国产精品一久久香蕉产线看 | 99re久久精品国产首页2020| 亚洲午夜精品久久久久久浪潮| 亚洲综合精品香蕉久久网97| 男女久久久国产一区二区三区| 狠狠色丁香久久婷婷综合蜜芽五月| 一级做a爰片久久毛片16| 青青草原精品99久久精品66| 伊人久久大香线蕉精品不卡| 久久精品中文字幕有码| 999久久久免费精品国产| 97精品久久天干天天天按摩| 久久99精品久久久久久hb无码 | 97久久精品无码一区二区| 国产午夜免费高清久久影院| 日本人妻丰满熟妇久久久久久|