Board index FlightGear Development Nasal

Project 3D to 2D coordinates

Nasal is the scripting language of FlightGear.

Re: Project 3D to 2D coordinates

Postby gordonshamway23 » Sun Nov 29, 2020 1:37 pm

http://wiki.flightgear.org/Howto:Projec ... top_canvas

WIki entry is done. Feel free to improve it.
gordonshamway23
 
Posts: 24
Joined: Sun Nov 22, 2020 8:15 pm

Re: Project 3D to 2D coordinates

Postby Hooray » Sun Nov 29, 2020 2:09 pm

Thanks for doing this, that's really looking exceptionally good !!
Feel free to let us know if you have any other questions, seems like a good deal to exchange a little information for tutorials :lol:
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Project 3D to 2D coordinates

Postby Johan G » Sun Nov 29, 2020 2:56 pm

That is a good start on the wiki. :D
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: Project 3D to 2D coordinates

Postby gordonshamway23 » Sun Nov 29, 2020 5:36 pm

Thank you, I am glad you like it.

I have indeed a question regarding the one limitation i described in the Wiki.

I think the properties "sim/current-view/raw-orientation[...]" and "sim/current-view/viewer-...-m" are updated at a low frequency, let's say at 10 fps.
Surely there is nothing I can do about it on the nasal side. Is there any chance this could be raised in future?
gordonshamway23
 
Posts: 24
Joined: Sun Nov 22, 2020 8:15 pm

Re: Project 3D to 2D coordinates

Postby Hooray » Sun Nov 29, 2020 5:56 pm

I would need to take a look at the source code - it would be relatively easy to fix - I'd suggest to file a ticket here: https://sourceforge.net/p/flightgear/codetickets/

If I grep through $FG_SRC, I see this:
Code: Select all
Viewer/view.cxx:330:    _tiedProperties.Tie("raw-orientation", 0, this, &View::getRawOrientation_w);
Viewer/view.cxx:331:    _tiedProperties.Tie("raw-orientation", 1, this, &View::getRawOrientation_x);
Viewer/view.cxx:332:    _tiedProperties.Tie("raw-orientation", 2, this, &View::getRawOrientation_y);
Viewer/view.cxx:333:    _tiedProperties.Tie("raw-orientation", 3, this, &View::getRawOrientation_z);



This suggests, it's using tied properties (references to C++ PODs)

You can probably check fg_init.cxx in $FG_SRC/Main where you will find some hard-coded "refresh rate" for the underlying SGSubsystem, possibly using some enum.
Again, I would need to take a look myself - but looking at your Nasal code, you are probably in a position to see for yourself ;-)
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Project 3D to 2D coordinates

Postby gordonshamway23 » Mon Nov 30, 2020 10:59 pm

You are right, the folllowing code shows, that "sim/current-view/viewer-...-m" is tied to View::_absolute_view_pos
and "sim/current-view/raw-orientation[..]" to mViewOrientation.


Viewer/view.hxx:
Code: Select all
class View : public SGSubsystem
{
    ...

    SGQuatd mViewOrientation;
    SGVec3d _absolute_view_pos;

    const SGVec3d& getViewPosition() { if ( _dirty ) { recalc(); } return _absolute_view_pos; }
    const SGQuatd& getViewOrientation() { if ( _dirty ) { recalc(); } return mViewOrientation; }

    ...
}


Viewer/view.cxx:
Code: Select all
void
View::bind ()
{
    ...

    _tiedProperties.Tie("raw-orientation", 0, this, &View::getRawOrientation_w);
    _tiedProperties.Tie("raw-orientation", 1, this, &View::getRawOrientation_x);
    _tiedProperties.Tie("raw-orientation", 2, this, &View::getRawOrientation_y);
    _tiedProperties.Tie("raw-orientation", 3, this, &View::getRawOrientation_z);

    _tiedProperties.Tie("viewer-x-m", this, &View::getAbsolutePosition_x);
    _tiedProperties.Tie("viewer-y-m", this, &View::getAbsolutePosition_y);
    _tiedProperties.Tie("viewer-z-m", this, &View::getAbsolutePosition_z);

   ...

}

double View::getAbsolutePosition_x() const
{
    return _absolute_view_pos.x();
}

... analog for y z

double View::getRawOrientation_w() const
{
    return mViewOrientation.w();
}

... analog for x y z


Views are members of the FGViewMgr subsystem as one can see in FGViewMgr::init (), which is initialized in fg_init.cxx, as you correctly stated.

Main/fg_init.cxx
Code: Select all
void fgCreateSubsystems(bool duringReset) {

   ... all other subsystem's initialization

    globals->add_new_subsystem<FGViewMgr>(SGSubsystemMgr::DISPLAY);
}


No indication of a refresh rate here. So I looked up:

Main/global.hxx
Code: Select all
class FGGlobals
{
   ...

   void add_subsystem (const char * name,
                                SGSubsystem * subsystem,
                                SGSubsystemMgr::GroupType
                                type = SGSubsystemMgr::GENERAL,
                                double min_time_sec = 0);

   template<class T>
   T* add_new_subsystem (SGSubsystemMgr::GroupType
                                type = SGSubsystemMgr::GENERAL,
                                double min_time_sec = 0)
    {
        T* sub = new T;
        add_subsystem(T::staticSubsystemClassId(), sub, type, min_time_sec);
        return sub;
    }

   ...
}


and

Main/global.cxx
Code: Select all
void
FGGlobals::add_subsystem (const char * name,
                          SGSubsystem * subsystem,
                          SGSubsystemMgr::GroupType type,
                          double min_time_sec)
{
    subsystem_mgr->add(name, subsystem, type, min_time_sec);
}


So min_time_sec, the time of the update interval is zero for FGViewMgr, which means it is updated every frame.
I also looked in SGSubsystem::update, SGSubsystemGroup::update and SGSubsystemGroup::Member::update to confirm that.

So the following is definetly called every frame:

Viewer/viewmgr.cxx:
Code: Select all
void
FGViewMgr::update (double dt)
{
    flightgear::View* currentView = get_current_view();
    if (!currentView) {
        return;
    }

  // Update the current view
  currentView->update(dt);

// update the camera now
    osg::ref_ptr<flightgear::CameraGroup> cameraGroup = flightgear::CameraGroup::getDefault();
    cameraGroup->setCameraParameters(currentView->get_v_fov(),
                                     cameraGroup->getMasterAspectRatio());
    cameraGroup->update(toOsg(currentView->getViewPosition()),
                        toOsg(currentView->getViewOrientation()));
}


This update calls getViewPosition() and getViewOrientation() of the current view, so the tied member variables _absolute_view_pos and mViewOrientation can't be dirty or out of date,
even if they are, no longer than 1 frame, which cannot cause such a delay I am experiencing when getting the value of the properties via nasal's getprop().
I am a bit clueless now, why I have that delay, maybe it has something to do with nasal or the nature of tied properties or the the mouse input is not instantly propagated to the variables .
I have to investigate.
Maybe someone have an idea.
gordonshamway23
 
Posts: 24
Joined: Sun Nov 22, 2020 8:15 pm

Re: Project 3D to 2D coordinates

Postby Hooray » Mon Nov 30, 2020 11:28 pm

that's looking good, thanks for the research !
If I remember correctly, there are "enums" for different "priorities" (=refresh rates) - i.e. the refresh rate could be "encoded" as part of "SGSubsystemMgr::DISPLAY".

Also, tied properties don't fire listeners - however, I am not sure how they relate to polling per frame using either getprop or props.Node

If in doubt, I'd suggest to use the property browser or the "logging" system to see if other subsystems seem to get a more reliable value that way.
If that's the case, there are some potential workarounds - for instance, the autopilot system gets to run at a higher frequency and could in theory copy/replicate a property that way.

Like you said, if you are seeing those properties only updated every 10 frames, that seems odd to me - and I assume that some of the state isn't reflected in the property tree

Again, it's been years since I looked at that code, so I need to take a look myself - if you need an answer asap, you could try the developers mailing list obviously.

PS: There is a property read/write tracing utility, I think it's documented in the "property browser" wiki article - that might be a good starting point.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Previous

Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests