4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Fluid Dynamics for lower editions
[Re: the_mehmaster]
#276780
07/06/09 11:44
07/06/09 11:44
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Heres a largely fixed version of your code, it turns out that the BIG reason that every second vertex was zero was purely because there was no wait between the first vertex-loop and the second. All other changes Ive made were mostly part of my fault hunting process and can probably be reversed. Im going to try and do a more "self-contained" and flexible version of this tonight, but there wont be much of your code left in it Im afraid, cause I will start from scratch, based on the webpage you sent me, rather than any of your code. I'll post it here if I have any luck. And if my version gets posted in contributions, I'll credit you.
#include <acknex.h>
#include <default.c>
var dest[20][20];
var source[20][20];
ENTITY* waterent;
PANEL* skeletonpan =
{
pos_x = 0; pos_y = 0;
digits( 0, 0, "nexus: %f", "Arial#18b", 1, nexus);
digits( 0, 20, "tempv: %f", "Arial#18b", 1, tempv);
flags = VISIBLE;
}
action fluid_action()
{
CONTACT* c;
var tempv, iloop, eloop;
//
// Initialise arrays
for(iloop=0; iloop<20; iloop++)
{
for(eloop=0; eloop<20; eloop++)
{
dest[iloop][eloop] = 0;
source[iloop][eloop] = 0;
}
}
//
//
while(1)
{
for(iloop=1; iloop<19; iloop++)
{
for(eloop=1; eloop<19; eloop++)
{
//perform simulation
dest[iloop][eloop] = (source[iloop-1][eloop]+source[iloop+1][eloop]+source[iloop][eloop-1]+source[iloop][eloop+1])/2-dest[iloop][eloop];
dest[iloop][eloop] *= 0.95;
vec_to_mesh(vector(0,0,dest[iloop][eloop]), my, iloop*20+eloop+1);
//debugging
tempv = source[iloop+1][eloop+1];
}
}
wait(1);
for(iloop=1; iloop<19; iloop++)
{
for(eloop=1; eloop<19; eloop++)
{
//perform simulation
source[iloop][eloop] = (dest[iloop-1][eloop]+dest[iloop+1][eloop]+dest[iloop][eloop-1]+dest[iloop][eloop+1])/2-source[iloop][eloop];
source[iloop][eloop] *= 0.95;
vec_to_mesh (vector(0,0,source[iloop][eloop]), my, iloop*20+eloop+1);
//debugging
//tempv = source[iloop+1][eloop+1];
}
}
wait(1);
}
}
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)
{
source[10][10]+=10;
while(key_cuu) wait(1);
}
wait(1);
}
}
[Off-topic]Im in Wallsend, Newcastle, NSW myself, on the far side of Sydney from you. So Im not really too far away, Im at work here, but I live in Morisset, a half-hour south.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Fluid Dynamics for lower editions
[Re: EvilSOB]
#276820
07/06/09 16:22
07/06/09 16:22
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
I don't think the thing's framerate independent.
The loops are executed every frame (while(1){...wait(1);}) and thus the wave reaches is end very fast. If a computer runs at 10fps it will cover 10 vertecies a second, if it runs at 60, the wave will make a speed of 60 vertecies a second.
The problem is, I don't see how to change that easily. The best way would, I think, be a sin() function that depends on time AND distance to the initial force on the water. Btw, I think this is a very cool idea and I'd like to see it evolve more, but could you make it look coler? like make it blue and then maybe add a light so the movement is easier to see...? As I think you want this for the extra version (did I understand that right?) I'm not recommending using shaders, otherwise I would.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Fluid Dynamics for lower editions
[Re: VeT]
#276926
07/07/09 06:59
07/07/09 06:59
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
#include <acknex.h>
#include <default.c>
var dest[20][20];
var source[20][20];
ENTITY* waterent;
PANEL* skeletonpan =
{
pos_x = 0; pos_y = 0;
digits( 0, 0, "nexus: %f", "Arial#18b", 1, nexus);
digits( 0, 20, "tempv: %f", "Arial#18b", 1, tempv);
flags = VISIBLE;
}
action fluid_action()
{
CONTACT* c;
var tempv, iloop, eloop;
//
// Initialise arrays
for(iloop=0; iloop<20; iloop++)
{
for(eloop=0; eloop<20; eloop++)
{
dest[iloop][eloop] = 0;
source[iloop][eloop] = 0;
}
}
//
//
while(1)
{
for(iloop=1; iloop<19; iloop++)
{
for(eloop=1; eloop<19; eloop++)
{
//perform simulation
dest[iloop][eloop] = (source[iloop-1][eloop]+source[iloop+1][eloop]+source[iloop][eloop-1]+source[iloop][eloop+1])*(time_step*0.8)-dest[iloop][eloop];
dest[iloop][eloop] *= 1*(1.1-time_step*1.1);
vec_to_mesh(vector(0,0,dest[iloop][eloop]), my, iloop*20+eloop+1);
//debugging
tempv = source[iloop+1][eloop+1];
}
}
wait(1);
for(iloop=1; iloop<19; iloop++)
{
for(eloop=1; eloop<19; eloop++)
{
//perform simulation
source[iloop][eloop] = (dest[iloop-1][eloop]+dest[iloop+1][eloop]+dest[iloop][eloop-1]+dest[iloop][eloop+1])*(time_step*0.8)-source[iloop][eloop];
source[iloop][eloop] *= 1*(1.1-time_step*1.1);
vec_to_mesh (vector(0,0,source[iloop][eloop]), my, iloop*20+eloop+1);
//debugging
//tempv = source[iloop+1][eloop+1];
}
}
wait(1);
}
}
function main()
{
video_mode = 10;
video_screen = 1;
fps_max = 100;
fps_min = 25;
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)
{
source[10][10]+=20;
while(key_cuu) wait(1);
}
wait(1);
}
}
It is now frame-rate independent. But I think i'll stop working on my code and wait for yours, because that will be neater... EDIT: changed some values to make it work better.
Last edited by the_mehmaster; 07/07/09 07:27.
|
|
|
Re: Fluid Dynamics for lower editions
[Re: VeT]
#276965
07/07/09 09:31
07/07/09 09:31
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
OP
User
Joined: Dec 2008
Posts: 528
Wagga, Australia
|
for now you can't, it is defined as plane.. i'll see what i can do It's allright, not necessary. At the moment what i am doing is modifying your buoyancy demo by putting a passable .hmp on top of the existing plane. The positions of the rigid bodies are read into predefined variables. It works. But if you did support .hmp, that would help, especially when evilSOB rolls out the new code. @evilSOB: If you want to make this work with .mdl as well you'll have to have a vec_for_mesh instruction as well as the existing vec_to_mesh, because otherwise the .mdl's vertices will be always at the same x and y coordinates. I can give an example if you want. Are you using the new 'ent_setmesh' and 'ent_getmesh' instructions instead of the old ones? just for compatibility.. Can't wait for this to be finished! should be really cool.
|
|
|
|