Original Post
Erm, where is it? The link seems to have dissappeared off the GD front page? (Or am I just being blind?)
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
float coo[128][128][3];
float vel[128][128];
int q[127][127][4];
void init()
{
int i,j;
for(i=0;i<128;i++)
for(j=0;j<128;j++)
{
coo[i][j][0]=(i-64.0f)/64.0f;
coo[i][j][1]=(j-64.0f)/64.0f;
vel[i][j]=coo[i][j][2]=0.0f;
}
for(i=0;i<127;i++)
for(j=0;j<127;j++)
{
q[i][j][0]=i*128+j;
q[i][j][1]=i*128+j+1;
q[i][j][2]=i*128+j;
q[i][j][3]=i*128+j+128;
}
};
void step()
{
int i,j;
for(i=1;i<127;i++)
for(j=1;j<127;j++)
{
vel[i][j]+=coo[i][j][2]-
(coo[i+1][j][2]+
coo[i-1][j][2]+
coo[i][j+1][2]+
coo[i][j-1][2])*0.25f;
}
for(i=1;i<127;i++)
for(j=1;j<127;j++)
{
coo[i][j][2]-=vel[i][j];
coo[i][j][2]*=0.99f;
}
for(i=0;i<128;i++)
{
coo[i][0][2]=0;
coo[i][127][2]=0;
coo[0][i][2]=0;
coo[127][i][2]=0;
}
}
float a,b,c;
void blup(int x, int y)
{
for(int x1=-10;x1<11;x1++)
for(int y1=-10;y1<11;y1++)
{
float v=100.0f-x1*x1-y1*y1;
if(v<0.0f)v=0.0f;
coo[(x+x1)&127][(y+y1)&127][2]+=v*0.004f;
}
}
void redraw()
{
static char counter;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef (0.0f, 0.0f, -2.0f);
glRotatef(-70,1,0,0);
//glRotatef(10,0,1,0);
glRotatef(c+=0.1f,0,0,1);
if(counter++==0)
blup(rand(),rand());
step();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,&coo[0][0][0]);
glDrawElements(GL_LINES, 127*127*4, GL_UNSIGNED_INT, &q[0][0][0]);
glutSwapBuffers();
}
float w,h;
void motion(int x, int y)
{
a=300.0f*x/w;
b=300.0f*y/h;
}
void reshape(int width, int height)
{
w=width;
h=height;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0f,(width+0.1f)/(height+0.1f),0.1f,10.0f);
glMatrixMode (GL_MODELVIEW);
glViewport (0, 0, width, height);
}
int main(int argc, char *argv[])
{
int i;
init();
glutInit(&argc, argv);
glutInitWindowSize(800,600);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutCreateWindow("Peter Popov GLUT");
glutIdleFunc(redraw);
glutDisplayFunc(redraw);
glutMotionFunc(motion);
glutReshapeFunc(reshape);
glutShowWindow();
glClearColor(1.0f,0.5f,0.2f,0.0f);
glutMainLoop();
return 0;
}
quote:
Original post by IronPeter
Is it really NS equation? It seems like the numerical solution of the Newton equation:
d^2 h / dt^2 = "laplas" h.
NS equation looks as:
1.) [d/dt+ v*grad] v = F - grad p
2.) div v = 0.
quote:
I guess I see the solution as drawing to another texture. But Im thinking that there has to be a better way then another pass (maybe Im just too optimistic).
quote:
Is it really NS equation? It seems like the numerical solution of the Newton equation:

quote:
I wasn''t there when you were having the lecture because it was midnight where I live, when you started it...
quote:
Thanks for any info! Excellent lecture, please do another one real soon!
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more