Jump to content
  • Advertisement
Sign in to follow this  
Nice Coder

Very fast Schools of fish

This topic is 5052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been playing metroid prime recently (i only got the game a few days ago). And i was looking at that pond, where you first get to the tallon overworld, you know, right by the waterfall. I was looking at the fish, and how they move. I was wondering if there was a really fast way of generating schools of fish (or paranas, of birds, or anything), which would allow you to make them, without burning the CPU budget. What i was thinking about, is we first do a bit of calculation (maybe once a second) We find out how large the school is We also find the closest objects. (ie. those which can be collided with, before the next update.) We also find out a cource which will take the school away from those objects, and closer to the goal (whatever the goal is). Once we've done that, We go, and for each fish, we calculate what direction they should go in. To do this we do the followikng things. We get a random byte. We take the msb of that byte to determine which direction it should go in (right or left) We get how powerful that direction is based on a 7 bit precomputed (hardcoded) table. In that table, most of the entries only hav einsignificant changes (ie. +- 1 degree), but a few have ubrupt cahanges (ie. table[128] could have + 90 degrees). Also the general speed of each fish increases and decreases, but not by much. (a couple of bits worth maybe). We also generate a force in the direction of the middle of the school. its amplitude gets greater as it gets further away form the center. We also generate a force, in the direction of the path. Its ampliturte gets greater, as the fish (average, as a school) gets further away. We then mix those, along with the random movement, in order to get the fishes new movememnt vector. Now for the path, we make a superfish entity, which is a fsm. Its states are basically "FindEat" "Findfood" "Curious" "Sleep" and "Run" "Findeat" occures when the school (at the furthest point) is close enough to something edible (a dead fish, algea, anything). Findfood basically gets the fish to randomly move, until it gets close enough to food, until it just moves in. "Curious" Basically circles around one object, that they havent seen before (like the player, an eniemy, or basically anything new,) "Sleep" Basically has no path. And the general speed of everything decreases to a crawl. "Run" Basically plots a path away from an object, and the speed increases, away from the object. As the fsm changes states, it changes the coefficients, which makes each force more or less powerful. depending on state. I've been thinking of two different things. either with the fsm. or just changing peramiters liniarly. Now the fsm, would basically be doing a few different things. The entire school has a tiredness index. It also has a fear index and a hunger index. Tiredness and hunger go up all the time. Slowly. Fear goes up when something happens suddenly. And if happens quickly. Especially if its asleep at the time. When the fi goes up above a certain threshold, it automatically switches to the run state. When its running, it doesn't change states, until its fi is low enough. (below a second, much lower threshhold). The fi decays slowly. When the tiredness index goes above a threshhold, then it goes to sleep. When it gets hungry enough, it goes to find something to eat, and as soon as it sees food, it eats. The other intepritation, is that it uses a series of equasions, to change a set of coefficients which change how the flock reacts. It'd be ... different to try, and it'd still have a few if's. But i'd be a nice little fuzzy logic implementation. Any thoughts? Implementations? From, Nice coder [Edited by - Nice Coder on January 6, 2005 5:04:11 AM]

Share this post


Link to post
Share on other sites
Advertisement
hey,
not quite the same as your describing but you can try this:
http://www.adrianboeing.com/files/boids.zip (1mb)
a bit of source included.
fish swim around and eat food.

look up 'boids' in google, i just added 'attact' vectors for mates,food and preditors.

so yeah, the random byte idea is probably not the best way to go, even though it may be faster.

Share this post


Link to post
Share on other sites
I'm looking into boids now, thanks.

the point of it, is to get a really fast algorithm, so you could have swarms of millions of carnivorous fish. Or wasps, or anything really.

From,
Nice coder

Share this post


Link to post
Share on other sites
I;m getting errors with your boids implementation.

I either get a "Cannot start graphics engine", in directX mode, or a null pointer error in opengl mode.

This is after the config screen.

From,
Nice coder

Share this post


Link to post
Share on other sites

----------------LOG BEGIN------------------
E:ERROR [C:\dev\engine\dxengine\dxEngine.cpp:95] (0xde0710:Unkown)DXEngine::WinInit-> Could not create device:D3DERR_INVALIDCALL
----------------LOG BEGIN------------------
E:ERROR [C:\dev\engine\dxengine\dxEngine.cpp:95] (0xde0710:Unkown)DXEngine::WinInit-> Could not create device:D3DERR_INVALIDCALL
----------------LOG BEGIN------------------
E:ERROR [C:\dev\engine\oglengine\oglEngine.cpp:101] (0xde0710:OpenGLEngine)OpenGLEngine::WinInit-> The Requested Fullscreen Mode Is Not Supported By Your Video Card
----------------LOG BEGIN------------------
WARNING [C:\dev\engine\oglengine\oglEngine.cpp:197] OpenGLEngine::WinInit->GL_ARB_multitexture is unsupported!
WARNING [C:\dev\engine\oglengine\oglEngine.cpp:218] OpenGLEngine::WinInit->GL_ARB_vertex_program unsupported!
loaded 3ds database
names in mesh list:
list[0]=UnitCube
mesh #0
3ds mesh name:UnitCube
nVertices: 8
nTextVerts:0
nFaces:12
WARNING [C:\dev\engine\oglengine\oglModel.cpp:153] OpenGLModel::Load3DS->#texture coordinates != #vertices
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
list[10]=object11
mesh #0
3ds mesh name:object
nVertices: 2128
nTextVerts:2128
nFaces:4214
mesh #1
3ds mesh name:object2
nVertices: 154
nTextVerts:154
nFaces:192
mesh #2
3ds mesh name:object3
nVertices: 154
nTextVerts:154
nFaces:192
mesh #3
3ds mesh name:object4
nVertices: 208
nTextVerts:208
nFaces:264
mesh #4
3ds mesh name:object5
nVertices: 208
nTextVerts:208
nFaces:264
mesh #5
3ds mesh name:object6
nVertices: 118
nTextVerts:118
nFaces:144
mesh #6
3ds mesh name:object7
nVertices: 118
nTextVerts:118
nFaces:144
mesh #7
3ds mesh name:object8
nVertices: 316
nTextVerts:316
nFaces:408
mesh #8
3ds mesh name:object9
nVertices: 442
nTextVerts:442
nFaces:576
mesh #9
3ds mesh name:object10
nVertices: 41
nTextVerts:41
nFaces:64
mesh #10
3ds mesh name:object11
nVertices: 41
nTextVerts:41
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
mesh #0
3ds mesh name:object
nVertices: 2192
nTextVerts:2192
nFaces:4220
mesh #1
3ds mesh name:object2
nVertices: 586
nTextVerts:586
nFaces:768
mesh #2
3ds mesh name:object3
nVertices: 154
nTextVerts:154
nFaces:192
mesh #3
3ds mesh name:object4
nVertices: 154
nTextVerts:154
nFaces:192
mesh #4
3ds mesh name:object5
nVertices: 122
nTextVerts:122
nFaces:160
mesh #5
3ds mesh name:object6
nVertices: 122
nTextVerts:122
nFaces:160
mesh #6
3ds mesh name:object7
nVertices: 550
nTextVerts:550
nFaces:720
mesh #7
3ds mesh name:object8
nVertices: 352
nTextVerts:352
nFaces:456
mesh #8
3ds mesh name:object9
nVertices: 41
nTextVerts:41
nFaces:64
mesh #9
3ds mesh name:object10
nVertices: 41
nTextVerts:41
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
list[10]=object11
list[11]=object12
list[12]=object13
mesh #0
3ds mesh name:object
nVertices: 2099
nTextVerts:2099
nFaces:4176
mesh #1
3ds mesh name:object2
nVertices: 45
nTextVerts:45
nFaces:64
mesh #2
3ds mesh name:object3
nVertices: 45
nTextVerts:45
nFaces:64
mesh #3
3ds mesh name:object4
nVertices: 41
nTextVerts:41
nFaces:64
mesh #4
3ds mesh name:object5
nVertices: 41
nTextVerts:41
nFaces:64
mesh #5
3ds mesh name:object6
nVertices: 70
nTextVerts:70
nFaces:128
mesh #6
3ds mesh name:object7
nVertices: 70
nTextVerts:70
nFaces:128
mesh #7
3ds mesh name:object8
nVertices: 89
nTextVerts:89
nFaces:128
mesh #8
3ds mesh name:object9
nVertices: 89
nTextVerts:89
nFaces:128
mesh #9
3ds mesh name:object10
nVertices: 45
nTextVerts:45
nFaces:64
mesh #10
3ds mesh name:object11
nVertices: 45
nTextVerts:45
nFaces:64
mesh #11
3ds mesh name:object12
nVertices: 45
nTextVerts:45
nFaces:64
mesh #12
3ds mesh name:object13
nVertices: 45
nTextVerts:45
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=Sphere01
mesh #0
3ds mesh name:Sphere01
nVertices: 482
nTextVerts:0
nFaces:960
WARNING [C:\dev\engine\oglengine\oglModel.cpp:153] OpenGLModel::Load3DS->#texture coordinates != #vertices
----------------LOG BEGIN------------------
WARNING [C:\dev\engine\oglengine\oglEngine.cpp:197] OpenGLEngine::WinInit->GL_ARB_multitexture is unsupported!
WARNING [C:\dev\engine\oglengine\oglEngine.cpp:218] OpenGLEngine::WinInit->GL_ARB_vertex_program unsupported!
loaded 3ds database
names in mesh list:
list[0]=UnitCube
mesh #0
3ds mesh name:UnitCube
nVertices: 8
nTextVerts:0
nFaces:12
WARNING [C:\dev\engine\oglengine\oglModel.cpp:153] OpenGLModel::Load3DS->#texture coordinates != #vertices
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
list[10]=object11
mesh #0
3ds mesh name:object
nVertices: 2128
nTextVerts:2128
nFaces:4214
mesh #1
3ds mesh name:object2
nVertices: 154
nTextVerts:154
nFaces:192
mesh #2
3ds mesh name:object3
nVertices: 154
nTextVerts:154
nFaces:192
mesh #3
3ds mesh name:object4
nVertices: 208
nTextVerts:208
nFaces:264
mesh #4
3ds mesh name:object5
nVertices: 208
nTextVerts:208
nFaces:264
mesh #5
3ds mesh name:object6
nVertices: 118
nTextVerts:118
nFaces:144
mesh #6
3ds mesh name:object7
nVertices: 118
nTextVerts:118
nFaces:144
mesh #7
3ds mesh name:object8
nVertices: 316
nTextVerts:316
nFaces:408
mesh #8
3ds mesh name:object9
nVertices: 442
nTextVerts:442
nFaces:576
mesh #9
3ds mesh name:object10
nVertices: 41
nTextVerts:41
nFaces:64
mesh #10
3ds mesh name:object11
nVertices: 41
nTextVerts:41
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
mesh #0
3ds mesh name:object
nVertices: 2192
nTextVerts:2192
nFaces:4220
mesh #1
3ds mesh name:object2
nVertices: 586
nTextVerts:586
nFaces:768
mesh #2
3ds mesh name:object3
nVertices: 154
nTextVerts:154
nFaces:192
mesh #3
3ds mesh name:object4
nVertices: 154
nTextVerts:154
nFaces:192
mesh #4
3ds mesh name:object5
nVertices: 122
nTextVerts:122
nFaces:160
mesh #5
3ds mesh name:object6
nVertices: 122
nTextVerts:122
nFaces:160
mesh #6
3ds mesh name:object7
nVertices: 550
nTextVerts:550
nFaces:720
mesh #7
3ds mesh name:object8
nVertices: 352
nTextVerts:352
nFaces:456
mesh #8
3ds mesh name:object9
nVertices: 41
nTextVerts:41
nFaces:64
mesh #9
3ds mesh name:object10
nVertices: 41
nTextVerts:41
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=object
list[1]=object2
list[2]=object3
list[3]=object4
list[4]=object5
list[5]=object6
list[6]=object7
list[7]=object8
list[8]=object9
list[9]=object10
list[10]=object11
list[11]=object12
list[12]=object13
mesh #0
3ds mesh name:object
nVertices: 2099
nTextVerts:2099
nFaces:4176
mesh #1
3ds mesh name:object2
nVertices: 45
nTextVerts:45
nFaces:64
mesh #2
3ds mesh name:object3
nVertices: 45
nTextVerts:45
nFaces:64
mesh #3
3ds mesh name:object4
nVertices: 41
nTextVerts:41
nFaces:64
mesh #4
3ds mesh name:object5
nVertices: 41
nTextVerts:41
nFaces:64
mesh #5
3ds mesh name:object6
nVertices: 70
nTextVerts:70
nFaces:128
mesh #6
3ds mesh name:object7
nVertices: 70
nTextVerts:70
nFaces:128
mesh #7
3ds mesh name:object8
nVertices: 89
nTextVerts:89
nFaces:128
mesh #8
3ds mesh name:object9
nVertices: 89
nTextVerts:89
nFaces:128
mesh #9
3ds mesh name:object10
nVertices: 45
nTextVerts:45
nFaces:64
mesh #10
3ds mesh name:object11
nVertices: 45
nTextVerts:45
nFaces:64
mesh #11
3ds mesh name:object12
nVertices: 45
nTextVerts:45
nFaces:64
mesh #12
3ds mesh name:object13
nVertices: 45
nTextVerts:45
nFaces:64
loaded 3ds database
names in mesh list:
list[0]=Sphere01
mesh #0
3ds mesh name:Sphere01
nVertices: 482
nTextVerts:0
nFaces:960
WARNING [C:\dev\engine\oglengine\oglModel.cpp:153] OpenGLModel::Load3DS->#texture coordinates != #vertices



This is Log.txt

From, Nice coder

Share this post


Link to post
Share on other sites
Ah, I think thats because your gfx card doesn't support multi-texturing? Perhaps?
Or I just suck.
But you could take a look at the source code and get some help anyway hopefully :)

Share this post


Link to post
Share on other sites
Would it be possible to do the swarm calculations on the GPU? Each fish could be represented as a vertex, and then the vertex program could perform some perterbation on the location of the fish, causing it to appear to be animated. It would be fast as hell and wouldn't burn up any of the CPU.

Share this post


Link to post
Share on other sites
Nice idea!


I've seen vidio cards being used for prosessing before...

But the real issue, is: Would it take longer getting the data to the card, then what it would take just to process it?

From,
Nice coder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!