Flocking.htm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. <html xmlns:MSHelp="http://msdn.microsoft.com/mshelp" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:xanx="http://schemas.microsoft.com/developer/xanx/2005"><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"><META NAME="save" CONTENT="history"><title>Flocking Sample</title>
  2. <style><!--
  3. /***********************************************************
  4. * SCRIPT-SUPPORTING STYLES
  5. ***********************************************************/
  6. /* Defines the userData cache persistence mechanism. */
  7. .userDataStyle
  8. {
  9. behavior: url(#default#userData);
  10. }
  11. /* Used to save the scroll bar position when navigating away from a page. */
  12. div.saveHistory
  13. {
  14. behavior: url(#default#saveHistory);
  15. }
  16. /* Formats the expand/collapse images for all collapsible regions. */
  17. img.toggle
  18. {
  19. border: 0;
  20. margin-right: 5;
  21. }
  22. /* Formats the Language filter drop-down image. */
  23. img#languageFilterImage
  24. {
  25. border: 0;
  26. margin-left: 0;
  27. vertical-align: middle;
  28. }
  29. /* Formats the Members Options filter drop-down image. */
  30. img#membersOptionsFilterImage
  31. {
  32. border: 0;
  33. margin-left: 0;
  34. vertical-align: middle;
  35. }
  36. /* Formats the Collapse All/Expand All images. */
  37. img#toggleAllImage
  38. {
  39. margin-left: 0;
  40. vertical-align: middle;
  41. }
  42. /* Supports XLinks */
  43. MSHelp\:link
  44. {
  45. text-decoration: underline;
  46. color: #0000ff;
  47. hoverColor: #3366ff;
  48. filterString: ;
  49. }
  50. body
  51. {
  52. background: #FFFFFF;
  53. color: #000000;
  54. font-family: Verdana;
  55. font-size: medium;
  56. font-style: normal;
  57. font-weight: normal;
  58. margin-top: 0;
  59. margin-bottom: 0;
  60. margin-left: 0;
  61. margin-right: 0;
  62. width: 100%;
  63. /*font-size: 110%;*/
  64. }
  65. div.section
  66. {
  67. margin-left: 15px;
  68. }
  69. div.hxnx5
  70. {
  71. margin-left: 1.5em;
  72. }
  73. /* Font for all headings */
  74. h1, h2, h3, h4, h5, h6
  75. {
  76. font-family: Verdana, Arial, Helvetica, sans-serif;
  77. margin-top: 18;
  78. margin-bottom: 8;
  79. font-weight: bold;
  80. }
  81. h1
  82. {
  83. font-size: 130%;
  84. color: #003399;
  85. }
  86. div#scrollyes h1 /* Changes font size for full-scrolling topic */
  87. {
  88. font-size: 150%;
  89. }
  90. h2
  91. {
  92. font-size: 125%;
  93. }
  94. h3
  95. {
  96. font-size: 115%;
  97. margin-top: 9;
  98. margin-bottom: 4;
  99. }
  100. h4
  101. {
  102. font-size: 115%;
  103. margin-top: 9;
  104. margin-bottom: 4;
  105. }
  106. h5
  107. {
  108. font-size: 100%;
  109. margin-top: 9;
  110. margin-bottom: 4;
  111. }
  112. h6
  113. {
  114. font-size: 100%;
  115. margin-top: 9;
  116. margin-bottom: 4;
  117. }
  118. ul p, ol p, dl p
  119. {
  120. margin-left: 0em;
  121. }
  122. p
  123. {
  124. margin-top: .6em;
  125. margin-bottom: .6em;
  126. }
  127. td p
  128. {
  129. margin-top: 0.0em;
  130. margin-bottom: 0.6em;
  131. }
  132. dd p
  133. {
  134. margin-top: 0.0em;
  135. margin-bottom: 0.6em;
  136. }
  137. .image
  138. {
  139. text-align: center;
  140. }
  141. dl
  142. {
  143. margin-top: 0em;
  144. margin-bottom: 1.3em;
  145. }
  146. dd
  147. {
  148. margin-bottom: 0em;
  149. margin-left: 0;
  150. }
  151. dl.glossary dd
  152. {
  153. margin-bottom: 0em;
  154. margin-left: 1.5em;
  155. }
  156. dt
  157. {
  158. margin-top: .6em;
  159. margin-bottom: 1;
  160. }
  161. ul, ol
  162. {
  163. margin-top: 0.6em;
  164. margin-bottom: 0.6em;
  165. }
  166. ol
  167. {
  168. margin-left: 2.5em;
  169. }
  170. ul
  171. {
  172. margin-left: 1.9em;
  173. }
  174. li
  175. {
  176. margin-bottom: 0.4em;
  177. }
  178. ul ol, ol ol
  179. {
  180. list-style-type: lower-alpha;
  181. }
  182. pre
  183. {
  184. margin-top: .6em;
  185. margin-bottom: .6em;
  186. }
  187. pre
  188. {
  189. font: 105% Lucida, mono;
  190. color: #000066;
  191. }
  192. code
  193. {
  194. font-family: Monospace, Courier New, Courier;
  195. font-size: 105%;
  196. color: #000066;
  197. }
  198. table.userdata td
  199. {
  200. background: #ffffff;
  201. background-color: #F5F5F5;
  202. border-color: #ffffff;
  203. border: none;
  204. }
  205. table.clsWarning
  206. {
  207. background: #ffffff;
  208. padding: 0px;
  209. margin: 0px;
  210. border: none;
  211. }
  212. table.clsWarning td
  213. {
  214. padding: 0px;
  215. margin: 0px;
  216. background: #ffffff;
  217. vertical-align: middle;
  218. font-size: 70%;
  219. }
  220. div#mainSection table
  221. {
  222. width: 98%;
  223. background: #ffffff;
  224. margin-top: 5px;
  225. margin-bottom: 5px;
  226. }
  227. div#mainSection table th
  228. {
  229. padding: 5px 6px;
  230. background: #EFEFF7;
  231. text-align: left;
  232. font-size: 70%;
  233. vertical-align: bottom;
  234. border-bottom: 1px solid #C8CDDE;
  235. }
  236. div#mainSection table td
  237. {
  238. padding: 5px 5px;
  239. background: #F7F7FF;
  240. vertical-align: top;
  241. font-size: 70%;
  242. border-bottom: 1px solid #D5D5D3;
  243. }
  244. div#syntaxCodeBlocks table th
  245. {
  246. padding: 1px 6px;
  247. color: #000066;
  248. }
  249. div#syntaxCodeBlocks table td
  250. {
  251. padding: 1px 5px;
  252. }
  253. /* Applies to the running header text in the first row of the upper table in the
  254. non-scrolling header region. */
  255. span#runningHeaderText
  256. {
  257. color: #003399;
  258. font-size: 90%;
  259. padding-left: 13;
  260. }
  261. /* Applies to the topic title in the second row of the upper table in the
  262. non-scrolling header region. */
  263. span#nsrTitle
  264. {
  265. color: #003399;
  266. font-size: 120%;
  267. font-weight: 600;
  268. padding-left: 13;
  269. }
  270. /* Applies to everything below the non-scrolling header region. */
  271. div#mainSection
  272. {
  273. font-size: 70%;
  274. width: 100%;
  275. }
  276. /* Applies to everything below the non-scrolling header region, minus the footer. */
  277. div#mainBody
  278. {
  279. font-size: 90%;
  280. margin-left: 15;
  281. margin-top: 10;
  282. padding-bottom: 20;
  283. }
  284. /* Adds right padding for all blocks in mainBody */
  285. div#mainBody p, div#mainBody ol, div#mainBody ul, div#mainBody dl
  286. {
  287. padding-right: 5;
  288. }
  289. div#mainBody div.alert, div#mainBody div.code, div#mainBody div.tableSection
  290. {
  291. width:98.9%;
  292. }
  293. div.alert p, div.code p
  294. {
  295. margin-top:5;
  296. margin-bottom:8;
  297. }
  298. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Begin Note Styles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  299. div#mainSection div.alert table
  300. {
  301. border: 0;
  302. }
  303. div#mainSection div.alert table th
  304. {
  305. padding-top: 0;
  306. padding-bottom: 0;
  307. padding-left: 5;
  308. padding-right: 5;
  309. }
  310. div#mainSection div.alert table td
  311. {
  312. padding-left: 5;
  313. padding-right: 5;
  314. }
  315. img.note
  316. {
  317. border: 0;
  318. margin-left: 0;
  319. margin-right: 3;
  320. }
  321. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - End Note Styles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  322. /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Begin Non-scrolling Header Region Styles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
  323. /* Applies to the entire non-scrolling header region. */
  324. div#header
  325. {
  326. background-color: #D4DFFF;
  327. padding-top: 0;
  328. padding-bottom: 0;
  329. padding-left: 0;
  330. padding-right: 0;
  331. width: 100%;
  332. }
  333. /* Applies to both tables in the non-scrolling header region. */
  334. div#header table
  335. {
  336. margin-top: 0;
  337. margin-bottom: 0;
  338. border-bottom-color: #C8CDDE;
  339. border-bottom-style: solid;
  340. border-bottom-width: 1;
  341. background: #D4DFFF;
  342. width: 100%;
  343. }
  344. /* Applies to cells in both tables in the non-scrolling header region. */
  345. div#header table td
  346. {
  347. color: #0000FF;
  348. font-size: 70%;
  349. padding-right: 20;
  350. padding-top: 1;
  351. padding-bottom: 1;
  352. border: none;
  353. background: #D4DFFF;
  354. }
  355. /* Applies to the last row in the upper table of the non-scrolling header region. Text
  356. in this row includes See Also, Constructors, Methods, and Properties. */
  357. div#header table tr#headerTableRow3 td
  358. {
  359. padding-bottom: 2;
  360. padding-top: 5;
  361. padding-left: 15;
  362. }
  363. /* Applies to the lower table in the non-scrolling header region. Text in this table
  364. includes Collapse All/Expand All, Language Filter, and Members Options. */
  365. div#header table#bottomTable
  366. {
  367. border-top-color: #FFFFFF;
  368. border-top-style: solid;
  369. border-top-width: 1;
  370. text-align: left;
  371. padding-left: 15;
  372. }
  373. blockquote
  374. {
  375. margin-left: 3.8em;
  376. margin-right: 3.8em;
  377. margin-top: .6em;
  378. margin-bottom: .6em;
  379. }
  380. sup
  381. {
  382. text-decoration: none;
  383. font-size: smaller;
  384. }
  385. a:link
  386. {
  387. color: #0000FF;
  388. /* font-weight: bold */
  389. }
  390. a:visited
  391. {
  392. color: #0000AA;
  393. /* font-weight: bold */
  394. }
  395. a:hover
  396. {
  397. color: #3366FF;
  398. /* font-weight: bold */
  399. }
  400. .label
  401. {
  402. font-weight: bold;
  403. margin-top: 1em;
  404. margin-left: -26px;
  405. }
  406. .tl
  407. {
  408. margin-bottom: .75em;
  409. }
  410. .atl
  411. {
  412. padding-left: 1.5em;
  413. padding-bottom: .75em;
  414. }
  415. .cfe
  416. {
  417. font-weight: bold;
  418. }
  419. .mini
  420. {
  421. font-size: smaller;
  422. }
  423. .dt
  424. {
  425. margin-bottom: -.6em;
  426. }
  427. .indent
  428. {
  429. margin-left: 1.9em;
  430. margin-right: 1.9em;
  431. }
  432. .product
  433. {
  434. text-align: right;
  435. color: #333333;
  436. font-size: smaller;
  437. font-style: italic;
  438. }
  439. .buttonbarshade
  440. {
  441. position: relative;
  442. margin: 0;
  443. left: 0px;
  444. top: 2;
  445. width: 50%;
  446. height: 40px;
  447. }
  448. .buttonbartable
  449. {
  450. position: absolute;
  451. margin: 0;
  452. padding:0;
  453. border:0;
  454. left:0px;
  455. top: 2;
  456. width: 100%;
  457. height: 40px;
  458. }
  459. /* background color, font for header */
  460. table.buttonbartable td, table.buttonbarshade td
  461. {
  462. background: #ffffff; /*#5177B8; #80C615;*/
  463. border-left: 0px solid #80C615;
  464. margin: 0;
  465. padding: 0px 0px 0px 0px;
  466. font-family: Impact, sans-serif;
  467. font-size: 14pt;
  468. }
  469. table.buttonbartable td.button1
  470. {
  471. background: #5177B8; /*#80C615;*/;
  472. padding: 0;
  473. font-weight: bold;
  474. text-align: center;
  475. cursor: hand;
  476. }
  477. table.buttonbartable td.button2
  478. {
  479. background: #5177B8; /*#80C615;*/;
  480. font-weight: bold;
  481. text-align: center;
  482. }
  483. table.buttonbartable td.button3
  484. {
  485. background: #5177B8; /*#80C615;*/;
  486. font-weight: bold;
  487. text-align: center;
  488. }
  489. table.buttonbartable td.runninghead
  490. {
  491. padding-left: 0px;
  492. font-style: italic;
  493. text-align: left;
  494. }
  495. .version
  496. {
  497. text-align: left;
  498. color: #000000;
  499. margin-top: 3em;
  500. margin-left: -26px;
  501. font-size: smaller;
  502. font-style: italic;
  503. }
  504. .lang, .ilang
  505. {
  506. color: #0000ff;
  507. font: normal 7pt Arial, Helvetica, sans-serif;
  508. }
  509. div.langMenu
  510. {
  511. position: absolute;
  512. z-index: 1;
  513. width: 96pt;
  514. padding: 8pt;
  515. visibility: hidden;
  516. border: 1px solid #000000;
  517. background: #ffffd0;
  518. }
  519. div.langMenu ul
  520. {
  521. padding-left: 2em;
  522. margin-left: 0;
  523. }
  524. div.filtered
  525. {
  526. margin: 4pt 0 8pt -26px;
  527. padding: 4px 4px 8px 26px;
  528. width: 100%;
  529. border: 2px solid #aaaacc;
  530. background: #ffffff;
  531. }
  532. div.filtered2
  533. {
  534. margin: 4pt 0 8pt -26px;
  535. padding: 4px 4px 8px 26px;
  536. width: 100%;
  537. border: none;
  538. background: #ffffff;
  539. }
  540. div.filtered h1, div.filtered h2, div.filtered h3, div.filtered h4
  541. {
  542. margin-left: -22px;
  543. }
  544. div.filtered span.lang
  545. {
  546. position: relative;
  547. left: -22px;
  548. }
  549. div.reftip
  550. {
  551. position: absolute;
  552. z-index: 1;
  553. padding: 8pt;
  554. visibility: hidden;
  555. border: 1px solid #000000;
  556. background: #ffffd0;
  557. }
  558. a.synParam
  559. {
  560. color: #0000FF;
  561. /*color: #3F7800;*/
  562. /*color: #8DC54F;*/
  563. text-decoration: none;
  564. font-weight: normal;
  565. }
  566. a.synParam:hover
  567. {
  568. text-decoration: underline;
  569. font-weight: normal;
  570. }
  571. div.sapop
  572. {
  573. position: absolute;
  574. z-index: 1;
  575. left: 26px;
  576. width: 100%;
  577. padding: 10px 10px 10px 36px;
  578. visibility: hidden;
  579. border: 1px solid #000000;
  580. background: #ffffd0;
  581. }
  582. div.footer
  583. {
  584. width: 100%;
  585. border: none;
  586. background: #ffffff;
  587. margin-top: 18pt;
  588. padding-bottom: 12pt;
  589. color: #0000FF;
  590. /*color: #228B22; */
  591. text-align: center;
  592. font-size: 76%;
  593. }
  594. div.preliminary
  595. {
  596. margin-top: 8pt;
  597. padding-bottom: 12pt;
  598. color: #A0A0A0;
  599. }
  600. /* A procedure section. eg. 'To create a file', 'To add a value' */
  601. div.proc
  602. {
  603. margin-left: 0.5em;
  604. }
  605. /* The title of a 'procedure' section. */
  606. div.proc h3
  607. {
  608. font-family: Verdana, Arial, Helvetica, sans-serif;
  609. font-weight: bold;
  610. font-size: 115%;
  611. margin-top: 1em;
  612. margin-bottom: 0.4em;
  613. margin-left: -0.5em;
  614. color: #003399;
  615. }
  616. div.proc ul
  617. {
  618. margin-left: 1.5em;
  619. }
  620. div.proc ol
  621. {
  622. margin-left: 2.0em;
  623. }
  624. .note
  625. {
  626. margin-left: 14pt;
  627. margin-right: 12pt;
  628. }
  629. .indent1
  630. {
  631. margin-left: 12pt;
  632. }
  633. .indent2
  634. {
  635. margin-left: 24pt;
  636. }
  637. .indent3
  638. {
  639. margin-left: 36pt;
  640. }
  641. p.proch
  642. {
  643. padding-left: 16px;
  644. }
  645. p.proch img
  646. {
  647. position: relative;
  648. vertical-align: top;
  649. left: -18px;
  650. margin-right: -14px;
  651. margin-bottom: -18px;
  652. }
  653. div.clsPlatSpec
  654. {
  655. background-color:#FFF8DC;
  656. border-style:solid;
  657. border-width:1pt 0pt 0pt 1pt;
  658. border-color:#ffE4C4;
  659. margin-top:0.6em;
  660. width:100%;
  661. }
  662. /* Applies to the language labels in the Language Filter drop-down list. */
  663. .languageFilter
  664. {
  665. color: #0000FF;
  666. cursor:hand;
  667. text-decoration:underline;
  668. padding-bottom:4;
  669. }
  670. /* Dropdown areas */
  671. #languageSpan {
  672. position: absolute;
  673. visibility: hidden;
  674. border-style: solid;
  675. border-width: 1px;
  676. border-color: #C8CDDE;
  677. background: #d4dfff;
  678. padding: 4px;
  679. font-size: 70%;
  680. }
  681. #membersOptionsSpan {
  682. position: absolute;
  683. visibility: hidden;
  684. border-style: solid;
  685. border-width: 1px;
  686. border-color: #C8CDDE;
  687. background: #d4dfff;
  688. padding: 4px;
  689. font-size: 70%;
  690. }
  691. --></style>
  692. <xml>
  693. <MSHelp:TOCTitle Title="Flocking Sample" />
  694. <MSHelp:RLTitle Title="Flocking Sample" />
  695. <MSHelp:Keyword Index="A" Term="O:Microsoft.Xna.Flocking" />
  696. <MSHelp:Keyword Index="A" Term="398f9c2c-f42f-5ea8-9bb4-ed2e946c5012" />
  697. <MSHelp:Keyword Index="K" Term="Flocking Sample" />
  698. <MSHelp:Attr Name="ProjType" Value="LocalProj" />
  699. <MSHelp:Attr Name="ProjType" Value="XNA_30" />
  700. <MSHelp:Attr Name="DocSet" Value="XNA" />
  701. <MSHelp:Attr Name="DocSet" Value="ExpressLibVS" />
  702. <MSHelp:Attr Name="DocSet" Value="C#" />
  703. <MSHelp:Attr Name="Locale" Value="en-us" />
  704. <MSHelp:Attr Name="CommunityContent" Value="1" />
  705. <MSHelp:Attr Name="AssetID" Value="398f9c2c-f42f-5ea8-9bb4-ed2e946c5012" />
  706. <MSHelp:Attr Name="TopicType" Value="kbOrient" />
  707. </xml>
  708. </head><body><div id="mainSection"><div id="mainBody">
  709. <h1>Flocking Sample</h1>
  710. This sample demonstrates how AIs can use simple rules to move together and create complex behaviors.
  711. <a name="ID2EK"></a><h1 class="heading">Sample Overview</h1><div id="ID2EK" class="hxnx1">
  712. <p>
  713. When programming the AI for your game, you often want your actors to move and react together without having to behave identically. For example, you might want to simulate a school of fish that all swim together without a centralized control or a battalion of soldiers that can march together in formation around obstacles.
  714. This sample demonstrates some of these behaviors. The sample has a flock of birds that fly to, and in the same direction as, other birds they see nearby. The sample also has a cat that you can turn on and who then chases the birds as they run away.
  715. This sample is based on the Chase and Evade sample, and assumes that the reader is familiar with the code and concepts explained in that sample.
  716. </p>
  717. <p>This sample uses the following controls.</p>
  718. <table>
  719. <tr>
  720. <th>Action</th>
  721. <th style="width: 192px">Windows Phone</th>
  722. <th>Windows - Keyboard Control</th>
  723. <th>Windows/Xbox - Gamepad Control</th>
  724. </tr>
  725. <tr>
  726. <td>Select the tuning parameter.</td>
  727. <td style="width: 192px"><strong>DRAG</strong> tuning bar</td>
  728. <td>UP ARROW, DOWN ARROW</td>
  729. <td>D-Pad Up and Down</td>
  730. </tr>
  731. <tr>
  732. <td>Increase/decrease the tuning parameter.</td>
  733. <td style="width: 192px"><strong>DRAG </strong>tuning bar</td>
  734. <td>LEFT ARROW, RIGHT ARROW</td>
  735. <td>
  736. D-Pad Left and Right, Left and Right Triggers</td>
  737. </tr>
  738. <tr>
  739. <td>Reset the bird flock.</td>
  740. <td style="width: 192px"><strong>TAP</strong> &quot;Reset Flock&quot; button</td>
  741. <td>X</td>
  742. <td>
  743. X</td>
  744. </tr>
  745. <tr>
  746. <td>Reset the tuning parameters.</td>
  747. <td style="width: 192px"><strong>TAP</strong> &quot;Reset Distance&quot; button</td>
  748. <td>B</td>
  749. <td>B</td>
  750. </tr>
  751. <tr>
  752. <td>Add/remove the cat</td>
  753. <td style="width: 192px"><strong>TAP</strong> &quot;Add/Remove Cat&quot; button</td>
  754. <td>Y</td>
  755. <td>
  756. Y</td>
  757. </tr>
  758. <tr>
  759. <td>Move the cat.</td>
  760. <td style="width: 192px"><strong>TAP </strong>or <strong>DRAG </strong>
  761. on screen</td>
  762. <td>W, S, A, D</td>
  763. <td>
  764. Left Thumbstick</td>
  765. </tr>
  766. <tr>
  767. <td>Exit the game.</td>
  768. <td style="width: 192px"><strong>BACK</strong></td>
  769. <td>ESC or ALT+F4</td>
  770. <td>
  771. <b>BACK</b>
  772. </td>
  773. </tr>
  774. </table>
  775. </div>
  776. </div>
  777. <a name="ID2EHE"></a><h1 class="heading">How the Sample Works</h1><div id="ID2EHE" class="hxnx1">
  778. <p>
  779. &nbsp;</p>
  780. <h2 class="subHeading">Flocking Behavior</h2>
  781. <div id="ID2E1D" class="hxnx2">
  782. <p>Flocking behavior is controlled by three simple behaviors:
  783. cohesion, alignment, and separation. Other behaviors can be present,
  784. but they are not required. In this sample, the birds also have a
  785. flee behavior. </p>
  786. <p>Cohesion is the birds’ tendency to fly together with others.
  787. Alignment is the birds’ tendency to fly in the same direction as
  788. other birds. Separation is the birds’ tendency to fly away from
  789. others that are too close. Fleeing is the birds’ tendency to avoid
  790. dangerous things. </p>
  791. <a name="ID2ECE"></a>
  792. <h4 class="subHeading">Cohesion</h4>
  793. <div id="ID2ECE" class="hxnx3">
  794. <p>Each bird flies towards others it can see. To make one bird
  795. fly closer to another, for each other bird inside its <b>
  796. detectionDist</b> value, the bird changes its <b>direction</b>
  797. towards the other bird in proportion to its <b>
  798. moveInFlockDirInfluence</b> setting and according to how close
  799. it is to the midpoint between its <b>detectionDist</b> and <b>
  800. separationDist</b> values. </p>
  801. </div>
  802. <a name="ID2EUE"></a>
  803. <h4 class="subHeading">Alignment</h4>
  804. <div id="ID2EUE" class="hxnx3">
  805. <p>Each bird flies in the general direction of others it can
  806. see. To make one bird line up with another, for each other bird
  807. inside its <b>detectionDist</b> value, the bird adds the <b>
  808. direction</b> the other bird is facing to its own <b>direction</b>
  809. in proportion to its <b>moveInFlockDirInfluence</b> setting. </p>
  810. </div>
  811. <a name="ID2EEF"></a>
  812. <h4 class="subHeading">Separation</h4>
  813. <div id="ID2EEF" class="hxnx3">
  814. <p>Each bird flies away from others that that are too close. For
  815. each other bird inside both its <b>detectionDist</b> <i>and</i>
  816. its <b>separationDist</b> values, the bird applies the
  817. separation rule instead of the cohesion rule. To move one bird a
  818. comfortable distance away from another, the bird adds the
  819. opposite of the direction towards the other bird&#39;s direction to
  820. its <b>direction</b> in proportion to its <b>
  821. moveInFlockDirInfluence</b> setting and according to the ratio
  822. of how close the other bird is relative to its <b>separationDist</b>
  823. value. </p>
  824. </div>
  825. <a name="ID2EYF"></a>
  826. <h4 class="subHeading">Flee</h4>
  827. <div id="ID2EYF" class="hxnx3">
  828. <p>Each bird flies away from the cat if the bird can see the
  829. cat. To move a bird away from the cat, if the cat is inside the
  830. bird&#39;s <b>detectionDist</b> and the bird isn&#39;t already moving
  831. away from the cat, the bird adds the opposite of the direction
  832. towards the cat to its <b>direction</b> value.</p>
  833. </div>
  834. </div>
  835. </div>
  836. <a name="ID2EAH"></a><h1 class="heading">Extending the Sample</h1><div id="ID2EAH" class="hxnx1">
  837. <ul>
  838. <li>Make one bird in the flock the leader and give it the wander
  839. behavior from the Chase and Evade sample. Then make the other birds
  840. in the flock follow the leader. </li>
  841. <li>Add different colored flocks and make the birds fly with their
  842. own kind and avoid other birds. </li>
  843. <li>Add formations. </li>
  844. <li>Add predator birds that chase the others.</li>
  845. </ul>
  846. </div>
  847. </div><div class="footer" id="footer"><p>© 2010 Microsoft Corporation. All rights reserved.<br>Send feedback to
  848. <a href="mailto:[email protected]?subject=Documentation Feedback: Flocking Sample">
  849. [email protected]</a>.</p></div></div></body></html>