vsTASKER 7 Tutorial
×
Menu
Index

Host to IG

 
The upper section of the CIGI Packet definition is reserved for Sending messages from host (vsTASKER simulation engine) to the IG.
We will create and explain the View Definition message. All other messages will follow the same principle.
 
First, let's create the Packet in the upper section and set it up like below:
 
Now, in the Code::Declaration, let's add the following code:
 
CigiViewDefV3 def;
 
In order to allow the user to set the values of some variables of the def object, we can define them specifically for the dynamic data interface.
To simplify, we will just let the user specify the view id and the fields of view. All the other values will be defaulted by the Packet.
Below the declaration above, add the following code:
 
public:
    int   view_id;  //&&  DEF[0]
    float h_fov;    //&&  LBL[Horizontal FoV] DEF[90] UNIT[deg]
    float v_fov;    //&&  LBL[Vertical FoV] DEF[70] UNIT[deg]
 
Now, below, let's add two methods. One for setting the view and the other one for updating the def class with user and default data.
 
public:
    void setCurrentView();
    void changeView(int new_id, float h, float v);
 
private:
    void setupParams();
 
In the Initialization panel, we call the setupParams function:
 
  case RESET: {
      setupParams();
  } break;
 
In the Methods panel, we define our two declared functions (explanations in the code below):
 
void Pkt::setCurrentView()
{
   CGI:view_id = this->view_id;  // store globally (at the CIGI settings level) the selected view
   tic();                        // send the message
}
 
void Pkt::changeView(int new_id, float h, float v)
{
    view_id = new_id;  // replace the current id
    h_fov = h;         // replace the horizontal fov
    v_fov = v;         // replace the vertical fov
    setupParams();     // send the data to the def object
    setCurrentView();  // send the object to the IG
}
 
void Pkt::setupParams()  // send the local user data to the def object
{
    def.SetViewID(view_id);
    def.SetGroupID(0);
 
    def.SetFOVLeftEn(true);
    def.SetFOVRightEn(true);
    def.SetFOVTopEn(true);
    def.SetFOVBottomEn(true);
 
    def.SetFOVLeft(-h_fov/2);
    def.SetFOVRight(+h_fov/2);
    def.SetFOVTop(+v_fov/2);
    def.SetFOVBottom(-v_fov/2);
 
    def.SetFOVNearEn(true);
    def.SetFOVFarEn(true);
    def.SetFOVNear(0);
    def.SetFOVFar(10000);
 
    def.SetProjectionType(def.ProjectionTypeGrp::Perspective);
}
 
Now, in the runtime (part called at the frequency specified in the Packet settings - here, manually or OnEvent), let's send the message:
 
  *mgr->OmsgPtr << def;
  mgr->nb_pkt++;
 
  return DONE;