// temporary one-point version static void CollideWithTerrain(Body *body) { if (!body->IsType(Object::DYNAMICBODY)) return; DynamicBody *dynBody = static_cast<DynamicBody*>(body); if (!dynBody->IsMoving()) return; Frame *f = body->GetFrame(); if (!f || !f->GetBody() || f != f->GetBody()->GetFrame()) return; if (!f->GetBody()->IsType(Object::TERRAINBODY)) return; TerrainBody *terrain = static_cast<TerrainBody*>(f->GetBody()); const Aabb &aabb = dynBody->GetAabb(); double altitude = body->GetPosition().Length() + aabb.min.y; if (altitude >= terrain->GetMaxFeatureRadius()) return; double terrHeight = terrain->GetTerrainHeight(body->GetPosition().Normalized()); if (altitude >= terrHeight) return; CollisionContact c; c.pos = body->GetPosition(); c.normal = c.pos.Normalized(); c.depth = terrHeight - altitude; c.userData1 = static_cast<void*>(body); c.userData2 = static_cast<void*>(f->GetBody()); hitCallback(&c); }
bool AIParagonCmdOrbit::TimeStepUpdate() { if (!ProcessChild()) { if (m_child->GetCommandName() == CmdName::CMD_PARAGON_FLYTO) { if (m_child->GetChildCommand() && m_child->GetChildCommand()->GetCommandName() == CmdName::CMD_PARAGON_STEERAROUND) { AIParagonCmdSteerAround* cmd = reinterpret_cast<AIParagonCmdSteerAround*>( m_child->GetChildCommand()); if (cmd->GetRemainingDistance() > 25000.0 && cmd->GetRemainingDistance() < 110000.0) { delete m_child; m_child = nullptr; } } } return false; } TerrainBody* planet = reinterpret_cast<TerrainBody*>(m_targetFrame->GetBody()); assert(planet); // Orbit position is adjusted to avoid perfectly oposite direction (which might cause // vector math to go berserk with NaNs) vector3d ship_pos = m_ship->GetPositionRelTo(m_targetFrame) - (m_ship->GetOrientRelTo(m_targetFrame).VectorZ() * 5000.0); vector3d ship_to_planet_dir = (planet->GetPosition() - ship_pos).Normalized(); vector3d orbit_position = planet->GetPosition() + (ship_to_planet_dir * GetTransitRadius(planet)); m_child = new AIParagonCmdFlyTo(m_ship, m_targetFrame, orbit_position, 0, true); return false; }
void ObjectViewerView::Update() { if (Pi::KeyState(SDLK_EQUALS)) viewingDist *= 0.99f; if (Pi::KeyState(SDLK_MINUS)) viewingDist *= 1.01f; viewingDist = Clamp(viewingDist, 10.0f, 1e12f); char buf[128]; Body *body = Pi::player->GetNavTarget(); if(body && (body != lastTarget)) { // Reset view distance for new target. viewingDist = body->GetBoundingRadius() * 2.0f; lastTarget = body; if (body->IsType(Object::TERRAINBODY)) { TerrainBody *tbody = static_cast<TerrainBody*>(body); const SystemBody *sbody = tbody->GetSystemBody(); m_sbodyVolatileGas->SetText(stringf("%0{f.3}", sbody->m_volatileGas.ToFloat())); m_sbodyVolatileLiquid->SetText(stringf("%0{f.3}", sbody->m_volatileLiquid.ToFloat())); m_sbodyVolatileIces->SetText(stringf("%0{f.3}", sbody->m_volatileIces.ToFloat())); m_sbodyLife->SetText(stringf("%0{f.3}", sbody->m_life.ToFloat())); m_sbodyVolcanicity->SetText(stringf("%0{f.3}", sbody->m_volcanicity.ToFloat())); m_sbodyMetallicity->SetText(stringf("%0{f.3}", sbody->m_metallicity.ToFloat())); m_sbodySeed->SetText(stringf("%0{i}", int(sbody->seed))); m_sbodyMass->SetText(stringf("%0{f}", sbody->mass.ToFloat())); m_sbodyRadius->SetText(stringf("%0{f}", sbody->radius.ToFloat())); } } snprintf(buf, sizeof(buf), "View dist: %s Object: %s", format_distance(viewingDist).c_str(), (body ? body->GetLabel().c_str() : "<none>")); m_infoLabel->SetText(buf); if (body && body->IsType(Object::TERRAINBODY)) m_vbox->ShowAll(); else m_vbox->HideAll(); }
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; }