Log In  
Log In  



I would like to add a basic 3d outside view to my flight sim project Tiny Sim. 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<0 it fails miserably for z>=0: the runway is somehow mirrored in the upper half of the screen.

rwy = {{{-1,0,0}, --points
       {{1,2}, --lines

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]<0) cam[2]=0
  if btn(4) then cam[3] -= 0.1 end
  if btn(5) then cam[3] += 0.1 end

function _draw()

  for i=1, 14 do

function draw_shape(s,c)
  for l in all(s[2]) do
    draw_line(s[1][l[1]], s[1][l[2]], c)

function draw_line(p1,p2,c)
  x0, y0 = project(p1)
  x1, y1 = project(p2)
  line(x0, y0, x1, y1, c or 6)

function draw_point(p,c)
  x, y = project(p)
  pset(x, y, c or 11)

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

--functions for roll, pitch and yaw

Runway being displayed correctly (z<0):

Runway with wrong projection (z>=0):

I split up the projection function for z<0 and z>=0 but did not find the right formula for z>=0 yet:

function project(p)
  if cam[3]<=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
    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

Any help is much appreciated!

P#59388 2018-11-27 14:46

Cart [#tenkizoti-0#] | Code | 2018-12-19 | License: CC4-BY-NC-SA | Embed

Change log:
0.5: finally got around to add a basic 3D outside view. Caveat: 3D only does pitch and yaw. Roll does not work yet, any help is greatly appreciated!


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.)

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.

Starting the program, you can choose between different scenarios (visual approach, final approach, full approach, engine failure and unusual attitudes; more scenarios to come). Here is what you need to know:

  • Tab toggles between flying mode and map/pause mode. Your flight path is shown in yellow.
  • Arrow keys control pitch and roll
  • X/Z control throttle. RPM are displayed on the lower left corner. Normal continuous operation is below 2400. Cruise flight at approx. 2200, approach at 1700-2000, final approach at 1250
  • On the left side of the display is the airspeed indicator, showing the indicated airspeed (IAS). Never exceed speed is 163 Knots IAS. Stall speed is around 40 Knots IAS.
  • To the right of the AI are the altimeter (feet) and vertical speed indicator (VSI, 100s of feet per minute).
  • On the bottom left is a small inset map, showing the airplane symbol as well as navigation aids (blue dots) and airports (pink dots).
  • In the lower half of the display is the horizontal situation indicator (HSI), which shows the current heading (on top), instrument landing system localizer (green arrow), the bearing to a navigation aid (blue arrow) as well as the distance to it in nautical miles (lower right)
  • The small arrow left of the HSI shows where the wind is coming from
  • There is a timer (minutes:seconds)
  • On the left side of the screen you can see the throttle (lever position and RPM) as well as the flaps indicator (press Q to toggle, lower flaps below 110 Knots IAS).
  • At the very top of the screen you can see the distance to your selected GPS waypoint and your ground speed (GS).
  • Note that the colors on the navigation instruments corresponds to the map symbols (green, blue, pink).
  • To successfully land, touch down with runway heading +/- 5 degrees, below 65 knots, wings level, positive pitch (i.e. nose slightly up) and a vertical speed of not more than -300 feet/min.

Here is the real display on a flight in the Swiss alps to compare:

P#20854 2016-05-19 08:30 ( Edited 2018-12-19 09:32)

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-03-24 19:16 | 0.050s | 4194k | Q:23