Board index FlightGear Development

Lost in view handling  Topic is solved

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Lost in view handling

Postby mhab » Sat Jan 16, 2016 12:56 pm

Hello

I am lost in a seemingly simple problem, so please help somebody ...
I dug "views.nas" hundred times from top to bottom to find my way, but fail ...

In an aircraft specific code I want to switch current view to a self defined view. i.e. view[101]
As far as I see, there is no available function in FG to do that ?
So I need the number of the view, which is not the number 101 but the counted number of available view nodes.
How can I get this number ?

What I tried is the following and it fails obviously, but what do I need to add in order to fix it ?
Code: Select all
    var views = nil;    # list of all view branches (/sim/view[n]) as props.Node

    forindex(i; views) {
      if (i.getNode("name") == "Co-Pilot View") {
        setprop("/sim/current-view/view-number", i);
        exit;
      }
    }


"Co-Pilot View" ... is the predefined view name in the view definition
101 would be the number assigned to this view

I just can't find how to fill the views vector, or however this is named ?

Thanks
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Lost in view handling

Postby mhab » Fri Jan 29, 2016 9:50 pm

It's a bit lonely here ...
Maybe I posted this in the wrong thread ?

It seems finally I found what I was looking for ...

Code: Select all
        var views = props.globals.getNode("/sim").getChildren("view");

        forindex(i; views) {
          if (i.getNode("name") == "Co-Pilot View") {
            setprop("/sim/current-view/view-number", i);
            exit;
          }
        }


Maybe somebody would care to comment ?

listening ...
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Lost in view handling

Postby PINTO » Fri Jan 29, 2016 10:02 pm

Are you automating view handling, or just wanting to set a custom binding to go to a view or...?
Looks like your second bit of code would work.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Lost in view handling

Postby mhab » Sat Jan 30, 2016 12:16 am

Hello

Thanks for the note. This is to become part of an aircraft specific binding and the idea is to allow to disable the cockpit view.
If that happens, right when cockpit view is the current view I need to switch to Co-pilot view.

Of course the code example is not doing all this and only serves to explain the problem I was struggling with.

Thanks again
Mike-DE
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10

Re: Lost in view handling

Postby Richard » Sat Jan 30, 2016 10:22 am

I think this is what you want[1]. The F-14 uses this technique to toggle between Pilot and RIO

Code: Select all
var CurrentView_Num = props.globals.getNode("sim/current-view/view-number");
var view_num = view.indexof("Your View Name");

var set_my_cockpit_view = func() {
    CurrentView_Num.setValue(view_num);
}

var toggle_my_view_and_cockpit_view = func() {
   cur_v = CurrentView_Num.getValue();
   if (cur_v != 0 ) {
      CurrentView_Num.setValue(0);
   } else {
      CurrentView_Num.setValue(my_view_num);
   }
}


-------------------
[1] there may be syntax errors as I've not actually run this code.
Richard
 
Posts: 810
Joined: Sun Nov 02, 2014 11:17 pm
Version: Git
OS: Win10

Re: Lost in view handling

Postby DFaber » Sat Jan 30, 2016 10:46 am

mhab wrote in Sat Jan 16, 2016 12:56 pm:So I need the number of the view, which is not the number 101 but the counted number of available view nodes.
How can I get this number ?


You don't need the number. Just do this:

Code: Select all
  setprop("sim/current-view/view-number", view.indexof("Walk View"));


Replace "Walk View" with the name of your custom View and your done.

Greetings
Detlef Faber
FlightGear Development:
http://flightgear-de.net

my 3D-Art:
https://www.sol2500.net
DFaber
 
Posts: 709
Joined: Fri Dec 01, 2006 8:51 pm
Location: Aachen, Germany
Version: GIT
OS: Linux

Re: Lost in view handling  

Postby mhab » Sat Jan 30, 2016 12:44 pm

Thanks a lot the "view.indexof(...)" was my missing link :-)
mhab
 
Posts: 418
Joined: Thu Apr 18, 2013 11:59 pm
Callsign: D-MIKE
Version: 2020.3.4
OS: Win10


Return to Development

Who is online

Users browsing this forum: No registered users and 8 guests