void Frame::UpdateOrbitRails(double time, double timestep) { m_oldPos = m_pos; m_oldAngDisplacement = m_angSpeed * timestep; // update frame position and velocity if (m_parent && m_sbody && !IsRotFrame()) { m_pos = m_sbody->GetOrbit().OrbitalPosAtTime(time); vector3d pos2 = m_sbody->GetOrbit().OrbitalPosAtTime(time+timestep); m_vel = (pos2 - m_pos) / timestep; } // temporary test thing else m_pos = m_pos + m_vel * timestep; // update frame rotation double ang = fmod(m_angSpeed * time, 2.0 * M_PI); if (!is_zero_exact(ang)) { // frequently used with e^-10 etc matrix3x3d rot = matrix3x3d::RotateY(-ang); // RotateY is backwards m_orient = m_initialOrient * rot; // angvel always +y } UpdateRootRelativeVars(); // update root-relative pos/vel/orient for (Frame* kid : m_children) kid->UpdateOrbitRails(time, timestep); }
void Frame::UpdateOrbitRails(double time, double timestep) { m_oldPos = m_pos; m_oldAngDisplacement = m_angSpeed * timestep; // update frame position and velocity if (m_parent && m_sbody && !IsRotFrame()) { m_pos = m_sbody->orbit.OrbitalPosAtTime(time); vector3d pos2 = m_sbody->orbit.OrbitalPosAtTime(time+timestep); m_vel = (pos2 - m_pos) / timestep; } // temporary test thing else m_pos = m_pos + m_vel * timestep; // update frame rotation double ang = m_angSpeed * timestep; // hmm. cumulative inaccuracy? worse! if (!is_zero_exact(ang)) { // frequently used with e^-10 etc matrix3x3d rot = matrix3x3d::RotateY(-ang); // RotateY is backwards m_orient = m_orient * rot; // angvel always +y } UpdateRootRelativeVars(); // update root-relative pos/vel/orient for (ChildIterator it = m_children.begin(); it != m_children.end(); ++it) (*it)->UpdateOrbitRails(time, timestep); }
static int l_get_gps(lua_State *l) { Player *player = LuaObject<Player>::CheckFromLua(1); vector3d pos = Pi::player->GetPosition(); double center_dist = pos.Length(); auto frame = player->GetFrame(); if(frame) { Body *astro = frame->GetBody(); if(astro && astro->IsType(Object::TERRAINBODY)) { TerrainBody* terrain = static_cast<TerrainBody*>(astro); if (!frame->IsRotFrame()) frame = frame->GetRotFrame(); vector3d surface_pos = pos.Normalized(); double radius = 0.0; if (center_dist <= 3.0 * terrain->GetMaxFeatureRadius()) { radius = terrain->GetTerrainHeight(surface_pos); } double altitude = center_dist - radius; vector3d velocity = player->GetVelocity(); double vspeed = velocity.Dot(surface_pos); if (fabs(vspeed) < 0.05) vspeed = 0.0; // Avoid alternating between positive/negative zero // RefreshHeadingPitch(); if (altitude < 0) altitude = 0; LuaPush(l, altitude); LuaPush(l, vspeed); const float lat = RAD2DEG(asin(surface_pos.y)); const float lon = RAD2DEG(atan2(surface_pos.x, surface_pos.z)); LuaPush(l, lat); LuaPush(l, lon); return 4; // } } } return 0; }