OpenGL Flare Design

Source: Internet
Author: User

One

When writing the wind-blown banner effect, note that the previous point and the next point, such as the z-coordinate relationship, the next point of the z-coordinate is the z-coordinate of the previous point, in fact, by the transfer of the wave to calculate, z-coordinate can be any curve of the function to calculate, such as sin, cos, this is just the , it depends on the algorithm, but the dynamic implementation is the coordinate transfer.

If the flag is divided into 44 rows, 44 columns, only the z-coordinate transfer, not the test x and Y,

So, a total of 45 * 45 points, each point three coordinate values

const float PI = 3.1415;

const int row = 44; //number of rows to be divided

const int column = 44; //number of columns to be divided

Const FLOAT length = 9; //The length of the banner

Const DISX = length/(float) column;

Const DISY = length/(float) row;

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

//row-by-row calculation of coordinate values

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; //To ensure that the banner is in the middle

Coord[i][j][1] = y;

Coord[i][j][2] = sin ((float) j/(FLOAT) colum * 2.0 * PI);

Note that the two numbers are integers when you divide.

}

}

Passing Z-coordinates

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

float hold = coord[i][0][2]; //Save the z-coordinate of the first point, and the last point to use

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

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

}

COORD[I][COLUMN-1] = hold;

}

This is the simplest calculation, the z coordinate of each column is the same, repeat the z coordinate of the last point and the first point z coordinate, you can also calculate the z coordinate of the column point according to a certain curve equation, then pass it to the next point, and the x and Z coordinates may also change, here is the simplest form.


Two

To enable the z-axis to move vertically and to move horizontally, two arrays are required to hold the z-coordinate values in both horizontal and vertical directions. Then the z coordinate is the composition of these two coordinate values:

const int row = 45;

const int column = 45;

const float Width= 9.0f;

Const float height = 9.0f;

float coord[row][column][3]; //Flag coordinates

float Hzcoord[row][column]; //flag z-coordinate horizontal component

float Vzcoord[column][row]; //Flag z-coordinate vertical component

//Calculate the horizontal component of the z-coordinate

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

}

}

//Calculate the vertical component of the z-coordinate

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;

//calculate coordinates for each point

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

}

}

The coordinates of each point are initialized, and the z-coordinate is passed at each frame of the dynamic:

//The transfer of horizontal coordinate components

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;

}

Transfer of//vertical coordinate components

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;

}

//coordinates of each point to be computed at each frame

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

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

//x and Y coordinates we don't have to change, because only the z-coordinate changes are considered.

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

}

}

650) this.width=650; "src=" http://www.cppblog.com/images/cppblog_com/biao/flag.png "vspace=" 0 "hspace=" 0 "longdesc= "Http://www.cppblog.com/biao/archive/2010/12/17/136764.html" style= "Font-family:verdana, Geneva, Arial, Helvetica, Sans-serif;font-size:13px;line-height:16.9px;white-space:normal;background-color:rgb (255,255,255); "/>


OpenGL Flare Design

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.