//A.4 Marching-Square程序
/* generates contours using marching squares */
/* region size */
#define X_MAX 1.0
#define Y_MAX 1.0
#define X_MIN -1.0
#define Y_MIN -1.0
/* number of cells */
#define N_X 50
#define N_Y 50
/* contour value */
#define THRESHOLD 0.0
#include<gl/glut.h>
void display()
{
double f(double,double);
int cell(double,double,double,double);
void lines(int,int,int,double,double,double,double);
double data[N_X][N_Y];
int i,j;
int c;
glClear(GL_COLOR_BUFFER_BIT);
/* form data array from function */
for(i=0;i<N_X;i++)
for(j=0;j<N_Y;j++)
data[i][j]=f(X_MIN+i*(X_MAX-X_MIN) /(N_X-1.0),
Y_MIN+j*(Y_MAX-Y_MIN)/(N_Y-1.0));
/* process each cell */
for(i=0;i<N_X;i++)
for(j=0;j<N_Y;j++)
{
c=cell(data[i][j],data[i+1][j],data[i+1][j+1],data[i][j+1]);
lines(c,i,j,data[i][j],data[i+1][j],data[i+1][j+1],data[i][j+1])
[OpenGL]课后案例04:Marching-Square程序
最新推荐文章于 2024-06-12 09:57:27 发布
