Sand/dust with fluid dynamics physics

It's possible to develop game that reproduce sand/dust with fluid dynamics physics?

Like this:
http://appbank.us/iphone/ipad-iphone-sand-play-with-sand-the-movements-are-so-real-you-can-even-make-a-sand-clock

Hi,

of course.. easy with corona..

i would say.. the sand are small balls..
if you want dust.. use particle candy ..

BR

There are examples of code for this?
I don't know Corona and If I buy Corona for iPhone it's included a support service?

here's an example to do something like this.
but honestly, the performance on an actual device is not very satisfying...

This works great with particle counts up to 100, but then it gets sloppy. I created this with much bigger objects (bouncing balls) and quickly changed it to "sand mode". There has to be a better solution, but you should get the idea:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- Project: PhysicsTest
-- Description: particle physics test
--
-- 2011 finefin
 
local physics = require("physics")
physics.start()
physics.setGravity( 0, 40 )
--physics.setDrawMode( "hybrid" )
 
-- A general function for dragging physics bodies
local function dragBody( event )
        local t = event.target
 
        local phase = event.phase
        if "began" == phase then
                display.getCurrentStage():setFocus( t )
                t.isFocus = true
                                -- Store initial position
                t.x0 = event.x - t.x
                t.y0 = event.y - t.y
                         if event.x > t.x then
                                t.rotation = t.rotation -  10
                         elseif event.x < t.x  then
                                  t.rotation = t.rotation + 10
 
                         end
                -- Make body type temporarily "kinematic" (to avoid gravitional forces)
                event.target.bodyType = "kinematic"  
                -- Stop current motion, if any
                event.target:setLinearVelocity( 0, 0 )
                event.target.angularVelocity = 0
 
        elseif t.isFocus then
                if "moved" == phase then
                        t.x = event.x - t.x0
                        t.y = event.y - t.y0
                                elseif "ended" == phase or "cancelled" == phase then
                        display.getCurrentStage():setFocus( nil )
                        t.isFocus = false
                        
                        -- Switch body type back to "dynamic", unless we've marked this sprite as a platform
                        if ( not event.target.isPlatform ) then
                                event.target.bodyType = "dynamic"
                        end
                end
        end
        -- Stop further propagation of touch event!
        return true
end
 
-- create world
local wallLeft = display.newRect( 0, -50, 10, 530 )
physics.addBody( wallLeft, "static", { friction=0.5 } )
 
local wallRight = display.newRect( 310, -50, 10, 530 )
physics.addBody( wallRight, "static", { friction=0.5 } )
 
local platform1 = display.newRect( 0, 50, 200, 10 )
physics.addBody( platform1, "static", { friction=0.5 } )
platform1.rotation = 10
platform1:addEventListener( "touch", dragBody )
platform1.isPlatform = true
 
local platform2 = display.newRect( 120, 150, 200, 10 )
physics.addBody( platform2, "static", { friction=0.5 } )
platform2.rotation = -10
platform2:addEventListener( "touch", dragBody )
platform2.isPlatform = true
 
local platform3 = display.newRect( 0, 250, 200, 10 )
physics.addBody( platform3, "static", { friction=0.5 } )
platform3.rotation = 10
platform3:addEventListener( "touch", dragBody )
platform3.isPlatform = true
 
-- create table for all particles
local balls = {}
 
-- remove particles that are out of bound
local function ifOutOfBounds (event)
                for i,val in pairs(balls) do
                        if(val.y > 480) or (val.y < -50) then  
                                          val:removeSelf();
                                          balls[i] = nil;
                        end
                end
        
end
 
local randomBall = function()
                -- create ball
                local ball
                ball = display.newRect(  160, -20, 1, 1 )
                ball.x = 160; ball.y = -20
                physics.addBody( ball, { density=1, friction=0.6, bounce=0.1, radius=1 } )
                ball.angularVelocity = math.random(800) - 400
                -- add ball to table
                balls[#balls + 1] = ball        
end
        
Runtime:addEventListener( "enterFrame", ifOutOfBounds )
timer.performWithDelay( 10, randomBall, -1 )

I don't think so actually. Fact of the matter is that doing something like that simulation is very CPU intensive and will not come out nicely via a scripting language. It's not as easy as AlenB thinks it is, box2d is not designed for that kind of simulation.

views:3872 update:2011/9/17 17:34:41
corona forums © 2003-2011