void TerrainImpl::deform(const Selection& selection, float intensity) { for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; iter ++) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float& height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); height += intensity * iter->second; } updateTiles(selection.getMin().getX(), selection.getMin().getY(), selection.getMax().getX(), selection.getMax().getY()); }
void TerrainImpl::avgFlatten(const Selection& selection, float intensity) { // add by 王宏张 2007-7-25 // 计算平均高度 float avgHeiht = 0.0f; for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; ++iter) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); avgHeiht += height; } avgHeiht /= selection.size(); for(Selection::const_iterator iter = selection.begin() ; iter != selection.end() ; ++iter) { if(size_t(iter->first.getX() + selection.getPosition().getX()) >= mInfo->getWidth() || size_t(iter->first.getY() + selection.getPosition().getY()) >= mInfo->getHeight()) continue; float& height = mInfo->at(size_t(iter->first.getX() + selection.getPosition().getX()) , size_t(iter->first.getY() + selection.getPosition().getY())); height = avgHeiht; // avgFlatten算法 } updateTiles(selection.getMin().getX(), selection.getMin().getY(), selection.getMax().getX(), selection.getMax().getY()); }
SelectionPopup::SelectionPopup(const Selection& sel, CelestiaCore* _appCore, QWidget* parent) : QMenu(parent), selection(sel), appCore(_appCore), centerAction(NULL), gotoAction(NULL) { Simulation* sim = appCore->getSimulation(); Vec3d v = sel.getPosition(sim->getTime()) - sim->getObserver().getPosition(); if (sel.body() != NULL) { addAction(boldTextItem(QString::fromUtf8(sel.body()->getName(true).c_str()))); // Start and end dates double startTime = 0.0; double endTime = 0.0; sel.body()->getLifespan(startTime, endTime); if (startTime > -1.0e9 || endTime < 1.0e9) { addSeparator(); if (startTime > -1.0e9) { ostringstream startDateStr; startDateStr << "Start: " << astro::TDBtoUTC(startTime); QAction* startDateAct = new QAction(startDateStr.str().c_str(), this); connect(startDateAct, SIGNAL(triggered()), this, SLOT(slotGotoStartDate())); addAction(startDateAct); } if (endTime < 1.0e9) { ostringstream endDateStr; endDateStr << "End: " << astro::TDBtoUTC(endTime); QAction* endDateAct = new QAction(endDateStr.str().c_str(), this); connect(endDateAct, SIGNAL(triggered()), this, SLOT(slotGotoEndDate())); addAction(endDateAct); } } } else if (sel.star() != NULL) { std::string name = sim->getUniverse()->getStarCatalog()->getStarName(*sel.star()); addAction(boldTextItem(QString::fromUtf8(ReplaceGreekLetterAbbr(name).c_str()))); // Add some text items giving additional information about // the star. double distance = v.length() * 1e-6; char buff[50]; setlocale(LC_NUMERIC, ""); if (abs(distance) >= astro::AUtoLightYears(1000.0f)) sprintf(buff, "%.3f %s", distance, ("ly")); else if (abs(distance) >= astro::kilometersToLightYears(10000000.0)) sprintf(buff, "%.3f %s", astro::lightYearsToAU(distance), ("au")); else if (abs(distance) > astro::kilometersToLightYears(1.0f)) sprintf(buff, "%.3f km", astro::lightYearsToKilometers(distance)); else sprintf(buff, "%.3f m", astro::lightYearsToKilometers(distance) * 1000.0f); addAction(italicTextItem(tr("Distance: ") + QString::fromUtf8(buff))); sprintf(buff, "%.2f (%.2f)", sel.star()->getAbsoluteMagnitude(), astro::absToAppMag(sel.star()->getAbsoluteMagnitude(), (float) distance)); addAction(italicTextItem(tr("Abs (app) mag: ") + QString::fromUtf8(buff))); sprintf(buff, "%s", sel.star()->getSpectralType()); addAction(italicTextItem(tr("Class: ") + QString::fromUtf8(buff))); setlocale(LC_NUMERIC, "C"); } else if (sel.deepsky() != NULL) { addAction(boldTextItem(QString::fromUtf8(sim->getUniverse()->getDSOCatalog()->getDSOName(sel.deepsky()).c_str()))); } addSeparator(); QAction* selectAction = new QAction(tr("&Select"), this); connect(selectAction, SIGNAL(triggered()), this, SLOT(slotSelect())); addAction(selectAction); centerAction = new QAction(tr("&Center"), this); connect(centerAction, SIGNAL(triggered()), this, SLOT(slotCenterSelection())); addAction(centerAction); gotoAction = new QAction(tr("&Goto"), this); connect(gotoAction, SIGNAL(triggered()), this, SLOT(slotGotoSelection())); addAction(gotoAction); QAction* followAction = new QAction(tr("&Follow"), this); connect(followAction, SIGNAL(triggered()), this, SLOT(slotFollowSelection())); addAction(followAction); if (sel.star() == NULL && sel.deepsky() == NULL) { QAction* syncOrbitAction = new QAction(tr("S&ynch Orbit"), this); connect(syncOrbitAction, SIGNAL(triggered()), this, SLOT(slotSyncOrbitSelection())); addAction(syncOrbitAction); } QAction* infoAction = new QAction("Info", this); connect(infoAction, SIGNAL(triggered()), this, SLOT(slotInfo())); addAction(infoAction); if (sel.body() != NULL) { QAction* setVisibilityAction = new QAction("Visible", this); setVisibilityAction->setCheckable(true); setVisibilityAction->setChecked(sel.body()->isVisible()); connect(setVisibilityAction, SIGNAL(toggled(bool)), this, SLOT(slotToggleVisibility(bool))); addAction(setVisibilityAction); }