yellowbaron [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=12916 3d projection issue <p>Hi,<br /> I would like to add a basic 3d outside view to my flight sim project <a href="https://www.lexaloffle.com/bbs/?tid=3393">Tiny Sim</a>. For this I started with the code below, which is just showing a simplified runway (essentially, a rectangle with some points). I am trying to get the projection function right and while it works for z&lt;0 it fails miserably for z&gt;=0: the runway is somehow mirrored in the upper half of the screen.</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>rwy = {{{-1,0,0}, --points {-1,0,30}, {1,0,30}, {1,0,0}}, {{1,2}, --lines {2,3}, {3,4}, {4,1}}, 4} cam = {0,1,-4} mult = 64 sp = 0.01 function _update() if btn(0) then cam[1] -= 0.1 end if btn(1) then cam[1] += 0.1 end if btn(2) then cam[2] += 0.1 end if btn(3) then cam[2] -= 0.1 end if(cam[2]&lt;0) cam[2]=0 if btn(4) then cam[3] -= 0.1 end if btn(5) then cam[3] += 0.1 end end function _draw() cls() print(&quot;x=&quot;..cam[1],0,6*1) print(&quot;y=&quot;..cam[2],0,6*2) print(&quot;z=&quot;..cam[3],0,6*3) draw_shape(rwy) for i=1, 14 do draw_point({0,0,i*2},7) end draw_point({-0.5,0,2},7) draw_point({0.5,0,2},7) end function draw_shape(s,c) for l in all(s[2]) do draw_line(s[1][l[1]], s[1][l[2]], c) end end function draw_line(p1,p2,c) x0, y0 = project(p1) x1, y1 = project(p2) line(x0, y0, x1, y1, c or 6) end function draw_point(p,c) x, y = project(p) pset(x, y, c or 11) end function project(p) x = (p[1]-cam[1])*mult/(p[3]-cam[3]) + 127/2 y = -(p[2]-cam[2])*mult/(p[3]-cam[3]) + 127/2 return x, y end --functions for roll, pitch and yaw</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Runway being displayed correctly (z&lt;0):</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/3dsim_000.png" alt="" /> <p>Runway with wrong projection (z&gt;=0):</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/3dsim_001.png" alt="" /> <p>I split up the projection function for z&lt;0 and z&gt;=0 but did not find the right formula for z&gt;=0 yet:</p> <div> <div style="max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>function project(p) if cam[3]&lt;=0 then x = (p[1]-cam[1])*mult/(p[3]-cam[3]) + 127/2 y = -(p[2]-cam[2])*mult/(p[3]-cam[3]) + 127/2 else x = (p[1]+cam[1])*mult/(p[3]+cam[3]) + 127/2 y = -(p[2]+cam[2])*mult/(p[3]+cam[3]) + 127/2 end return x, y end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Any help is much appreciated!</p> https://www.lexaloffle.com/bbs/?tid=32336 https://www.lexaloffle.com/bbs/?tid=32336 Tue, 27 Nov 2018 14:46:09 UTC Tiny Sim <p> <table><tr><td> <a href="/bbs/?pid=20854#p"> <img src="/bbs/thumbs/pico8_tenkizoti-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=20854#p"> Tiny Sim 1.1</a><br><br> by <a href="/bbs/?uid=12916"> yellowbaron</a> <br><br><br> <a href="/bbs/?pid=20854#p"> [Click to Play]</a> </td></tr></table> </p> <h3>Hi Aviator!</h3> <p>This is a tiny flight simulator based on a Cessna-172R with a G1000 glass cockpit. (This is the plane I fly in real life, so I thought it would be a challenge to see if it can be done with Pico-8.) </p> <p>The flight model is not based on theory but on my observations as a pilot. I have to say that it's quite good ;-) Within the limits of Pico-8 it quite feels like the real thing.</p> <p><strong>Disclaimer:</strong> while I created the instruments and the flight model, the majority of the programming work was done by <a href="https://www.lexaloffle.com/bbs/?uid=25532"><a href="https://www.lexaloffle.com/bbs/?uid=25532"> @freds72</a></a>, including 3D outside view, code structure, eye candy, music, etc. Many thanks Fred, this would not have been possible without your ninja programming skills!!</p> <p>If you want to go flying right away, the cheatsheet will get you in the air in less than 1 minute:</p> <p><a href="https://www.lexaloffle.com/bbs/files/12916/Cheatsheet.png" target=_view_image><img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/Cheatsheet.png" width=156 height=160 alt="" /></a></p> <p>If you are more the serious type, there is a 34-page <a href="https://drive.google.com/open?id=1nuQb7-b5rt0Hrfiyq7UBZMbsBKLwfZhi">flight manual</a>, which explains everything in detail and features 20+ flight lessons.</p> <p><a href="https://drive.google.com/open?id=1nuQb7-b5rt0Hrfiyq7UBZMbsBKLwfZhi"><img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/manual_s.png" alt="" /></a></p> <p>We also created an entire area you can fly in (with a mountain, an island, ships and much more):</p> <p><a href="https://www.lexaloffle.com/bbs/files/12916/Aeronautical chart.png" target=_view_image><img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/Aeronautical chart.png" width=160 height=160 alt="" /></a></p> <p>Just as a sneak preview, here are some of the things you can do:</p> <p>Smooth landings</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/tinysim_v10_0.gif" alt="" /> <p>High speed buzzing</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/tinysim_v10_1.gif" alt="" /> <p>Illegal low-level flying at night</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/tinysim_v10_42.gif" alt="" /> <p>Instrument flying in the clouds</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/tinysim_v10_5.gif" alt="" /> <p>Here is the real cockpit on a flight in the Swiss alps to compare:</p> <img style="" border=0 src="https://www.lexaloffle.com/bbs/files/12916/DSC_2407.JPG" width=840 height=554 alt="" /> <h3>Update 1.1</h3> <ul> <li>fixed polygon gaps</li> <li>added collision detection for wind turbines</li> </ul> https://www.lexaloffle.com/bbs/?tid=3393 https://www.lexaloffle.com/bbs/?tid=3393 Thu, 19 May 2016 08:30:44 UTC