View unanswered posts | View active topics It is currently Mon May 06, 2024 3:44 pm



Reply to topic  [ 111 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
 Hydrodynamic Challenge! 
Author Message
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
well, taking a look at how normal particle movement is manipulated (eg TLB's gravity, the "water" zalo made, whatever else) we just use for statements, which are easy enough to move ♥♥♥♥ with. however, they do the calculation for all particles inside their working set, not individually. well, thats from what i can deduce, and the fact that
Code:
if Water2.PresetName == "Water Particle 2" and Water1.Pos ~= Water2.Pos then
doesnt work, even though the particles are obviously in different positions. i wasnt suggesting the for statement should be run separately, more that we needed a way of calculating the particles separately, not as a group. im thinking of using the Id of the MOID and a local count variable to try and deal with it, but that is going to be sloooow.

we all know miles' softbodies arent going to happen, but there's no reason why particle based water cant, other than us not knowing enough about how we should go about it.
so, rather than being a ♥♥♥♥, do you have any ideas daman? particle based water should be fine and doable, at least on a small scale, however i'm stuck because as you said, i dont know enough lua (or enough CC based functions and their arguments) to pull magical methods out of my ass.


Mon Mar 23, 2009 8:54 pm
Profile WWW

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post Re: Hydrodynamic Challenge!
I think Tim is stuck on the part where it distinguishes between particles correctly.
And since all Data did was bind some game functions to Lua, Tim doesn't have all
the access to the game that he needs.

In short, current Lua may not be good enough for water... yet.


Tue Mar 24, 2009 12:26 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
i know. his version also makes all the water explode to the left and up when it gets checked, due to the way co-ordinates are set up.
im stuck at the same bit, im trying different methods but it isnt getting anywhere. either all the water moves, or none of it does.


Tue Mar 24, 2009 1:34 am
Profile WWW
User avatar

Joined: Fri Apr 27, 2007 4:55 pm
Posts: 1178
Location: America!
Reply with quote
Post Re: Hydrodynamic Challenge!
I've got the stuff working, it is just a matter of getting it to work quickly. Without optimization at the C++ level, I don't see this happening any time soon.

The reason that the water explodes is because I was just testing that the particles actually did move. The actual force needed still has to be refined.

Currently, you can get about 100 particles before it lags beyond usability. Brute forcing the particle calculations would make this even worse.


Tue Mar 24, 2009 1:44 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
i can has code?
i'd like to have a look at how you did it.


Tue Mar 24, 2009 1:47 am
Profile WWW
User avatar

Joined: Mon Jun 04, 2007 5:55 am
Posts: 1627
Location: Ohio
Reply with quote
Post Re: Hydrodynamic Challenge!
kotsoft wrote:
by soft body are you thinking of simulating it as just the surface as in like a polygon, or more of a finite element like simulation with triangle meshes? in my previous post i probably misunderstood your idea of soft bodies, as i had been doing a lot of research simulating soft bodies and fluids just by the polygon without any internal springs.


Simulate the surface like a polygon (any number of sides) and all deformations are also more polygons, replacing whats 'behind' it or 'in it' depending on 2d or 3d.


and Daman, you just always try to ruin my fun. I just went on a tangent as 'physics could be done in this way'

I didn't however say "This exact thing will work in lua, DO IT" you are in no way witty, or fun, NOR are you important. Do not make half-page essays on why I am wrong, its creepy, like a stalker who claims to hate there target. stop it.


Tue Mar 24, 2009 3:31 am
Profile YIM WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
hey, sweet. got it working, now i just need to tweak the repulsion. :D and make it faster etc etc
put this at the end of your update activity function, after removing the last end.
Code:
for Water1 in MovableMan.Particles do
   if Water1.PresetName == "Water Particle" then
      for Water2 in MovableMan.Particles do
         if Water2.PresetName == "Water Particle" and DifCalc(Water1.Pos.X,Water2.Pos.X) < 10 and DifCalc(Water1.Pos.Y,Water2.Pos.Y) < 10 then
            if 0.1 < DifCalc(Water1.Pos.X,Water2.Pos.X) and 0.1 < DifCalc(Water1.Pos.Y,Water2.Pos.Y) then
               if Water1.Pos.X > Water2.Pos.X then
                  Water1.Vel.X = Water1.Vel.X + SpeedCalc(Water1.Pos.X,Water2.Pos.X)
                  Water2.Vel.X = Water2.Vel.X - SpeedCalc(Water1.Pos.X,Water2.Pos.X)
               else
                  Water1.Vel.X = Water1.Vel.X - SpeedCalc(Water1.Pos.X,Water2.Pos.X)
                  Water2.Vel.X = Water2.Vel.X + SpeedCalc(Water1.Pos.X,Water2.Pos.X)
               end
               if Water1.Pos.Y > Water2.Pos.Y then
                  Water1.Vel.Y = Water1.Vel.Y + SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
                  Water2.Vel.Y = Water2.Vel.Y - SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
               else
                  Water1.Vel.Y = Water1.Vel.Y - SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
                  Water2.Vel.Y = Water2.Vel.Y + SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
               end
            end
            if Water1.Vel.X > 50 then
               Water1.Vel.X = 50
            end
            if Water1.Vel.X < -50 then
               Water1.Vel.X = -50
            end
            if Water1.Vel.Y > 50 then
               Water1.Vel.Y = 50
            end
            if Water1.Vel.Y < -50 then
               Water1.Vel.Y = -50
            end
         end
      end
   end
end

end

function DifCalc(a,b)
   local diff = a - b;
   if diff < 0 then
      diff = diff * -1
   end
   return diff
end

function SpeedCalc(a,b)
   local diff = a - b;
   if diff < 0 then
      diff = diff * -1
   end
   local speed = math.abs((1/diff)*1)
   return speed
end

the speed limitations are there for testing purposes, because they were moving at obscene speeds. finding the values should be easy.
this starts lagging for me after about 50 particles though, so it needs a buttload of optimisation XD sorry for the messy coding, im pretty new to lua.


Tue Mar 24, 2009 4:11 am
Profile WWW

Joined: Fri Apr 06, 2007 10:11 pm
Posts: 45
Reply with quote
Post Re: Hydrodynamic Challenge!
I made a faster (from what I've seen) way using tables, but I have to work a bit on not getting th particles to settle, but that should be all I have to do. Wait... gotta work on th grouping a bit too.

The problem with the above method... you're going through the list of particles a lot.
For each water particle, you're testing it against every other water particle. You even test the particle against itself. The number of runs through that block is waterParticles^2, so even with only 5 particles, the block will be run through 25 times. At 5 more particles, you've quadruped the number of tests. So at 100 particles, you will run that block 10000 times! No wonder we can't work these things fast. Not to mention that you're still seeing if the particle is even a water particle, and in an actual game of CC, there will be many other particles around which will slow it down slightly.
Trust me, there is a better way to do it, I just won't tell or show you yet *glee*

I have no idea what my current guess is, but at least double the particles of the above method on my laptop.


Tue Mar 24, 2009 6:24 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
obviously it will, however i dont know how to use tables in lua so i'm doing it the angry way, that makes your computer cry. if i could figure out how to get timers doing what i want, i could make this work a lot better. until then, i'm working on a horrendously limited method :P
at least it helps me learn, i suppose.


Tue Mar 24, 2009 7:46 am
Profile WWW
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post Re: Hydrodynamic Challenge!
Adding everything to a table isn't going to make anything faster. The only reasoning I could see behind that is to time the calculations to happen at times other than constantly.

Actually, thinking about it, it could check for new particles against a table and add them to the table if they're new(and water), then the water processing can be ran on the table instead. That'd eliminate calling MovableMan.Particles as much, but you're still going through a table and comparing them all so I doubt it would see any performance increase.

Is that what you're intending to do?


Tue Mar 24, 2009 2:14 pm
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
it would eliminate comparing them to themselves, and also eliminate recomparison if you did it right, theoretically. so you would get less than half the calculations just from comparisons alone. if i could do my regulation each 10 frames rather than every frame, that would take a lot of the lag out of my method. im still trying to get all the particles into a table in a usable format though :-(
i'd love a look at your source camalaio, care to divulge anything?


Wed Mar 25, 2009 1:40 am
Profile WWW
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post Re: Hydrodynamic Challenge!
Geti wrote:
it would eliminate comparing them to themselves



Uh,

Code:
if water1 ~= water2 then
code
end


That already does that(eliminate comparing properties of the particle). That's not really the problem.

Quote:
and also eliminate recomparison if you did it right[/code]

Recomparison? You mean comparing things that haven't changed? That can already be done but you'd be retrieving more to check what's changed and make it slower overall.



Quote:
, theoretically


no


In the end you're going to need to compare every particle to every other particle to perform proper physics. You'll at least be checking every other particle to see if it's close enough to perform physics calculations. . .

Storing everything to a table would just have you compare it to a table to check for new values, which would still include a run for every particle through MovableMan.Particles, and then a run through the table to check for new particles. It'll still be going through two lists in that method. I really can't think of any other use for tables in this situation at the moment.

I'm anticipating seeing what you've done with some table method, or an explanation on what you believe you could use tables for to optimize it.


Wed Mar 25, 2009 5:45 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
yeah, good if we could just do neighbor calculations though, using coordinates or simmilar..
anyway, the functions you need to declare for my water:
Code:
function DifCalc(a,b)
   local diff = a - b;
   if diff < 0 then
      diff = diff * -1
   end
   return diff
end

function SpeedCalc(a,b)
   local diff = a - b;
   if diff < 0 then
      diff = diff * -1
   end
   local speed = ((1/diff)*1)
   return speed
end

function WaterCalc(a,b,c)
local limit = a
local overlaplimit = math.random(b)

for Water1 in MovableMan.Particles do
   if Water1.PresetName == "Water Particle" then
      for Water2 in MovableMan.Particles do
         if Water2.PresetName == "Water Particle" and DifCalc(Water1.Pos.X,Water2.Pos.X) < limit and DifCalc(Water1.Pos.Y,Water2.Pos.Y) < limit then
            -- part 1 - repulsion
            if 1 < DifCalc(Water1.Pos.X,Water2.Pos.X) and 1 < DifCalc(Water1.Pos.Y,Water2.Pos.Y) then
               if Water1.Pos.X > Water2.Pos.X then
                  Water1.Vel.X = Water1.Vel.X + SpeedCalc(Water1.Pos.X,Water2.Pos.X)
                  --Water2.Vel.X = Water2.Vel.X - SpeedCalc(Water1.Pos.X,Water2.Pos.X)
               else
                  Water1.Vel.X = Water1.Vel.X - SpeedCalc(Water1.Pos.X,Water2.Pos.X)
                  --Water2.Vel.X = Water2.Vel.X + SpeedCalc(Water1.Pos.X,Water2.Pos.X)
               end
               if Water1.Pos.Y > Water2.Pos.Y then
                  Water1.Vel.Y = Water1.Vel.Y + SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
                  --Water2.Vel.Y = Water2.Vel.Y - SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
               else
                  Water1.Vel.Y = Water1.Vel.Y - SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
                  --Water2.Vel.Y = Water2.Vel.Y + SpeedCalc(Water1.Pos.Y,Water2.Pos.Y)
               end
            end
            -- part 2 - overlap prevention
            if 1 > DifCalc(Water1.Pos.X,Water2.Pos.X) and 1 > DifCalc(Water1.Pos.Y,Water2.Pos.Y) then
               if Water1.Pos.X > Water2.Pos.X then
                  Water1.Vel.X = Water1.Vel.X + overlaplimit
                  Water2.Vel.X = Water2.Vel.X - overlaplimit
               else
                  Water1.Vel.X = Water1.Vel.X - overlaplimit
                  Water2.Vel.X = Water2.Vel.X + overlaplimit
               end
               if Water1.Pos.Y > Water2.Pos.Y then
                  Water1.Vel.Y = Water1.Vel.Y + overlaplimit
                  Water2.Vel.Y = Water2.Vel.Y - overlaplimit
               else
                  Water1.Vel.Y = Water1.Vel.Y - overlaplimit
                  Water2.Vel.Y = Water2.Vel.Y + overlaplimit
               end   
            end
         end
      end
   end
end
-- inserted as a function for ease
end

and the variables im using in Jimbobway:UpdateActivity()
Code:
WaterCalc(6,1.5)

it works well enough at 100% for 30 particles as is :P


Wed Mar 25, 2009 6:50 am
Profile WWW

Joined: Fri Apr 06, 2007 10:11 pm
Posts: 45
Reply with quote
Post Re: Hydrodynamic Challenge!
Urg, bad news.
This is a shared laptop, and the others users use CC too, but don't like some of my mods. Some smart guy decided to just delete the RTE instead of just removing the .rte in the name. No, it's not in the recycle bin.

I'll give you guys an idea of what I was doing later, I'm kinda busy, and I just wanted to inform you that this happen :(

Maybe water just wasn't meant to be in Cortex Command?

And Geti, there is a simple way to optimize your code a bit, I'll show you as soon as I can get on. You complicated things with positive/negative.


Thu Mar 26, 2009 2:04 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Hydrodynamic Challenge!
really? thats for determining which direction to move the particles, i cant think of any other way of doing it..


Thu Mar 26, 2009 2:39 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 111 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.049s | 15 Queries | GZIP : Off ]