Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: Airplane new "fly-by" camera addition - working !  (Read 11111 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Airplane new "fly-by" camera addition - working !
« on: September 23, 2018, 06:33:34 am »

Most recent updated version at the end of the topic !


From my experience with flight simulation I knew that to enjoy fully the flying in outerra the availability of different camera views is very important, adding a lot to realism. With pleasure I discoverd that the cessna172 has allready several first person view onboard cameras that can be accessed simply by pressing the "change seat" key "v" (see outerra menu / air under advanced settings) and these can me modified in the javascript file of the plane if desired. However an important camera - known to all flightsimmers is missing: a fly-by camera placing an "external observer" on the predicted flightpath of the plane at some distance ahead of the plane to observe the plane flying by, simply by pressing the v key.  So I decided to add another onboard camera- this time however not a stationary one fixed to the plane, but a "dynamic" one that moves relative to the plane compensating the instantaneous motion of the plane as much as I could achieve. The effect is as if an (allmost fixed) external observer looks at the plane while flying by. Fly-by parameters such as nearest fly-by distance, range or if you wish duration of fly-by, level of the camera above or below the expected flight path are changed randomly for each fly-by within preset ranges. I am working also on a "ground-level camera", observing the plane always from ground as it flies by, plus an "airport camera" fixed at the airport (would allow flying the plane from remote as RC plane), using the same principle but this is still WIP.

Here is the download link for the otx file of my  mig29 camera mod with fly-by camera and some other new cameras included. The plane will appear in the aircraft menu as "fly77/mig29flyby/mig29"
Once spawned press "v" repeatedly until you come accross the fly-by camera.


https://www.dropbox.com/s/sehnh9ql0e81ryj/mig29flyby.otx?dl=0

Below is the code that you need to clip into your airplane javascript file...but read carefully the instructions below and in any case backup your files before doing any modification.

Here is a video of a flight I recorded in Norway, some Fjord flying. Enjoy !  - Sorry for the bad take-off :-) ...had to take care of the camera with my mouse.  A second video shows the effect of the camera mounted on a MIG29 fulcrum - flying an imaginary bombing mission near Frankfurt. ..Enjoy !  Adding the camera only takes adding a few lines of code to the javascript file of any of the airplane models.





Below is the addition to the javascipt file of the model  for the default  MIG29 Fulcrum , that had just one camera (the pilot camera). Note that besides the fly-by camera I added also all the other fixed fps cameras 1 to 9 (wings, bombs etc views). For a plane that allready has these views add only the last (for me ist camera 10) which is the fly-by camera. I suggest you to test it on the MIG29 before you try it on other planes.


On the header of the file add:

Code: [Select]

//---------------------------------------------
//      section added for different cameras ,
//       including fly-by camera
//--------------------------------------------

var seat_cam = 0;
function switch_seat(cam)
{
 if(cam===0)   seat_cam=0;
   else if(cam===1)seat_cam=1;
   else if(cam===2)seat_cam=2;
   else if(cam===3)seat_cam=3;
   else if(cam===4)seat_cam=4;
   else if(cam===5)seat_cam=5;
   else if(cam===6)seat_cam=6;
   else if(cam===7)seat_cam=7;
   else if(cam===8)seat_cam=8;
   else if(cam===9)seat_cam=9;
   else if(cam===10)seat_cam=10;
   else return false;
   return true;
}

var distance=0;  // fly-by camera
var flag=0; // fly-by camera
var xobs, yobs, zobs, fobs, xdist, ydist, zdist, fdist; //fly-by camera
var zobsdef ; // fly-by camera
var veast,vnorth, vdown; // fly-by camera
var psi,psi_start;  // fly-by camera  heading
var theta,theta_start;    // fly-by camera  picth
var phi,phi_start;    // fly-by camera  roll

var rangedef=150;  // fly-by camera  setup
var bypassdist= 30; // fly-by camera  setup
var zobsdef1=4 ; // fly-by camera  (may be bigger than zobsdef2 for takeoff on rough runways
var zobsdef2=4 ; // fly-by camera



function randomIntFromInterval(min,max){
    return Math.floor(Math.random()*(max-min+1)+min);
}

//---------------------------------------------
//--------------------------------------------



Then add the the indicated code below in the update frame function as indicated:

Code: [Select]
function update_frame(dt){

//Set FPS camera FOV OT World Interface
if (this.get_camera_mode() == 0){
  ot_world.set_camera_fov(fov_cockpit_zoom);
}


//---------------------------------------------
//      section added for different cameras ,
//       including fly-by camera
//--------------------------------------------


if(seat_cam===0){
    flag=0;
    this.set_fps_camera_pos({x:0.0,y:4.8,z:2.9});
  }//pilot seat

  else if(seat_cam===1){
    flag=0;
    this.set_fps_camera_pos({x: 0, y:7, z:1.2});
  }//sensor cam

  else if(seat_cam===2){
    flag=0;
    this.set_fps_camera_pos({x:0, y:-3, z:0.5});
  }//bellow cam

  else if(seat_cam===3){
    flag=0;
    this.set_fps_camera_pos({x: -6.5, y:-3, z:2.70});
  }//left wing cam

  else if(seat_cam===4){
    flag=0;
    this.set_fps_camera_pos({x:6.5,y:-3,z: 2.7});
  }//right wing cam

  else if(seat_cam===5){
    flag=0;
    this.set_fps_camera_pos({x:-1.2,y:4,z:1.8});
  }//nose cam

  else if(seat_cam===6){
    flag=0;
    this.set_fps_camera_pos({x: -3.5,y:-3,z:1.2});
  }//bomb left

  else if(seat_cam===7){
    flag=0;
    this.set_fps_camera_pos({x: 3.5,y:-3,z: 1.2});
  }//bomb right

  else if(seat_cam===8){
    flag=0;
    this.set_fps_camera_pos({x: 0,y:-8,z: 3.5});
  }//tail

  else if(seat_cam===9){
    flag=0;
    this.set_fps_camera_pos({x: 0,y:-10,z: 1.2});
  }//exhaust

  // fly-by
  else if(seat_cam===10){

    if (0.3048*this.jsbsim['position/h-agl-ft'] < 3 ){
      zobsdef=zobsdef1;
      } else {
      zobsdef=zobsdef2;
    }
 

    if (flag==0){
      xdist=0;
      ydist=0;
      zdist=0;
      fdist=0;
      psi_start=this.jsbsim['attitude/heading-true-rad'];
      theta_start=0 ; // this.jsbsim['attitude/pitch-rad'];
      phi_start=0; // this.jsbsim['attitude/roll-rad'];
      zobdsef = randomIntFromInterval(4,30);
      rangedef = randomIntFromInterval(100,800);
      bypassdist= randomIntFromInterval(30,200);

      flag=1;
    }
    else{
      psi=this.jsbsim['attitude/heading-true-rad']-psi_start;
      theta=this.jsbsim['attitude/pitch-rad']-theta_start;
      phi=this.jsbsim['attitude/roll-rad']-phi_start;
     
      veast = 0.3048 * this.jsbsim['velocities/v-east-fps'];
      vnorth = 0.3048 * this.jsbsim['velocities/v-north-fps'];
      vdown = 0.3048 * this.jsbsim['velocities/v-down-fps'];
      vabs=Math.sqrt(veast*veast+vnorth*vnorth+vdown*vdown);

      fdist = fdist + vabs * dt; // real length of path flown
      fobs = rangedef - fdist;  // distance remaining to camera

      ydist = ydist + Math.abs(vabs * Math.cos(psi)) * dt; // length of path along initial flight direction
      yobs=  rangedef - ydist;

     

      zdist = zdist - vdown * dt;  // increase if plane goes up
      zobs=  zobsdef - zdist - Math.sin(theta)*fobs + Math.sin(phi)*bypassdist;
 
     

      xdist = xdist + vabs * Math.sin(psi) * dt; // length of path perpendicular to initial flight direction
      xobs = bypassdist- xdist - Math.sin(psi)*fobs;
 
      this.set_fps_camera_pos({x: xobs, y:yobs, z:zobs});
      if (Math.sqrt(xobs*xobs+yobs*yobs+zobs*zobs)>2*rangedef ){
         flag=0;
      }
    }
  } // fly-by camera


//--------------------------------------------
//--------------------------------------------



The important parameters that you can change are the following which determine the range of values to compute
      zobdsef = randomIntFromInterval(4,30);  // how much the camera will be above the flightpath ...keep > 2 on rough runways to avoid the camera going below ground.
      rangedef = randomIntFromInterval(100,800);  // half of the total flightpath in meters
      bypassdist= randomIntFromInterval(30,200);  // closes aproach distance in meters
« Last Edit: December 02, 2018, 04:54:33 pm by fly77 »
Logged

josem75

  • Sr. Member
  • ****
  • Posts: 286
  • newbie
Re: Airplane new "fly-by" camera addition - working !
« Reply #1 on: September 23, 2018, 09:22:08 am »

Wow great job. This would be very nice adition i want time ago. Thank you very much.

I have one ask. In the rear camera of a car (can be also in a plane but example is better with car), when you are in a road which is going downwith high angle, you need to take control of the mouse for adjust camera and see the road and what you have in front.
Same way, if you follo and road go up in high angle, you again need to move camera down with mouse, because if not you cant see what you have in front of you.

In many race games camera is fixed for adjust altitude and angle. So when you go up camera go down a bit, and you go down camera go up a bit. So you just can drive and no bother with cam position.
I hope you understand what i say.
This would be posible to do in Outerra?
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Airplane new "fly-by" camera addition - working !
« Reply #2 on: September 23, 2018, 10:22:09 am »

Glad that you like the new fly-by camera video. As soon as I have "cleaned up" a little bit the script I will post it - so that it can be easily added to any airplane - and eventually also as an airplane otx file with this (and eventually other ) camera added already. 
Yes I understand what you mean. It happens to me also especially in outerra where OSM roads are sometimes very sloped (way too sloped !). As I am working also on my "drive-by" camera for vehicles applying the same principle I think it is possible. Indeed as I need anyway to detect the world position and pitch/heading/roll of the vehicle then I can use the pitch to "dynamically" adjust the camera height when the slope is above a certain threshold. I need to practice with object ECEF coordinates first though.
« Last Edit: September 23, 2018, 10:29:52 am by fly77 »
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Airplane new "fly-by" camera addition - working !
« Reply #3 on: December 02, 2018, 04:55:50 pm »

Here is an updated version of the mig29  with much improved "fly-by" camera included

Download from here:

https://www.dropbox.com/s/sehnh9ql0e81ryj/mig29flyby.otx?dl=0

With pleasure here I present the video of aWac9 who first used it in his "top-gun" clip

« Last Edit: December 02, 2018, 04:59:52 pm by fly77 »
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Airplane new "fly-by" camera addition - working !
« Reply #4 on: December 06, 2018, 02:41:17 pm »

Please download from here an updated, much improved version, of the fly-by camera mod for Cessna 172.
In addition to the flyby camera I also have included a "formation flight" camera both contributing highly to thr realism of flight that indeed outerra is capable of   - just need to uncover it !

https://www.dropbox.com/s/y32ihi43bnz53yp/C172flyby.otx?dl=0

It will appear in the aircraft menu as a new Cessna172flyby, recognizably by its thumbnail.


Below a demonstration flight around lake constance (Germany)



instructions:

As usual for cameras press "V" for first-person-view cameras

pressing repeatedly "V" scrolls through the various cameras including the Cessna's default cameras and finally two new cameras...a fly-by and a formation flight camera.

When arriving at the flyby camera note that the range of flyby varies randomly between 25 m and 50 m for consecutive fly-bys
Similarly the nearest approach to the camera varies randomly between 15 m and 30 m for consecutive fly-bys

The fly-by range can be increased by pressing "H" or decreased by pressing "J"

A fly-by can be initiated "at will" instead of automatically by pressing "\" (backslash) provided that the key has been assigned
previously in the outerra menu F1 -> controls -> configure -> air -> advanced -> annunciator -> test stall warn

After the fly-by camera comes the "formation flight" camera.
It captures the position of the plane during a moment of the fly-by.
Contrary to the fly-by camera (which tracks the plane) you can look around freely with the mouse ...the plane might be behind you depending when you pressed "V" during the last fly-by.
Look around and try to get used to it. It is worth it.

Note: for all first-person view cameras including the fly-by and formation flight ones press +/- on the numerical keypad to zoom in/out.

As for the Mig29flyby also for the cessna it is convenient to  set air turbulence to zero in the outerra weather menu, to avoid excessive camera shaking.

Finally to go backwards with the cameras instead of pressing "V" press "shift+V"..very useful.


Enjoy !
« Last Edit: December 07, 2018, 03:24:56 pm by fly77 »
Logged

aWac9

  • Hero Member
  • *****
  • Posts: 2601
  • newbie
Re: Airplane new "fly-by" camera addition - working !
« Reply #5 on: December 06, 2018, 03:05:48 pm »

magnificent .. another great contribution for the community.
Thank you.
Logged

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: Airplane new "fly-by" camera addition - working !
« Reply #6 on: December 06, 2018, 03:22:44 pm »

Thanks. Anyway any suggestions for improvement are wellcome  ;)   Next challenge: ground camera !  Needs some deep understanding of coordinate systems, euler angles and rotation quaternions !  :facepalm:  Meanwhile a fake but nevertheless cool "moving ground camera" can be already mimicked by having the camera set below the plane and  flying more or less low.
« Last Edit: December 06, 2018, 04:43:16 pm by fly77 »
Logged

aWac9

  • Hero Member
  • *****
  • Posts: 2601
  • newbie
Re: Airplane new "fly-by" camera addition - working !
« Reply #7 on: December 06, 2018, 05:03:24 pm »

Great angles, very nice, although we still need some practice. :)

 8) I'm having little problems with sound editing, :o


« Last Edit: December 07, 2018, 02:22:52 am by aWac9 »
Logged