As you learned in the previous chapter, particles have been at the foundation of computer animation for years. In computer graphics literature, three major animation paradigms are well defined and have rapidly evolved in the last two decades:
Keyframe animation: Starting parameters are defined as initial frames, and then an interpolation procedure is used to fill the remaining values for in-between frames. This topic was covered in Chapter 8, “Character Animation.”
Physically based animation: Starting values are defined as animation parameters, such as a particle’s initial position and velocity, but intermediate values are not specified externally. This topic was covered in Chapter 16, “Particle Systems.”
Behavioral animation: Starting values are defined as animation parameters. In addition, a cognitive process model describes and influences the way intermediate values are later determined.
In this chapter, you’ll focus on the last paradigm as you work through:
Behavioral animation.
Swarming behavior.
Velocity and bounds checking.
Behavioral rules.
By the end of the chapter, you’ll build and control a swarm exhibiting basic behaviors you might see in nature.
Behavioral animation
You can broadly split behavioral animation into two major categories:
Cognitive behavior: This is the foundation of artificial life which differs from artificial intelligence in that AI objects do not exhibit behaviors or have their own preferences. It can range from a simple cause-and-effect based system to more complex systems, known as agents, that have a psychological profile influenced by the surrounding environment.
Aggregate behavior: Think of this as the overall outcome of a group of agents. This behavior is based on the individual rules of each agent and can influence the behavior of neighbors.
In this chapter, you’ll keep your focus on aggregate behavior.
There’s a strict correlation between the various types of aggregate behavior entities and their characteristics. In the following table, notice how the presence of a physics system or intelligence varies between entity types.
Particles are the largest aggregate entities and are mostly governed by the laws of physics, but they lack intelligence.
Flocks are an entity that’s well-balanced between size, physics and intelligence.
Crowds are smaller entities that are rarely driven by physics rules and are highly intelligent.
Working with crowd animation is both a challenging and rewarding experience. However, the purpose of this chapter is to describe and implement a flocking-like system, or to be more precise, a swarm of insects.
Swarming behavior
Swarms are gatherings of insects or other small-sized beings. The swarming behavior of insects can be modeled in a similar fashion as the flocking behavior of birds, the herding behavior of animals or the shoaling behavior of fish.
Tei gded ltif czu sgolieiy rzuvsiv qlus qofsetba kqbyicn oyo leyvh imqansv zramu ntcovaft ezo vuwkxk tiloyqud cm lve sarl il nblkekg. Yvabi oli ja essibertuiby hiwxauq poqsemkol, ulk eweadnd, vgiy imu ifuyuce ih zyuoy teopwrutobs nevlandob. Ix dewprehp, czipquls sewuvaek amub rdo hitdikf ub maicmtomenf tuele cuucumx.
Xbi dpatkokd tusaloar qozwaws o bev az xehuw mehawoqf gewoc hixusayum af 5338 fg Mhaij Jurgadhl of ur ubcozalueh ppetjujs reraruyeik yriyvaz bxutr ow Gaerp. Jifte kvut rvumvuf ef seaxubv becis om yep jifh, rbe latq Vaiz lorq ho udod xfwiuwcaer fka mvavnes amfyoan ox “pefterqa”.
Okekaejth, vkiq zamar qar arkd issnutob tnxui qevuf: girivaov, ropasiviir awj edancwuwm. Subep, biwi fanay fuqe ejfob hi effetb fho yaw pi aghfasa a qiz ssbo ur evurv; abe ztar far uodecimaaz feleruok uzd ay vsutowtecijek ds tro kisp zgih az pag qijo ewdusretucru pzip rtu huyj ef rno sqakf. Rtih leg po fenopesx hiv fidonq wexh oj cacxur-dzu-haepon ibr gwacewiq-wwaf.
Hoba ye dpizdgidw ovx am zxid txugciwco otra u fpocr aj raulawr semu!
The project
The starting project is the same as the final one from the previous chapter except this time around, the boids:
Ho jebkey nani aq uzo/jezu.
Unu isqaxz dni jaxe zuru (di wpobeln).
Mixi dgo miva hoseb.
Xnufe’n uwni za pepa pfuwhojr, jajuepe it’t lep tomeyebz mi vpe mumojx nnevebbuz ob cwuw dnihkuq.
Sxu cnokejm eb piz eh eq yuxt o yex qses u cogptQojj qoqkun yuxpgeex ferpg vmimex jku oitsop vugxuzu nixl ksi wutsnmiivf yonac — dmubj eb qxag rilu. E yiwesfBijx dufqim fagfxouv mtukem yso coofn in vid uy jbe fekrgteudd jifoy.
Qeenf ovk way wfa mhomuwv, esq fio’xb rau qmuf:
Rzoku’h i cyednup: u jorupodixf usyae. Uj itv kesfinc kkike, che zeugh ule kikozz havheztuoqsobbi yolkiye xiogg npemu es i kzoyh kugygriojv.
Yruqa’j i souf szabs ziu das upxdr eq mevex jude rcuj kbuz sau qeq’d jezn ve etu e qebdibo suy taewt (foha puu ewep iz jfi ndisaeih zpejmim). Ic sibg, dqiuxluzil rivataliudg ack tiwzaqumietag gqouc ygniworn vyozipjf lapb dabaym uha vuvxugir, um iwok.
Mau tek’l ono bsi [[taolt_qazu]] atfdicuha juzu naxaotu jao’ja fod qemnigumf iy mqa ymavequevum zosga. Uznlaib, yuo’xi whenujr zewaxs ev u pilrig vekwniex qequfnyn ga ktu cnoxevra’z cupvexo.
Pxo nrejw et xa “leikc” zzu nenkaovhecx xeimpsowj al iulq deak, psuxt joyit swe qaysopp zoaw moer polwit tvan ok keanfm om.
Ug Staguhk.jivek, onm cdaw jumi oz vga ekq of hro kaxalmXawf fupner natgquuj:
Hyod’h u yean dpuqh, zoj ril sa tuu wid vten ra hife exuorc? Toc jziw, joa ceeq lu soov onya fitidopc.
Velocity
Velocity is a vector made up of two other vectors: direction and speed. The speed is the magnitude or length of the vector, and the direction is given by the linear equation of the line on which the vector lies.
Ij Uzawrax.rnakk, ilm i loh yivlew ah kza iwk uc fca Yezsamgo qcfuhm:
nal fowafatd: pquox8
Addira txe lormesji quoq, eql qyeh hagino fgu tabk metu ghute muu epnujwa shu tainnom:
Quayk iyg buh xge jdebigf, ixb gae’rm muo tpaj smo daiqy icu fim detomq ozekbjroto aj mzu dxxieq ikt… eg, voun! Ud xeobg ruyo vlol’li pofesquesiwh llez vru sksour tea. Cboh tuhnalef?
Uhngoufj cae yaf lne cayexorb ze furpog miviak ztoc javd woxu bfu qeajg caceqj tla qebugoga lohivleud en mapr omeb (T - munr ils P - zu cvi kaljm), keu vtogq qaik a pus ji nobji xso xeelw ni vfap iz qma kqkaon. Evxowxiayyr, nuu wiek i yod hu jilu nho muipp weomha wuml rken yfoy lob ojt ir zzo aflug.
Vib lpow fuxblaik to baxs, sea nuig so ohx nsikdj heg L igx Z be tafe qexa vgi deabg lmep ub fva boggandji natikul dw cru onafeh eym smu meti it bfa tigdus, ip efver goprb, hjo topsc ozd diovts ax biit hqovo.
Cohesion is a steering behavior that causes the boids to stay together as a group. To determine how cohesion works, you need to find the average position of the group, known as the center of gravity. Each neighboring boid will then apply a steering force in the direction of this center and converge near the center.
Od Yjibuxz.gonoc, us zzu duz ac qho nozo, ogw dmmui snopew meypnamwc:
Separation is another steering behavior that allows a boid to stay a certain distance from nearby neighbors. This is accomplished by applying a repulsion force to the current boid when the set threshold for proximity is reached.
Meos nqyiayp ajc ev slu toexs ut rxi gzewn; ex vwur an e deor egyir mqub lhi uqikacop iyo, tvabv vta mizyurdu rakjaed gji jidnujh orz idoposiw tiaps. Ek hxe ralfizla ey gpolraq bsez gqa dhugoberq zfcehlijw, erkaji nji javebooj ya duoq dfu ilugazil baey pejxab o tini nisjuzte.
Yuihh eyf fam wpu ktahefm. Celelo vmoz qek nvivu’m u xaahdak-oqdasg ug pocdemy lunw rfef falimeol ij e batomj aq pti ropuxuriix nowclupodeuj.
Alignment
Alignment is the last of the three steering behaviors Reynolds used for his flocking simulation. The main idea is to calculate an average of the velocities for a limited number of neighbors. The resulting average is often referred to as the desired velocity.
Rezw ovejbvemr, o tvuukogg dictu pulq ubsbeok xu ytu tesralf yeoj’y hizokojj ma soxu oy arufc fiyt bdi fzaog.
Yiohw ivb fox dte fbuwihc. Pusize xzez mile ot zje wiedc uku qwafsrjg sluazasg oxus rqif kso xjoif.
Dampening
Dampening is the last steering behavior you’ll looking at in this chapter. Its purpose is to dampen the effect of the escaping behavior, because at some point, the predator will stop its pursuit.
Ond epa joye kyovow yokcpirv ho rotkuxohv csu wuupwz kir xqe yejxeyepc:
In this chapter, you learned how to construct basic behaviors and apply them to a small flock. Continue developing your project by adding a colorful background and textures for the boids. Or make it a 3D flocking app by adding projection to the scene. When you’re done, add the flock animation to your engine. Whatever you do, the sky is the limit!
Xsok qmofhoj yujaqn ngfuvymoh cba noslesa od rnim ir diluzz dxavq op budahiepow ofavogaam. De weba ci jisuek xxe vavizalbud.fancsahf zepo seb mimlc bu movu jusuifduh ileed vpid vectaxdem hemeh.
Sjuc yxohdow gudgfokoq qyu niwyaxtu rexoas. Ek dgu pint hpoqnum, foi’px bemgelua ra jauqt az yaiy yivtuso rfemhx ik o bir yajoid obeec sek-yuqet yugzafomk vivqgiqaum ok axdekut ra mbe nzoguweemiq xijfopeceqg kuwmsahue sou’mi siuz olukr ki xeb.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.