void Display::displayText(std::string text, Coordinates position){ const char* textTemp = text.c_str(); //Ne fonctionne pas tout le temps a verifier al_draw_text(font, (al_map_rgba(255, 0, 0, 255)), position.getX(), position.getY(), ALLEGRO_ALIGN_CENTRE, textTemp); al_flip_display(); }
void Scene::render(SDL_Surface * surface){ SDL_Surface *image = NULL;//, *rotation = NULL; for (std::vector<Item>::iterator it=items.begin(); it!=items.end(); ++it){ Item varitem = *it; //TODO: LOAD image //image = IMG_Load(varitem.resource.rawPath.c_str()); image = IMG_Load("image.bmp"); SDL_Rect r;//,r2; Coordinates newCoor = varitem.coordinates; newCoor = newCoor.isoToScreen( newCoor, ApplicationPreferencesManager::getIntegerPreference("tileWidth", DEFAULT_WIDTH), ApplicationPreferencesManager::getIntegerPreference("tileHeight", DEFAULT_WIDTH) ); r.x = newCoor.x; r.y = newCoor.y; r.w = ApplicationPreferencesManager::getIntegerPreference("tileWidth", DEFAULT_WIDTH); r.h = ApplicationPreferencesManager::getIntegerPreference("tileHeight", DEFAULT_WIDTH); //r2 = r; //r2.w = sqrt(r.w*r.w+r.h*r.h)/2.0; //r2.h = r2.w; image->w = r.w; image->h = r.h; //rotation = rotozoomSurface(image, 45, 1.0, 1); //rotation->w = r.w; //rotation->h = r.h; //SDL_BlitSurface(rotation, NULL, surface, &r); SDL_BlitSurface(image, NULL, surface, &r); //SDL_FreeSurface(rotation); SDL_FreeSurface(image); } }
void copyCoordinates(Coordinates& dst, const Coordinates& src) { assert(dst.size() >= src.size()); for (Coordinates::size_type i = 0; i < src.size(); ++i) { dst[i] = src[i]; } }
//------------------------------------------------------------------------------ bool SVGLine::resize() { signed int x, y; std::string str_value; Coordinates *coord = new Coordinates(0,0); std::cout << "id: " << id_ << std::endl; std::cout << "x2: " << coordinates_.back().getX() << std::endl; std::cout << "y2: " << coordinates_.back().getY() << std::endl; coordinates_.erase(coordinates_.begin()+1); while(true) { if(ui_->getParam(" x2? ", false, false, x, str_value, true)) break; } coord->setX(x); while(true) { if(ui_->getParam(" y2? ", false, false, y, str_value, true)) break; } coord->setY(y); coordinates_.push_back(*coord); delete coord; return true; }
SimpleTensor<T> median3x3(const SimpleTensor<T> &src, BorderMode border_mode, T constant_border_value) { SimpleTensor<T> dst(src.shape(), src.data_type()); const int size_tot_filter = filter_size * filter_size; for(int src_idx = 0; src_idx < src.num_elements(); ++src_idx) { std::array<T, size_tot_filter> filter_elems = { { 0 } }; Coordinates id = index2coord(src.shape(), src_idx); const int x = id.x(); const int y = id.y(); for(int j = y - static_cast<int>(border_size.top), index = 0; j <= y + static_cast<int>(border_size.bottom); ++j) { for(int i = x - static_cast<int>(border_size.left); i <= x + static_cast<int>(border_size.right); ++i, ++index) { id.set(0, i); id.set(1, j); filter_elems[index] = tensor_elem_at(src, id, border_mode, constant_border_value); } } std::sort(filter_elems.begin(), filter_elems.end()); dst[src_idx] = filter_elems[size_tot_filter / 2]; } return dst; }
JSValue JSCoordinates::speed(ExecState* exec) const { Coordinates* imp = impl(); if (!imp->canProvideSpeed()) return jsNull(); return jsNumber(exec, imp->speed()); }
bool LocationMonitorApp::OnAppInitializing(AppRegistry& appRegistry) { // TODO: // Initialize App specific data, and add your initialization code here // The App's permanent data and context can be obtained from the appRegistry. // // If this method is successful, return true; otherwise, return false. // If this method returns false, the App will be terminated. LocationListener* pListener = null; pListener = new LocationListener(); LocationCriteria criteria; criteria.SetAccuracy(LOC_ACCURACY_HUNDRED_METERS); LocationProvider* pLocProvider = new LocationProvider(); pLocProvider->Construct(criteria, *pListener); //bool awake = true; //pLocProvider->KeepLocationUpdateAwake(awake); Coordinates coord; coord.Set(27.0, 125.0, 0.0); //result Set (double latitude, double longitude, double altitude) RegionId regionId; pLocProvider->AddMonitoringRegion(coord, 100, regionId); MockLocationListener* timer = new MockLocationListener(); timer->StartApp(); return true; }
Flag::Flag(Entity* entity) : Entity(entity) { Vector3* pos = entity->getCurrentPos(); this->currentPos = new Vector3(pos->getX(), pos->getY(), pos->getZ()); Coordinates coordin = entity->getCoordinates(); this->coord = new Coordinates(coordin.getCol(), coordin.getRow()); Base base = entity->getBase(); Base* newBase = new Base(base); this->base = newBase; this->name = entity->getName(); this->currentTile = NULL; this->team = entity->getTeam(); this->killedBy = entity->getKilledBy(); this->damageBuffer = 0; this->magic = entity->getMagic(); this->walkable = entity->isWalkable(); this->attackable = entity->isAttackable(); this->hideInFog = entity->getHideInFog(); this->shield = 0; this->removeFromGame = false; player = ""; classname = "Flag"; life = 30; attackable = true; }
Coordinates Coordinates:: operator+(const Coordinates &other) const { Coordinates result(*this); std::copy(other.begin(), other.end(), std::back_inserter(result)); return result; }//operator+
//------------------------------------------------------------------------------ void Game::findTeleportLocation(const string teleport_letter, const Coordinates& position, Coordinates& teleport_exit) { int portal_x=0, portal_y=0; for (std::size_t y = 0; y < board_->size(); y++) { for (std::size_t x = 0; x < board_->at(y).size(); x++) { string symbol = board_->at(y).at(x)->getFieldSymbol(Field::FOR_GAME); // If the momentary field in this loop is not the one the player wants to // enter and if it has the same portal letter as the one he wants to enter // it must be the corresponding portal of that field. std::size_t player_x = position.getX(); std::size_t player_y = position.getY(); if (((x != player_x) || (y != player_y)) && symbol == teleport_letter) { portal_x = static_cast<int>(x); portal_y = static_cast<int>(y); } } } teleport_exit.setX(portal_x); teleport_exit.setY(portal_y); }
LinearRing::LinearRing() { init(); Coordinates* tmp = new Coordinates(); tmp->addCoordinate(0.0, 0.0, 0.0); AddChild(tmp); }
JSValue JSCoordinates::altitudeAccuracy(ExecState* exec) const { Coordinates* imp = impl(); if (!imp->canProvideAltitudeAccuracy()) return jsNull(); return jsNumber(exec, imp->altitudeAccuracy()); }
const Coordinates to_chunk_coordinates(const Coordinates& c) { int x = ((int)std::floor(c.x() / (double)NM_CHUNK_SIZE)); int y = ((int)std::floor(c.y() / (double)NM_CHUNK_SIZE)); return {x, y}; }
std::set< std::string > BoggleSolver::giveMeWords(std::string base, Coordinates start, std::set< Coordinates > alreadyUsed) const { std::set< std::string > result; std::set< std::string > otherResult; base+=getLetter(start.getX(),start.getY()); alreadyUsed.insert(start); if(base.size()>=MIN_WORD_LENGTH ) { //Attention, upper != lower+1 std::string upperBound = dictionnary.getUpperBound(base); if(dictionnary.isValid(base)) result.insert(base); //Optimisation : si on ne trouve pas base dans le début de upper bound, on peut arreter if(upperBound.compare(0,base.size(),base)!=0) return result; } std::vector<Coordinates> adj = start.getAdjacent(gridSize-1,gridSize-1); for(std::vector<Coordinates >::const_iterator it = adj.begin(); it != adj.end();++it) { if(alreadyUsed.find(*it)==alreadyUsed.end()) { otherResult = giveMeWords(base,*it,alreadyUsed); std::set_union(result.begin(), result.end(), otherResult.begin(), otherResult.end(), std::inserter(result,result.end())); } } return result; }
/// For algorithm details, see http://wiki.openstreetmap.org/wiki/Relation:multipolygon/Algorithm void MultipolygonProcessor::process() { bool allClosed = true; // NOTE do not count multipolygon tag itself bool hasNoTags = relation_.tags.size() < 2; Ints outerIndecies; Ints innerIndecies; CoordinateSequences sequences; for (const auto &member : members_) { if (member.type!="w") continue; Coordinates coordinates; auto wayPair = context_.wayMap.find(member.refId); if (wayPair!=context_.wayMap.end()) { coordinates = wayPair->second->coordinates; } else { auto areaPair = context_.areaMap.find(member.refId); if (areaPair!=context_.areaMap.end()) { coordinates = areaPair->second->coordinates; // NOTE make coordinates to be closed ring coordinates.push_back(coordinates[0]); // NOTE merge tags to relation // hasNoTags prevents the case where relation has members with their own tags // which should be processed independently (geometry reusage) if (member.role=="outer" && hasNoTags) mergeTags(areaPair->second->tags); } else { auto relationPair = context_.relationMap.find(member.refId); if (relationPair==context_.relationMap.end()) return; // NOTE cannot fill relation: incomplete data resolve_(*relationPair->second); } } if (coordinates.empty()) continue; if (member.role=="outer") outerIndecies.push_back(static_cast<int>(sequences.size())); else if (member.role=="inner") innerIndecies.push_back(static_cast<int>(sequences.size())); else continue; auto sequence = std::make_shared<CoordinateSequence>(member.refId, coordinates); if (!sequence->isClosed()) allClosed = false; sequences.push_back(sequence); } if (outerIndecies.size()==1 && allClosed) simpleCase(sequences, outerIndecies, innerIndecies); else complexCase(sequences); }
Coordinates TCXParser::position() { Coordinates pos; qreal val; bool res; while (_reader.readNextStartElement()) { if (_reader.name() == "LatitudeDegrees") { val = _reader.readElementText().toDouble(&res); if (!res || (val < -90.0 || val > 90.0)) _reader.raiseError("Invalid LatitudeDegrees"); else pos.setLat(val); } else if (_reader.name() == "LongitudeDegrees") { val = _reader.readElementText().toDouble(&res); if (!res || (val < -180.0 || val > 180.0)) _reader.raiseError("Invalid LongitudeDegrees"); else pos.setLon(val); } else _reader.skipCurrentElement(); } return pos; }
//------------------------------------------------------------------------------ int Game::calculateNextField(Coordinates& position, Coordinates &go_to, string leaving_to) { if (leaving_to == Fastmove::LEFT_) { go_to.changeXBy(-1); return 0; // Next field is a valid neighboring field } else if (leaving_to == Fastmove::RIGHT_) { go_to.changeXBy(1); return 0; } else if (leaving_to == Fastmove::UP_) { go_to.changeYBy(-1); return 0; } else if (leaving_to == Fastmove::DOWN_) { go_to.changeYBy(1); return 0; } else if (isupper(leaving_to[0]) && isalpha(leaving_to[0])) { findTeleportLocation(leaving_to, position, go_to); return 1; // Next field is a teleport field. } else { return -1; // leaving_to string not valid } }
bool AllVersionsChunkIterator::setPosition(Coordinates const& pos) { if (VersionID(pos[0]) != currVersion) { return false; } return inputIterator->setPosition(Coordinates(pos.begin()+1, pos.end())); }
void Viewport::drawPolygon(Object* obj){ auto coords = obj->getNCoords(); Coordinates nCoords; if(coords.size() == 1){// Usuario quer um ponto? drawPoint(obj); return; }else if(coords.size() == 2){// Usuario quer uma linha? drawLine(obj); return; } transformCoordinates(coords, nCoords); prepareContext(obj); cairo_move_to(m_cairo, nCoords[0].x, nCoords[0].y); for(unsigned int i = 0; i<nCoords.size(); i++) cairo_line_to(m_cairo, nCoords[i].x, nCoords[i].y); cairo_close_path(m_cairo); Polygon* p = (Polygon*) obj; if(p->filled()){ cairo_stroke_preserve(m_cairo); cairo_fill(m_cairo); }else cairo_stroke(m_cairo); }
/** * Does the damages. Damage is linear inside the damage radius. * @param capsule The capsule. * @param collidingLocation The coordinates of the collision. */ void Projectile::doDamages( const BodyProjectile &capsule, const Coordinates &collidingLocation ) { Body *body; BodyCannon *cannon; float damage; int i; for ( i = 0; ( body = capsule.getWorld().getBody( i ) ) != NULL; i++ ) { cannon = dynamic_cast<BodyCannon*>(body); if ( cannon ) { damage = this->getDamage( cannon->getLocation().getDistance( collidingLocation.getX(), collidingLocation.getY() ) ); if ( damage ) cannon->getOwner().doDamage( this->shooter, damage ); } } }
Point::Point() { init(); Coordinates* tmp = new Coordinates(); tmp->addCoordinate(0.0, 0.0, 0.0); AddChild(tmp); }
JSValue JSCoordinates::heading(ExecState* exec) const { Coordinates* imp = impl(); if (!imp->canProvideHeading()) return jsNull(); return jsNumber(exec, imp->heading()); }
void GameState::controlLoop(SDL_Event * e) { switch (e->type){ case SDL_KEYDOWN: break; case SDL_KEYUP: break; case SDL_MOUSEMOTION: break; case SDL_MOUSEBUTTONDOWN: int x,y; if(SDL_BUTTON(SDL_GetMouseState(&x, &y)) == SDL_BUTTON_LEFT){ std::cout<<x<<","<<y<<std::endl; Coordinates newCoor = Coordinates(x,y); newCoor = newCoor.screenToIso( newCoor, ApplicationPreferencesManager::getIntegerPreference("tileWidth", DEFAULT_WIDTH), ApplicationPreferencesManager::getIntegerPreference("tileHeight", DEFAULT_HEIGHT) ); std::cout<<newCoor.x<<","<<newCoor.y<<"\n"<<std::endl; int isoDeltaX = ApplicationPreferencesManager::getIntegerPreference("MapDeltaX",0) - ApplicationPreferencesManager::getIntegerPreference("MapDeltaY",0); int isoDeltaY = (ApplicationPreferencesManager::getIntegerPreference("MapDeltaY",0) + ApplicationPreferencesManager::getIntegerPreference("MapDeltaX",0))/2; ApplicationPreferencesManager::setIntegerPreference("IsoDeltaX",isoDeltaX); ApplicationPreferencesManager::setIntegerPreference("IsoDeltaY",isoDeltaY); std::cout<<"Delta"<<std::endl; std::cout<<ApplicationPreferencesManager::getIntegerPreference("MapDeltaX",0)<<","<<ApplicationPreferencesManager::getIntegerPreference("MapDeltaY",0)<<std::endl; std::cout<<ApplicationPreferencesManager::getIntegerPreference("IsoDeltaX",0)<<","<<ApplicationPreferencesManager::getIntegerPreference("IsoDeltaY",0)<<std::endl; } break; case SDL_MOUSEBUTTONUP: break; default: break; } }
void MainWindow::addLine(GtkBuilder* builder){ LineDialog dialog(GTK_BUILDER(builder)); bool finish = false; while(!finish){ if(dialog.run() == 1){ try{ Coordinates c; c.emplace_back(dialog.getX1(), dialog.getY1()); c.emplace_back(dialog.getX2(), dialog.getY2()); Object* obj = _world->addLine( dialog.getName(), dialog.getColor(), c); _viewport->transformObj(obj); addObjOnListStore(dialog.getName(), "Line"); gtk_widget_queue_draw(_mainWindow); log("Nova reta adicionada.\n"); finish = true; }catch(MyException& e){ log(e.what()); showErrorDialog(e.what()); } }else finish = true; } }
// Return list of joined slices Coordinates joinedSlices() const { Coordinates slices0; bool prev_good = false; int max_i = block_length_ - frame_length_; for (int i = 0; i <= max_i; i++) { bool curr_good = goodSlice(i); if (curr_good) { if (prev_good) { // increase previous slice ASSERT_GT(slices0.size(), 0); slices0.back().second += 1; } else { // add new slice int stop = i + frame_length_ - 1; slices0.push_back(StartStop(i, stop)); } } prev_good = curr_good; } Coordinates slices; BOOST_FOREACH (const StartStop& slice, slices0) { StartStop slice1 = strip(slice); if (valid(slice1)) { slices.push_back(slice1); } }
JSValue jsCoordinatesAccuracy(ExecState* exec, JSValue slotBase, const Identifier&) { JSCoordinates* castedThis = static_cast<JSCoordinates*>(asObject(slotBase)); UNUSED_PARAM(exec); Coordinates* imp = static_cast<Coordinates*>(castedThis->impl()); JSValue result = jsNumber(exec, imp->accuracy()); return result; }
const Vector2D Coordinates::GetParallaxDisplacedPosition(const Vector2D position, float displacement_factor) { sf::View& view = GameApp::get_mutable_instance().GetView(); Coordinates tmp; tmp.SetWorldPixel(Vector2D(view.GetCenter().x, view.GetCenter().y)); Vector2D viewcenter_worldfloat = tmp.GetWorldFloat(); Vector2D diff = position - viewcenter_worldfloat; return viewcenter_worldfloat + diff * displacement_factor; }
BezierCurve::BezierCurve(const Coordinates& coords) { if (coords.size() < 4 || (coords.size() - 4) % 3 != 0) { throw CGException("A bezier curve must be defined with 4, 7, 10, 13, 16, ... coordinates"); } addCoordinate(coords); regeneratePath(0.1); }
int AttackNearestEnemy::validateTactic(list<Action*> &newActions, Unit* squad, const vector<Unit*>& enemyUnits, const vector<Unit*>& alliedUnits) { if (enemyUnits.size() == 0 || squad->getNShipsAlive() == 0) return 0; squad->setTarget(-1); int Ret = 0; Coordinates myPos = squad->getAveragePos(); float minDist = 99999; Unit *nearestUnit = NULL; for (unsigned int i = 0; i < enemyUnits.size(); ++i) { Coordinates enemyAvrg = enemyUnits[i]->getAveragePos(); if (enemyUnits[i]->getNShipsAlive() > 0) { float dist = myPos.distance(enemyAvrg); if (dist < minDist) { minDist = dist; nearestUnit = enemyUnits[i]; squad->setTarget(i); } } } if (nearestUnit && minDist < squad->getSquadBaseStats().range) { for (unsigned int i = 0; i < squad->nShips(); ++i) { Ship *iShip = squad->getShip(i); if (iShip->isAlive() && iShip->getStats().currentAtkCD == 0) { while (1) { int s = rand() % nearestUnit->nShips(); if (nearestUnit->getShip(s)->isAlive()) { iShip->getStats().currentAtkCD = iShip->getBaseStats().maxAtkCD; newActions.push_back(new AttackAction(iShip, nearestUnit->getShip(s), squad->getUnitInfo(), nearestUnit->getUnitInfo())); ++Ret; break; } } } } } // TODO: Se eu nao conseguir atacar, devo desconsiderar o target? // if (Ret == 0) // squad->setTarget(-1); return Ret; }
/// Converts geometry. void fillVertices(const Coordinates &coordinates) { vertices_.reserve(coordinates.size() * 3); for (std::size_t i = 0; i < coordinates.size(); ++i) { const utymap::GeoCoordinate coordinate = coordinates[i]; vertices_.push_back(coordinate.longitude); vertices_.push_back(coordinate.latitude); vertices_.push_back(eleProvider_ == nullptr ? 0 : eleProvider_->getElevation(quadKey_, coordinate)); } }