X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fmodel.cxx;h=8016f97ca3b6e5da9ac240e6d5158405ad210257;hb=a2acc953ae337d45954382904e0d1ea6c63b48a0;hp=32237ee4a68d55aef7d9a869c85a18b815539071;hpb=00738f22f754ee58b8f33c17d19953b3452075cc;p=flightgear.git diff --git a/src/Main/model.cxx b/src/Main/model.cxx index 32237ee4a..8016f97ca 100644 --- a/src/Main/model.cxx +++ b/src/Main/model.cxx @@ -94,13 +94,13 @@ FGAircraftModel::init () // Load animations vector animation_nodes = props.getChildren("animation"); - for (int i = 0; i < animation_nodes.size(); i++) { + for (unsigned int i = 0; i < animation_nodes.size(); i++) { vector name_nodes = animation_nodes[i]->getChildren("object-name"); if (name_nodes.size() < 1) { SG_LOG(SG_INPUT, SG_ALERT, "No object-name given for transformation"); } else { - for (int j = 0; j < name_nodes.size(); j++) { + for (unsigned int j = 0; j < name_nodes.size(); j++) { _animations.push_back(read_animation(name_nodes[j]->getStringValue(), animation_nodes[i])); } @@ -150,10 +150,12 @@ FGAircraftModel::update (int dt) long elapsed_ms = (_current_timestamp - _last_timestamp) / 1000; _last_timestamp.stamp(); - if (globals->get_viewmgr()->get_current() == 0) { + int view_number = globals->get_viewmgr()->get_current(); + + if (view_number == 0 && !fgGetBool("/sim/view/internal")) { _selector->select(false); } else { - for (int i = 0; i < _animations.size(); i++) + for (unsigned int i = 0; i < _animations.size(); i++) do_animation(_animations[i], elapsed_ms); _selector->select(true); @@ -171,14 +173,57 @@ FGAircraftModel::update (int dt) sgMat4 sgTUX; sgCopyMat4( sgTUX, sgROT ); - sgPostMultMat4( sgTUX, pilot_view->get_VIEW_ROT() ); - sgPostMultMat4( sgTUX, sgTRANS ); - + sgMat4 VIEW_ROT; + sgCopyMat4( VIEW_ROT, pilot_view->get_VIEW_ROT()); + if (view_number == 0) { + // FIXME: orientation is not applied + // correctly when view is not forward + sgMakeRotMat4( sgROT, -pilot_view->get_view_offset() + * SGD_RADIANS_TO_DEGREES, pilot_view->get_world_up() ); + + /* Warning lame hack from Wilson ahead */ + /* get the pitch value */ + sgVec3 rph; + sgCopyVec3(rph, pilot_view->get_rph()); + /* double it to counter the value already in the VIEW_ROT */ + float pitch = rph[1] * 2; + /* make a ROT matrix + with the values waited by the X coordinate from the offset + rotation see sgROT above + */ + sgMat4 PunROT; + PunROT[0][0] = SG_ONE; + PunROT[0][1] = SG_ZERO; + PunROT[0][2] = SG_ZERO; + PunROT[0][3] = SG_ZERO; + PunROT[1][0] = SG_ZERO; + PunROT[1][1] = cos((1 - sgROT[0][0]) * -pitch); + PunROT[1][2] = -sin((1 - sgROT[0][0]) * -pitch); + PunROT[1][3] = SG_ZERO; + PunROT[2][0] = SG_ZERO; + PunROT[2][1] = sin((1 - sgROT[0][0]) * -pitch); + PunROT[2][2] = cos((1 - sgROT[0][0]) * -pitch); + PunROT[2][3] = SG_ZERO; + PunROT[3][0] = SG_ZERO; + PunROT[3][1] = SG_ZERO; + PunROT[3][2] = SG_ZERO; + PunROT[3][3] = SG_ONE; + + sgPostMultMat4( sgTUX, PunROT ); + sgPostMultMat4( sgTUX, VIEW_ROT ); + sgPostMultMat4( sgTUX, sgROT ); + sgPostMultMat4( sgTUX, sgTRANS ); + /* end lame hack */ + + } else { + sgPostMultMat4( sgTUX, VIEW_ROT ); + sgPostMultMat4( sgTUX, sgTRANS ); + } + sgCoord tuxpos; sgSetCoord( &tuxpos, sgTUX ); _position->setTransform( &tuxpos ); } - } FGAircraftModel::Animation