{"id":1,"date":"2011-08-01T16:50:54","date_gmt":"2011-08-01T14:50:54","guid":{"rendered":"http:\/\/kahrstrom.com\/gamephysics\/?p=1"},"modified":"2024-03-23T16:22:54","modified_gmt":"2024-03-23T16:22:54","slug":"hello-world","status":"publish","type":"post","link":"http:\/\/kahrstrom.com\/gamephysics\/2011\/08\/01\/hello-world\/","title":{"rendered":"First Post"},"content":{"rendered":"<p>So, I thought I&#8217;d try playing around with game physics. A long time ago, when I was about 14, I started programming. I really wanted to become a game programmer, and started learning C and C++, writing DOS programs on my 486. Writing directly to video memory (0A000h) in VGA mode 13h, optimizing the code with little assembler snippets. My highpoint was a demo for a friends <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bulletin_board_system\">BBS<\/a>\u00a0written completely in assembler, with a lovely lens effect and flames:<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/eQkB6SipJkU\" frameborder=\"0\" width=\"425\" height=\"349\"><\/iframe><\/p>\n<p>Soon though, my interest shifted more towards physics, and later mathematics, and I ended up with a PhD in mathematics earned by investigating wonderful properties of infinite dimensional representations of semi-simple Lie algebras. Now, many years down the line, my interest has move back towards programming, and I&#8217;ve decided to try and understand at least the basics of game physics modeling.<\/p>\n<p>So, I started looking at simple integration methods. I was well acquainted with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Euler_integration\">Euler<\/a> and <a href=\"http:\/\/en.wikipedia.org\/wiki\/Runge-kutta\">Runge-Kutta<\/a> integration, but soon read about <a href=\"http:\/\/en.wikipedia.org\/wiki\/Verlet_integration\">Verlet integration<\/a>. Whereas in Euler integration you keep track of the position and velocity of a particle, in Verlet integration you keep track of the current and previous position of a particle. In that respect, they are equivalent, since you can get a velocity from the current and previous position, and vice versa. Where they differ are in the dynamics, how the new data are computed based on the current acceleration.<\/p>\n<p>In Euler integration, you do<\/p>\n<p>\\(p_1 = p_0 + \\Delta t v_0\\),<br \/>\n\\(v_1 = v_0 + \\Delta t a_0\\),<\/p>\n<p>where \\(v_0\\) and \\(p_0\\) are the previous position and velocity, \\(v_1\\) and \\(p_1\\) are the new position and velocity, \\(\\Delta t\\) is the time difference between frames, and \\(a_0\\) is the acceleration. Basically, at each time point you extrapolate what the position and velocity will be in the future based on the current velocity, position and acceleration.<\/p>\n<p>In Verlet integration, you do the following instead:<\/p>\n<p>\\(p_1 = 2p_0 &#8211; p_{-1} + \\Delta t^2a_0\\),<\/p>\n<p>where \\(p_0\\) is the current position, \\(p_{-1}\\) is the previous position, and \\(p_1\\) is the next position. If we solve the above equation for \\(a_0\\), we get<\/p>\n<p>\\(\\displaystyle a_0 = \\frac{p_1 &#8211; 2p_0 + x_{-1}}{\\Delta t^2} = \\frac{(p_1 &#8211; p_0) &#8211; (p_0 &#8211; p_{-1})}{\\Delta t^2} = \\frac{\\frac{p_1 &#8211; p_0}{\\Delta t} &#8211; \\frac{p_0 &#8211; p_{-1}}{\\Delta t}}{\\Delta t}\\).<\/p>\n<p>Getting creative with our notation, we can write this as<\/p>\n<p>\\(\\displaystyle a_0 = \\frac{v_{\\scriptstyle 1\/2} &#8211; v_{-1\/2}}{\\Delta t}\\),<\/p>\n<p>i.e. we effectively use the velocity between our timepoints to compute the new positon \\(p_1\\). For various reasons, this gives a much better approximation than Euler integration. Actually, if the acceleration is constant, Verlet integration gives exact results.<\/p>\n<p>So, to try this out I wrote a little test using OpenGL of a ball on a string affected by gravity, using Verlet integration. The string is modelled as a sequence of stiff springs, so in this example I also have constraints on the position of the endpoints of the springs, but I&#8217;ll leave that for the next point.<\/p>\n<p><iframe loading=\"lazy\" src=\"http:\/\/www.youtube.com\/embed\/u6Rl8YxeXLo\" frameborder=\"0\" width=\"560\" height=\"349\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I thought I&#8217;d try playing around with game physics. A long time ago, when I was about 14, I started programming. I really wanted to become a game programmer, and started learning C and C++, writing DOS programs on my 486. Writing directly to video memory (0A000h) in VGA mode 13h, optimizing the code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[5],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-integration","tag-integration"],"_links":{"self":[{"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":10,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":193,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/posts\/1\/revisions\/193"}],"wp:attachment":[{"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kahrstrom.com\/gamephysics\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}