{"id":673,"date":"2013-11-24T13:53:26","date_gmt":"2013-11-24T12:53:26","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=673"},"modified":"2013-11-24T13:53:26","modified_gmt":"2013-11-24T12:53:26","slug":"vb-net-and-xna-article-13-first-steps-with-farseer-physics-engine","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=673","title":{"rendered":"VB.Net and XNA : Article 13 &#8211; First steps with Farseer Physics Engine"},"content":{"rendered":"<p>In previous articles, we have seen many basics which should help to make a game : scrolling, moving shapes, collision, inputs (mouse, keyboard, gamepad)&#8230;<\/p>\n<p>However, you may sometimes need to implement some physic principles : gravity, friction, restitution, etc.<\/p>\n<p>This is where <a href=\"http:\/\/farseerphysics.codeplex.com\/\" target=\"_blank\">Farseer Physics Engine<\/a> comes to the rescue.<br \/>\nFarseer Physics Engine is a collision detection system with realistic physics responses.<\/p>\n<p>2 importants concepts to start with :<br \/>\n&#8211;<strong>World<\/strong><br \/>\nThe world object is the manager of it all. It iterates all the objects in the world each time you call the Step() function and makes sure everything is consistent and stable.<br \/>\n&#8211;<strong>Body <\/strong><br \/>\nThe body keeps track of world position. It is basically a point is space that is affected by forces such as impulses from collisions and gravity.<\/p>\n<p>Lets add a project reference to farseer (note : I used msbuild \/property:configuration=release \u00ab\u00a0Farseer Physics XNA.csproj\u00a0\u00bb to build it).<br \/>\nThen we will create a world, add a body to it and draw a texture based on the body position.<\/p>\n<p>I encourage you to play with the world properties such as restitution, friction etc to see how it affects your world.<br \/>\nAlso, notice how easy it is to detect collision (although I manage only plain shape for now, no convex shapes).<\/p>\n<p>The source code : <a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/XNA_DEMO_19.zip\">XNA_DEMO_19<\/a><\/p>\n<p>A video to illustrate it.<\/p>\n<div style=\"width: 695px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-673-1\" width=\"695\" height=\"386\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/farseer1.mp4?_=1\" \/><a href=\"https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/farseer1.mp4\">https:\/\/labalec.fr\/erwan\/wp-content\/uploads\/2013\/11\/farseer1.mp4<\/a><\/video><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In previous articles, we have seen many basics which should help to make a game : scrolling, moving shapes, collision, inputs (mouse, keyboard, gamepad)&#8230; However, you may sometimes need to implement some physic principles : gravity, friction, restitution, etc. This is where Farseer Physics Engine comes to the rescue. Farseer Physics Engine is a collision <a href='https:\/\/labalec.fr\/erwan\/?p=673' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,35],"tags":[],"class_list":["post-673","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-xna","category-34-id","category-35-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=673"}],"version-history":[{"count":1,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":676,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions\/676"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}