{"id":152,"date":"2025-09-25T00:57:52","date_gmt":"2025-09-25T00:57:52","guid":{"rendered":"https:\/\/leonwoud.com\/devblog\/?p=152"},"modified":"2025-09-25T00:57:54","modified_gmt":"2025-09-25T00:57:54","slug":"mazes-now-in-3d","status":"publish","type":"post","link":"https:\/\/leonwoud.com\/devblog\/mazes-now-in-3d\/","title":{"rendered":"Mazes now in 3D!"},"content":{"rendered":"\n<p>Probably a surprise to no one, but while going through the maze generation exercise I thought it would be nice to display a maze in 3d. <\/p>\n\n\n\n<p>There is (though I haven&#8217;t gotten to it yet) an entire section of the <a href=\"http:\/\/mazesforprogrammers.com\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Mazes for Programmers<\/a> book dedicated to generating mazes that wrap around 3d shapes, like mazes on cubes, spheres, even a m\u00f6bius strip!<\/p>\n\n\n\n<p>Displaying a maze in 3d isn&#8217;t in the scope of the book, but it&#8217;s not hard to take the concepts and translate them to 3d.<\/p>\n\n\n\n<p>So I&#8217;m back in <code>p5.js<\/code> looking at its Web GL canvas. Getting a simple grid maze to display in 3d was no problem, just a few minutes of trial and error getting the walls to draw in the correct orientation.<\/p>\n\n\n\n<p>I did run into issues with the <code>camera<\/code>. A skill issue on my end, it&#8217;s just not how I&#8217;m used to thinking about 3d cameras. I was trying to get the a camera to traverse the maze along a given path.<\/p>\n\n\n\n<p>While trying to figure out these issues (looking the wrong way, spinning around in circles, clipping through walls, being in the completely wrong place) I ended up creating a debug scene which I&#8217;ll share. <\/p>\n\n\n\n<p>Here you can see a red arrow taking the path the camera would take, pointing in the direction the camera should be pointing. Taking the little bit of a time to set this up helped me solve all the issues with positioning \/ orienting things the correct way, so that is a win.<\/p>\n\n\n\n<p>This example is using the &#8216;Orbit Control&#8217; built into <code>p5.js<\/code>, you can use the middle-mouse to zoom in-out, left-button to rotate and right-button to pan.<\/p>\n\n\n\n<p><a href=\"https:\/\/www.leonwoud.com\/mazes\/02\/index.html\">https:\/\/www.leonwoud.com\/mazes\/02\/index.html<\/a><\/p>\n\n\n\n<iframe src=\"https:\/\/www.leonwoud.com\/mazes\/02\/index.html\" width=\"100%\" height=\"850px\" style=\"border: 0;\"><\/iframe>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Probably a surprise to no one, but while going through the maze generation exercise I thought it would be nice to display a maze in 3d. There is (though I haven&#8217;t gotten to it yet) an entire section of the Mazes for Programmers book dedicated to generating mazes that wrap [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"bgseo_title":"","bgseo_description":"","bgseo_robots_index":"index","bgseo_robots_follow":"follow","footnotes":""},"categories":[14],"tags":[15,13,16,17],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-mazes","tag-3d","tag-maze","tag-p5-js","tag-webgl"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/comments?post=152"}],"version-history":[{"count":1,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":154,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/posts\/152\/revisions\/154"}],"wp:attachment":[{"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/media?parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/categories?post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leonwoud.com\/devblog\/wp-json\/wp\/v2\/tags?post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}