Board index FlightGear Development

Trucks models in and out

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.

Trucks models in and out

Postby Jabberwocky » Sat Jan 10, 2015 6:41 pm

Hi,

I try to run a pushback truck as visible AI/MP model. Now, this snippet is from one of those experiments

Code: Select all
      if (getprop("sim/model/pushback/enabled")) {
         var pos_truck = me.moorings["local"].position;
         var heading=getprop("/orientation/heading-deg");
         me.model["local"].remove();
         if (getprop("sim/model/pushback/position-norm")>0.95) {
            var pos_aircraft = geo.aircraft_position();
            var distance=8.35; #correction for tailwheel x-offset from zero point
   
            var course=geo.normdeg(heading+180); #180 deg to get away from the plane
            pos_truck.set_lat(pos_aircraft.lat());
            pos_truck.set_lon(pos_aircraft.lon());
            pos_truck.set_alt(pos_aircraft.alt());

            pos_truck.apply_course_distance(course, distance);
print("truck ", pos_truck.lat(), pos_truck.lon());
print("craft ", pos_aircraft.lat(), pos_aircraft.lon());
         }
         me.model["local"] = geo.put_model(me.model_path, pos_truck, geo.normdeg(heading+180));
      }


But what happens is, the truck, which is initially visible from the FG instance, I started it, disappears as soon as "enabled" is set on true. If I comment out the remove-line, I have of course thousands of trucks in the same position and FG crashes, that was to be expected, but they are visible. So ...

- why does the truck go invisible on me id there should be always one left?
- is there a more elegant way to force a model to move instead of remving it and then placing it anew? geo.nas has no hint about a possibility like a move_model.

J.
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby wlbragg » Sat Jan 10, 2015 7:04 pm

is there a more elegant way to force a model to move instead of remving it and then placing it anew


Can't you change property tree value similar to

Code: Select all
props.globals.getNode("/ai/models/" ~ me.cargoParent ~ "/position/latitude-deg" ).setDoubleValue(me.latNode.getValue());
props.globals.getNode("/ai/models/" ~ me.cargoParent ~ "/position/longitude-deg" ).setDoubleValue(me.lonNode.getValue());
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4874
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Trucks models in and out

Postby Jabberwocky » Sat Jan 10, 2015 7:23 pm

I probably can, when the player is on MP. But the whole thing should also work as a single truck solution for if he is offline. And even if I set it in ai/models while I am in mp, there is no update for the model's position here (or is my FG messed up?).
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby onox » Sat Jan 10, 2015 8:22 pm

Just enable/disable the truck in its .xml model file with a select animation. Make sure to use sim/multiplay/generic/ properties.
onox
Retired
 
Posts: 431
Joined: Fri Jun 20, 2014 2:45 pm

Re: Trucks models in and out

Postby Jabberwocky » Sat Jan 10, 2015 10:14 pm

like that?

Code: Select all
   <animation>
      <type>select</type>
      <condition>
         <property>sim/model/pushback/enabled</property>
         <property>gear/gear[2]/wow</property>
      </condition>
   </animation>


alas, no truck. I ckecked "enabled" and "wow", but are correct. I also checked the position and altitude of the truck ... all correct. But no truck. Which is weird, because when I initally start the truck (with the select commented out), it is visible. Only after I start to remove and re-put it in, it doesn't appear.
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby Jabberwocky » Sat Jan 10, 2015 11:30 pm

Okay, a part of the mystery is solved ... but ... not nice

If the update loop runs on a timer of 0, the changes are simply too fast and all that is (un)visible is actually the removing of the model while the adding of the new model seems not to happen. I changed the update look to 0.05 seconds and there it is ... only it flickers now badly. Any ideas about that?

J.
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby Hooray » Sat Jan 10, 2015 11:44 pm

Jabberwocky wrote in Sat Jan 10, 2015 6:41 pm:is there a more elegant way to force a model to move instead of remving it and then placing it anew? geo.nas has no hint about a possibility like a move_model.


See: http://wiki.flightgear.org/Scripted_AI_Objects
Image
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Trucks models in and out

Postby Jabberwocky » Sun Jan 11, 2015 2:10 am

Yeah, I saw that article, but it is all about waypoints and I have not many waypoints for a pullback truck
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby Hooray » Sun Jan 11, 2015 10:32 am

Jabberwocky wrote in Sun Jan 11, 2015 2:10 am:Yeah, I saw that article, but it is all about waypoints and I have not many waypoints for a pullback truck



Actually, it's not about waypoints at all - in fact, I cannot even find this term when I search for it in the article :?:
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11329
Joined: Tue Mar 25, 2008 8:40 am

Re: Trucks models in and out

Postby elgaton » Sun Jan 11, 2015 10:56 am

I think he's searching for a way to access pushback routes programmatically.
NIATCA 2nd admin, regular ATC at LIPX and creator of the LIPX custom scenery
elgaton
 
Posts: 1107
Joined: Tue Mar 19, 2013 4:58 pm
Callsign: I-ELGA/LIPX_TW
Version: Git
OS: Windows + Arch Linux

Re: Trucks models in and out

Postby onox » Sun Jan 11, 2015 11:27 am

Jabberwocky wrote in Sat Jan 10, 2015 10:14 pm:like that?

Code: Select all
   <animation>
      <type>select</type>
      <condition>
         <property>sim/model/pushback/enabled</property>
         <property>gear/gear[2]/wow</property>
      </condition>
   </animation>



No, you need to use a sim/multiplay/generic/ property, so use something like:

Code: Select all
   <animation>
      <type>select</type>
      <condition>
         <property>sim/multiplay/generic/int[11]</property>
      </condition>
   </animation>


Check Models/Pushback/Military.xml of the old VMX-22 model. Its pushback truck is visible over MP.

Check http://wiki.flightgear.org/Multiplayer_protocol to see the list of properties that get send over MP. It seems gear/gear[2]/compression-norm does get send over MP, so you should use that property instead of gear/gear[2]/wow.
onox
Retired
 
Posts: 431
Joined: Fri Jun 20, 2014 2:45 pm

Re: Trucks models in and out

Postby Jabberwocky » Mon Jan 12, 2015 12:41 am

Okay, will do that next week when I have a little time to experiment with it.
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby Jabberwocky » Wed Jan 14, 2015 6:07 pm

Okay, now I played around a bit and the situation is a little confusing:

Hooray posted a link to a Wiki page that included a snippet that basically ends up with

Code: Select all
aim9.aiObj.set_pos(lat, lon, alt);


only I have no idea where to get the file "Nasal/ai/aim9/aim9.missile", it is not in the F-14B I got from the main page ... so I am at a dead end here because this otherwise apparently wonderful example doesn't include the source for the missile.

Onox suggestion to go via a property and animation seems to work (I have to streamline my source to move around some props, but that isn't the problem). Now it works, but the animation runs the truck the wrong direction or the wrong distance. So, some math to do.
The problem here is, I am not sure how the x/y/z-coordinate system and the lat/lon/alt-coordinate system correlate. -x is west, +x east? -y is north, +y is south? z to alt seems to be the only clear part.

J.
Jabberwocky
Retired
 
Posts: 1319
Joined: Sat Mar 22, 2014 7:36 pm
Callsign: JWOCKY
Version: 3.0.0
OS: Ubuntu 14.04

Re: Trucks models in and out

Postby Philosopher » Wed Jan 14, 2015 6:13 pm

the correlation between geocentric (lat/lon/alt) and model coordinates (x/y/z) depends on the orientation of the model.... I don't think it's possible to convert between them in animation space.
Thanks,
Philosopher
(inactive but lurking occasionally...)
Philosopher
 
Posts: 1590
Joined: Sun Aug 12, 2012 6:29 pm
Location: Stuck in my head...
Callsign: AFTI
Version: Git
OS: Mac OS X 10.7.5

Re: Trucks models in and out

Postby Thorsten » Wed Jan 14, 2015 6:34 pm

The problem here is, I am not sure how the x/y/z-coordinate system and the lat/lon/alt-coordinate system correlate.


What xyz coordinate system? There's the model one (see the ac file for coordinates), the local cartesian one of the terrain tile (x is north, y is west, z is up or so), the world cartesian coordinate system (+z is the north pole, x and y point towards the equator).

If you ask for world coordinates, geo.nas has helper routines for conversion from (lat, long, alt) to world (xyz). Otherwise you can usually get by at the simple expense of picking a point (aircraft, camera, ...) and defining your own local coordinate system around that origin. It's what the weather system does. I guess animations do the implicitly by using the aircraft origin. Since you know the aircraft origin in (lat, lon, alt) from the property tree, you can use the geo class to get relative xyz values from there.
Thorsten
 
Posts: 10941
Joined: Mon Nov 02, 2009 8:33 am

Next

Return to Development

Who is online

Users browsing this forum: No registered users and 18 guests