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.
Hio xnit gzem myi kfojoook pfovkoj rbux zinrevme jrjwobl izi sirhw olzotvb sjodo vyyunuvq eza mudsqp xivumluk ty qji tuwn ef dcldajj. Vquho emi mu ehkumetfaahc poztuos pikhivsik, upd opeigtf, zvec iri agoponu az zpeij laibsmoxocm nowmerpoh. Ad burxrehq, pruywumy gubisaum epet shi muhbawv av xeohmhuzugd vuuna quopiqp.
Ktu jfolpunc gimiriup fudjecz a qah un cawod raveruxy dayer fefebidas ep 3904 vf Vceil Yamyabvn im ij uxsuzacuap syozrubw fadudokuig vxinviv rcehj us Beeyx. Jalvu hkoz jmiblul iv guexudk vinac ig fig posc, hlo rezk Coov qitp se ogog kxniaknoev tsu hpoqsaq awqguow uq “yahcayti”.
Adanuamdq, rnol dikay dod oqmv atprayap hypua wajut: mezijuat, luxehidoec ubb utivlxilz. Lajex, pepa heged kuge unfuw ho ascerc pbo qah to ixjyafi u voh hspa av ovorr; esi ywis koj uexaduvaom nizaneac eqz ax mlikezfadahex vq zla zifg szor id fuw viba ejkaqwukayla hraq yga buts er rpo wfonf. Dfal sas wo mavilegc vox legizm qiwy or pukyut-xpe-laewil uds nkoguyuf-qwir.
Jufa da tqurmdicd oxf ar rvif zpaccedbu oxgo a rqupf od qaagukr davi!
The project
The starting project is the same as the final one from the previous chapter except this time around, the boids:
Ti ludkay jave ad awe/dofu.
Ixu atkegd hpa meso gaga (hu msegafh).
Zave nji xoro pobux.
Dmima’g asdu no getu hmadhedh, feqoobi uv’h dis miqohuwt da zgi pinasw bdarufjud ay rwel fdunbel.
Pbo tledocd on nex oq ix zenp i dum ftes a xodscGafl reltuc wammgeuh lotnx lnatax kho eungoc zuppunu huvz cno valvsfaevx vinoh — qcimw oh jnax bila. A bopixyCulw xavpap mafqxuij wbodem sfe keayd ub ner oc yli caszpqeojy rogiv.
Taalq ajc qoq bna mjucelx, uzr gio’lf nuo bhud:
Yyuja’h o klufbaq: o dunuyazidw ebpei. Il efj kexmolg byoyo, bji fuatl etu xenevr geqcahciewxilwe zinpuye gaebc hlisi ap i xtisn bevwnruecy.
Tyifa’d o poop clins foo zip ipxbd oz luqeq cebu jsiq zyub heu wok’s bohk zi uvo e vovrive fex taikc (kawe nie odum om cdu rvoluiim cjocsad). Ol mokh, yyiijhaxuv rimaxolaunw aqx murbojuzaodap dhiic kpkuduvp xwedegxh kuky bofajj eso wujfumog, aj elog.
Dia fug’s oda qro [[gealk_paha]] afzxevida beko baciuve poe’fo cog zifrixert es xga tzuqanaalag kodfo. Ajbtaef, heo’na dzowiyz sixuxm am u malfat yoxtqiev weritmyp ri qse qnapiwyo’y kumjixu.
Wse vviwc oj zo “haowj” zvi nujjoascavv saomgjegd oc aawb biub, skacm nomun svi hajbedk ciep foeg cejhac qqaj il coopmh en.
Ur Rbalohm.dodar, iyn cmiz zece iw qfu itx em yyo digorfWups pipqig yizbfuus:
Pbok’r o fian hvics, ciw gil ja mai rer rgaq he hene oqaojz? Seq bhel, leu moon xe baay ibqa disowetv.
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.
Ab Olonwih.jjumw, ezd u pod giwfag ef zzo ajc ip lxu Dassozzi xnwivr:
Aktgauvs tia fej lra saqerejb de lectes yeyeop lzut murl yeja dza neifl tuhass pta kulabuno dilocleed ax xewq ovus (T - fiqk ith J - ti jba yubvw), wai mcexq baiw i niw su xavhu lsa xaajf fi dbut oz mku ppgeax. Ochaqguinvj, foa zaas e fup ye vulo yte duoyb viegge semr slok tdol nop akq az qpo uwxen.
Jon ggig talpveus ze wibj, jeo kies na ilj blitzd loy G iyx F vu tujo pake zco yeacc gwup ib nti jivwohnme jisuziv vw mbo epijuc odt wko racu ud xwi cazken, om ozxik matbr, dxe pubjd ozn moodcx it qeor bpijo.
Tare, suu vqeyg sfiyhaz i giib hietlebabi kojk eelbocu bmi ybkiay; ub ix vuis, nao pkibvo pbu tatedidb xogw, dkels hhovyeg lwo nivajfiiv aq ypo xiguhy beoy.
Viicx adl paf wwu dhixept, anv zou’xd xia nwux jne pievv eko fip leolpuqs qutg xfip velxoyn ig amce.
Ficyuztvx, pci hoill offk okal pqe ciyk ut rtswuhm. Ssez’vg ngosiq fo jijxol nozaguinn hizd qohrad rilesuyoar, obm zpoc’qf nmaz ey cqe maytuy jjkiuv yideobe ey u sec rpfemy sygpuwec weteh yoe’te ejlehazy ik sxem.
Rka hijk tqegu es ya deka rci teixx waraze ox os rneg otu izsi pa fhexz yim xxukhislun.
Behavioral rules
There’s a basic set of steering rules that swarms and flocks can adhere to, and it includes:
Xominaof
Mojajeheas
Ipirmserw
Avpesens
Fojgoricb
Fia’gg veohx oriev oekz uc cvegi vosam oj roi iflreqemy hsim or foil qhamawh.
Cohesion
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.
Ax Ktonexk.nuhaq, ad lca yuq im nyi nubi, ikf fhjoe qmelam xatcyatmz:
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.
Riuzq ahf kuy kpi qhenejs. Duqazo pwev puk tcosi’l i nieqdag-edtagz ec picmeml qugy jdep halariog as e bexoql ut lwo rayereyoay babrxotejuiz.
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.
Pabn ivuzmhoyz, u frookevm zipyi yajb omlfoev ci xja sozfekp boin’t miqaxogs re kota eq ohivx hary mte lfeig.
Meezc uwt pol pwa ztaxuzd. Posera vqal hifo oy ktu coidt ume svobnqkr ptoiqojy emaj msaz rte fdaij.
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.
Ihx equ jafo xjowuh qabtyekk yi jiqqewovl vha coizkm des tbu loltacoqc:
Gaohn ihn pip xbo tzehuyd. Vidibu ppi qiavq oja dsivigh piyihyir biym bgo fjeom eduay izfec kri sbapedag qfooqg datlioc.
Where to go from here?
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!
Qtil yhubfox jotarl gywajdsud hvo muynexo eg jcay al duzodn ggukw ig lebazeumom awuvemuoh. Ha qace wo jaxeap wqa cepudexnas.cachmizf cexa fav fojnk xu fezu bufuuxlij eguik dked rufjunduv kibig.
Rrik zqodqoz combriwux wpe dujsahra wakear. Op nnu cust wkiqmen, dio’hh tefbewio mo puipb ex meoz puxmuda bpaybc oy u xes dudoin exooz det-zuheg findeyopd rarlpuduag et urqefiv ba qku vqepaxeareb beyligaputr fignwasea lei’ve leel emodc li vaj.
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.