Hi,

I am trying to show the trajectory the aircraft just flied when start replaying. Is there anybody who had ever done that? Or could you give me some ideas about the solution?

I have successfully draw "points" along the trajectory by this way:

- In replay.hxx, define:
ssgRoot * _scene;
ssgSelector * _selector;
vector <SGModelPlacement *> * _trajectory;
ssgBranch * trajectories;
ssgBranch * fgLoadTrajectoryPoint();
void load(); //get the (lon, lat, alt) from terms (short_term...long_term)
sgdVec3 * pos_v1; //store the lon, lat, alt of each points.


- In replay.cxx,

1. fgLoadTrajectoryPoint():
Just clone the existing codes in acmodel.cxx which load the 3D model of the aircraft. I load a model of Point (like the light point showed in runway).
2. load():
Get the lon, lat, alt of each point in terms (short, mid, long). Store in pos_v1.
Then do some initializatioin:
ssgBranch * trajectory = fgLoadTrajectoryPoint();
for (int i=0; i<nv; i++)
{
_trajectory = new SGModelPlacement;
_trajectory -> init (trajectory);
_trajectory -> setVisible(true);
trajectories->addKid(_trajectory->getSceneGraph() );
}
_selector->addKid( trajectories );
globals->get_scenery()->get_scene_graph()->addKid(_selector);
3. update():
if ( replay_master->getBoolValue() ) {
// don't record the replay session
Point3D scenery_center = globals->get_scenery()->get_center();
for (int i=0; i<nv; i++)
{
(* _trajectory)[i]->setVisible(true);
(* _trajectory)[i]->setPosition(pos_v1[i][0],
pos_v1[i][1],
pos_v1[i][2]);
(* _trajectory)[i]->setOrientation(0.0, 0.0, 0.0);
(* _trajectory)[i]->update( scenery_center );
}
_trajectory -> setVisible(true);


By this way I showed the trajectory which is composed of "points" successfully. But now, I want to show "lines" for this trajectory and I found I may need to find out some other ways because it's improper to use SGModelPlacement here now. Another thing is I want to draw the vertical line of each "point"...I mean the line connecting the "point" and the current elev point of the terrain.

I tried a "dirty" but "fast"(I think) way like this but I failed to get what I want:

In the main.cxx, fgRenderFrame(), I add some codes like this:

if ( replay_master -> getBoolValue()){
          FGReplay *r = (FGReplay *)(globals->get_subsystem( "replay" ));

//nv is the size of pos_v1.
if ((*r).nv > 0)
{
Point3D scenery_center = globals->get_scenery()->get_center();


             FGViewer *v = globals -> get_current_view();
             Point3D vp( v-> get_view_pos()[0],
                         v-> get_view_pos()[1],
                         v-> get_view_pos()[2]);

for ( int i=0; i<(*r).nv; i++ )
{
double lon_rad = ((*r).pos_v1[i][0]) * SGD_DEGREES_TO_RADIANS;
double lat_rad = ((*r).pos_v1[i][1]) * SGD_DEGREES_TO_RADIANS;
double elev = ((*r).pos_v1[i][2]) * SG_FEET_TO_METER;


Point3D geod(lon_rad, lat_rad, elev);
Point3D world_pos = sgGeodToCart( geod );
Point3D offset = world_pos - scenery_center; //correct or not???
offset = offset - vp; //correct or not???


              (*r).view_pos1[i][0] = offset.x();
              (*r).view_pos1[i][1] = offset.y();
              (*r).view_pos1[i][2] = offset.z();
             }
          }

          glMatrixMode(GL_PROJECTION);
          glPushMatrix();
          glLoadIdentity();
          glMatrixMode(GL_MODELVIEW);
          glPushMatrix();
          glLoadIdentity();
          glLineWidth(10.0f);
          glColor3f(1.0,0.0,0.0);
          glBegin(GL_LINES);
          for ( int i=0; i<(*r).nv; i++ )
          {
                glVertex3f((*r).view_pos1[i][0],
                           (*r).view_pos1[i][1],
                           (*r).view_pos1[i][2]);
          }
          glEnd();

          glMatrixMode(GL_MODELVIEW);
          glPopMatrix();
          glMatrixMode(GL_PROJECTION);
          glPopMatrix();
       }

}

I failed to see the trajectory but just some random lines showed in the screen. Can anyone take some time to help me and shed some lights on this issue?

Thanks.

Regards,
Qingrou

_________________________________________________________________
免费下载 MSN Explorer: http://explorer.msn.com/lccn/



_______________________________________________ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to