Announcements
- Forum fixes
- Assignment 2 (critiques)
- Assignment 3 (graphics readings)
- Friday (show and tell)
Steering Behaviors
Each time, “steer”
- maintain velocity (if flying), or adjust
- change direction
- each agent does it independently (but can look at others)
- distributed model
Different “Behaviors”
- wander
- goals
- potential field / vector fields
- align
- follow
- avoid
- collide
- prediction (go where you think there will be space)
- visible vs. all direction
- distance cutoff vs. all
How to combine behaviors?
- add them
- be smart
- prioritize
Scalability – What if N gets big
Two/Three different issues:
- O(n^2) behaviors (everybody checks everybody else)
- worst case O(n^2) behaviors (collision checks, visible or close effects)
- linear (but really slow) parts (drawing)
Can you do anything about linear?
- avoid off-screen (culling)
- overdraw / high density (visibility)
O(n^2) all effects all
- gravitation effects-like things
- tricks for distant interactions (2 things far away seem like 1 bigger one)
- work hierarchically
- fancy algorithms exist for physics cases (n-body simulation) – hacky versions possible for flock like things
Better performance effects come from avoiding N^2 (for the checks) – quickly rule out large groups
Key: use good data structures to organize things
Applications:
- collisions
- static objects can be “compiled”
- test against simpler objects first
- nearest neighbors (k-NN, approximate k-NN, d-neighbor, …)
- range search
- useful for culling and LOD
Intro to Spatial Data Structures
Big topic, quick brush
best structures depend on application and data – so get some basic ideas
as # of dimensions go up, things get trickier
1D Example
- range scan
- collision (points in range) check
- k-nearest neighbor for each
naïve is n^2
sort
- n log n cost to sort
- equivalent to building search tree
- finding 1 k-nn is log n + k (find in tree, then look at neighbors)
- final all knn is n k (since go through sorted list)
updates? (re-sort, fast sort for small # of changes)
can you do better than k-nn?
- radix sort (buckets)
- too few buckets – more chance of piling up
- too many buckets – cost of clearing them gets high
- sensitive to distribution
approximate nearest neighbor
- just look in bucket (might be off by bucket size)
- this is an over-simplified strategy – there are much better ones
Higher dimensions
- no analog to sorting
- grids are bad (grows really quickly – often lots of cells, most are empty)
- search trees
- split on multiple axis (quad-trees / octrees)
- split on 1 axis at a time (k-d trees)
- pick 1 axis?
- could get lucky or un-lucky
- pick1 axis multiple times?
- unlikely to get unlucky all the times
- think of a dimension as a locality preserving hash
Weird Fact: in high dimensions, hard to do better than linear search (LSH as approximation to do dimensionality reduction)
In practice: for low dimensions (2,3,4, …) – highly efficient spatial data structures + tricks
Simulation basics
see http://graphics.cs.wisc.edu/Courses/Games08/Main/Flocking
see https://pages.graphics.cs.wisc.edu/679-11/files/2011/09/09-13-11-GamesFlocking.pdf (pages 3/4)
- 2008.1 (concept of local control, historical note, terms)
- particles / simulation (state, velocity, why this is ODE, step model) 2011 notes
- 2008.2 (basic model)
- 2008.3 (more flocking stuff)
Spatial Data Structs Notes from 2011: https://pages.graphics.cs.wisc.edu/679-11/files/2011/09/09-21-11-SpatialDataStructures.pdf