3 registered members (AndrewAMD, Quad, M_D),
1,217
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Fluid Dynamics for lower editions
[Re: VeT]
#276989
07/07/09 10:32
07/07/09 10:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Im still working on this, Ive gotten the code to go VERY short now. eg.
var Data[2][20][20];
action fluid_action()
{ var x, y, i=0;
for(y=0; y<20; y++) for(x=0; x<20; x++) Data[0][x][y] = Data[1][x][y] = 0;
while(me)
{
for(y=1; y<19; y++) for(x=1; x<19; x++)
{
Data[i][x][y] = (Data[!i][x-1][y] + Data[!i][x+1][y] + Data[!i][x][y-1] + Data[!i][x][y+1]) / 2 - Data[i][x][y];
Data[i][x][y] *= 0.95;
vec_to_mesh(vector(0,0,Data[i][x][y]), my, (y*20)+x+1);
}
i = !i;
wait(1);
}
}
//
But Im currently having some difficulties trying to use malloc to define a three dimensional array, in order for it to cope with different size HMP's.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Fluid Dynamics for lower editions
[Re: EvilSOB]
#277077
07/07/09 16:47
07/07/09 16:47
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Gaaah! So close and yet so so far.... Ive streamlined the code, and it now includes MY version of accounting for FPS. I couldnt get yours to work "the same" under different FPS rates. [EDIT] I dont think this FPS-matching is correct. Ive got another idea in mind but I wont get to it till tonight... But my TWO remaining issues are these. 1> Craps out if terrain is larger than 32x32. Is there some odd limitation on terrains? (The vec_to_mesh seems to refuse to go higher than 1024 vertices.) Issue fixed by using CONTACT structure. 2> I cannot sucessfully store a pointer to data-array[0] into the entities skill1. Please check my code on this. Its not something Im familiar with.... Thanks guys....
#include <acknex.h>
#include <default.c>
#define vertex_arrays skill1 //vertex data arrays (var*)
#define vertex_count skill2 //number of vertices per array
#define vertex_wide skill3 //width of HMP in vertices
#define vertex_high skill4 //height of HMP in vertices
#define viscosity skill5 //"thickness" of the fluid. 0=Water -> 100=EngineOil
action fluid_action()
{
if(!ent_status(my,2)||!ent_status(my,3)) return; //not a terrain entity.
var size_x=ent_status(my,2)+1, size_y=ent_status(my,3)+1;
var x, y, f, tmp, ***data = malloc(sizeof(var)*2);
for(f=0; f<2; f++)
{ data[f] = malloc(sizeof(var)*size_x);
for(x=0; x<size_x; x++)
{ (data[f])[x] = malloc(sizeof(var)*size_y);
for(y=0; y<size_y; y++)
((data[f])[x])[y] = 0;
}
}
my.vertex_arrays = (void*)(data[0])[0];
my.vertex_count = ent_status(my, 0);
my.vertex_wide = size_x;
my.vertex_high = size_y;
my.viscosity = 0;
while(me)
{
f = !f;
for(y=1; y<(size_y-1); y++) for(x=1; x<(size_x-1); x++)
{
tmp = ((data[!f])[x-1])[y] + ((data[!f])[x+1])[y] + ((data[!f])[x])[y-1] + ((data[!f])[x])[y+1];
((data[f])[x])[y] = (tmp / 2 - ((data[f])[x])[y]) * 0.95;
CONTACT* c = ent_getvertex(my,NULL,(y*size_x)+x+1);
c.v.y = ((data[f])[x])[y];
ent_setvertex(my,c,(y*size_x)+x+1);
}
if(key_1) ((data[0])[2])[size_y/2] += 5; //TEST POKE - debug only
wait(-(25+my.viscosity)/1000);
}
//cleanup
for(x=0; x<size_x; x++) { free((data[0])[x]); free((data[1])[x]); }
free(data[0]); free(data[1]); free(data);
}
ENTITY* waterent;
function main()
{
video_mode = 10;
video_screen = 1;
level_load("");
vec_set(camera.x, vector(0,50,50));
vec_set(camera.pan, vector(270,-45,0));
//
waterent = ent_create("waterent32.hmp", nullvector, fluid_action);
//
while(1)
{
if(key_cuu)
{
beep();
((var*)waterent.vertex_arrays)[110] += 15;
while(key_cuu) wait(1);
}
wait(1);
}
//cleanup
for(x=0; x<size_x; x++) { free((data[0])[x]); free((data[1])[x]); }
free(data[0]); free(data[0]); free(data);
}
//
Last edited by EvilSOB; 07/07/09 21:15.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Fluid Dynamics for lower editions
[Re: EvilSOB]
#277119
07/07/09 21:07
07/07/09 21:07
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
In the manual it is recommended to have terrains smaller than 32x32. It is probably unneeded to support larger terrains. oh you fixed it. cool!
Pointer to skill? hmm.. I have no idea.
That code is a lot more compact than mine, which is a very good thing. My 14-year-old code is no where near your standard!
I get a compilation error in line 73. the variable 'x' is undeclared. When i get rid of the cleanup lines it compiles though..
When i press the up arrow, no ripples are anywhere. Or is this part of the problem?
Anyway, great job!
Last edited by the_mehmaster; 07/07/09 21:19.
|
|
|
Re: Fluid Dynamics for lower editions
[Re: the_mehmaster]
#277126
07/07/09 21:19
07/07/09 21:19
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Updated the code, now works with larger than 32*32.
Try testing my code "as is" before splicing it into yours. That would explain the error at cleanup.
Its still got a bit of testing to do, which I wont get to till after 7pm tonight. Its time for bed...
[EDIT] Damn, I gotta drive home from work first....
Last edited by EvilSOB; 07/07/09 21:20.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Fluid Dynamics for lower editions
[Re: the_mehmaster]
#277136
07/07/09 22:34
07/07/09 22:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Bad post... Sorry. But here is a repost, complete EXCEPT that the frame-rate dependance still needs tuning. But as I said before, I'll get to that tonight. I need to sleep, but thought of how to "control" the entitys fluid from outside while driving home. Eureka!...ohshit.ohshit...Swerve! With this edition, all you need to do is directly adjust one of the vertices, and the action will now see it and react accordingly. See the loop in main for how its done.
#include <acknex.h>
#include <default.c>
#define viscosity skill1 //"thickness" of the fluid. 0=Water -> 100=EngineOil
#define vertex_wide skill2 //width of HMP in vertices
#define vertex_high skill3 //height of HMP in vertices
action fluid_action()
{
if(!ent_status(my,2)||!ent_status(my,3)) return; //not a terrain entity.
var size_x=ent_status(my,2)+1, size_y=ent_status(my,3)+1;
var x, y, f, tmp, ***data = malloc(sizeof(var)*2);
for(f=0; f<2; f++)
{ data[f] = malloc(sizeof(var)*size_x);
for(x=0; x<size_x; x++)
{ (data[f])[x] = malloc(sizeof(var)*size_y);
for(y=0; y<size_y; y++)
((data[f])[x])[y] = 0;
}
}
my.viscosity = 0;
my.vertex_wide = size_x;
my.vertex_high = size_y;
while(me)
{
f = !f;
for(y=1; y<(size_y-1); y++) for(x=1; x<(size_x-1); x++)
{
CONTACT* c = ent_getvertex(my,NULL,(y*size_x)+x+1);
if((c.v.y!=((data[0])[x])[y])&&(c.v.y!=((data[1])[x])[y]))
((data[f])[x])[y] = c.v.y;
else
{
tmp = ((data[!f])[x-1])[y] + ((data[!f])[x+1])[y] + ((data[!f])[x])[y-1] + ((data[!f])[x])[y+1];
((data[f])[x])[y] = (tmp / 2 - ((data[f])[x])[y]) * 0.95;
c.v.y = ((data[f])[x])[y];
ent_setvertex(my,c,(y*size_x)+x+1);
}
}
wait(-(25+my.viscosity)/1000);
}
//cleanup
for(x=0; x<size_x; x++) { free((data[0])[x]); free((data[1])[x]); }
free(data[0]); free(data[1]); free(data);
}
ENTITY* waterent;
function main()
{
video_mode = 10;
video_screen = 1;
level_load("");
vec_set(camera.x, vector(0,50,50));
vec_set(camera.pan, vector(270,-45,0));
waterent = ent_create("waterent.hmp", nullvector, fluid_action);
while(1)
{
if(key_cuu)
{
CONTACT* c = ent_getvertex(waterent,NULL,210);
c.v.y += 5; //YES .y IS correct in D3D terms
ent_setvertex(waterent,c,210);
while(key_cuu) wait(1);
}
wait(1);
}
}
//
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Fluid Dynamics for lower editions
[Re: EvilSOB]
#277165
07/08/09 06:35
07/08/09 06:35
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
all you need to do is directly adjust one of the vertices, and the action will now see it and react accordingly Yes! no more predefined variables for every action! That's what i used to do with newton.. Great work! i'll try to get this working with newton now.
|
|
|
Re: Fluid Dynamics for lower editions
[Re: the_mehmaster]
#277166
07/08/09 06:41
07/08/09 06:41
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
Before i upload a demo, do you know of a fixed-function environment mapping shader? would make the demo look a heap cooler.. EDIT: couldn't find a working one in the wiki.. EDIT2: Just thought i'd submit this: FluidSimDemo1 What it is: This demo is the simplest. It is just a terrain applied with the fluid action. To interact with the fluid, hold down your left mouse button and drag it around the plane. This is the first (and simplest) demo in a series, which I made in about half an hour (shows how easy your code is to work with). I am almost finished the newton one which i will submit very soon.
Last edited by the_mehmaster; 07/08/09 08:02.
|
|
|
Re: Fluid Dynamics for lower editions
[Re: the_mehmaster]
#277188
07/08/09 08:53
07/08/09 08:53
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
I was going to post EDIT3, but that's a bit too far..
The FPS independancy works quite well already. What needs to be improved?
EDIT: It's very hard to resist the temptation of posting the demo in contributions..Gotta wait until all the demos are finished though.
Last edited by the_mehmaster; 07/08/09 09:01.
|
|
|
|