资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

opengl飘动设计-创新互联

一、

创新互联公司2013年成立,先为汕头等服务建站,汕头等地企业,进行企业商务咨询服务。为汕头企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

在写风吹旗帜效果的时候,注意的是上一个点与下一个点的如Z坐标的关系,下一个点的Z坐标是上一个点的此时的Z坐标,其实就是按波的传递性来计算,Z坐标可以按任何曲线的函数来计算,如sin, cos,这只是最基本的思想,要做得真实,就看算法的了,但动态实现就是用坐标传递。

如把旗帜分成44行,44列,只计算Z坐标的传递,不考试X与Y,

那么,一共有45 * 45个点,每个点三个坐标值

       const float PI = 3.1415;

       const int row = 44;    //要分成的行数

       const int column = 44;   // 要分成的列数

       const float length = 9;  //旗帜的长度

       const disx = length / (float)column;

       const disy = length / (float)row;

       float coord[row][column][3];

        // 按行逐行计算坐标值

       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);

                       // 注意除法时要不要把两个数都是整数

                }

       }

传递Z坐标

       for (int i=0; i < row; i++) {

               float hold = coord[i][0][2]; //保存第一个点的Z坐标,最后一个点要使用

               for (int j=0; j < column-1; j++) {

                        coord[i][j][2] = coord[i][j+1][2];

                }

                coord[i][column-1] = hold;

       }

这是最简单的计算,每一列的Z坐标都相同,重复了最后一个点的Z坐标与第一个点的Z坐标,还可以把列点的Z坐标按照一定的曲线方程来计算,然后把它传递给下一个点,还有X与Z坐标也有可能会变化,这里都是最简单的形式。

二、

为了能使Z轴即能在垂直方向运动,又能在水平方向运动,则需要两个数组来保存水平方向和垂直方向的Z坐标值。然后Z坐标为这两个坐标值的合成:

       const int row = 45;

       const int column = 45;

       const float width= 9.0f;

       const float height = 9.0f;

       float coord[row][column][3];  // Flag的坐标

       float hzcoord[row][column];   // Flag的Z坐标水平分量

       float vzcoord[column][row];   // Flag的Z坐标垂直分量

        //计算Z坐标的水平分量

       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);

               }

       }

        //计算Z坐标的垂直分量

       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;

        //计算每个点的坐标

       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];

               }

       }

上面已经完成初始化每个点的坐标,下面就到了动态的每一帧时Z坐标的传递了:

        //水平坐标分量的传递

       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;

       }

        //垂直坐标分量的传递

       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;

       }

        //每一帧时要计算的每个点的坐标

       for (int i = 0; i < row; i++) {

               for (int j = 0; j < column; j++) {

                        //X与Y坐标我们不用去变换,因为只考虑了Z坐标的变化

                       //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];

               }

       }

opengl  飘动设计

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:opengl飘动设计-创新互联
转载来于:http://cdkjz.cn/article/cdjgpd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220