Scene* Chapter7_1::createScene() { cocos2d::Rect visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect(); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); // create a scene auto scene = Scene::create(); // add title auto label = LabelTTF::create("TileMap", "Marker Felt.ttf", 32); label->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height/2).x, Vec2(visibleRect.origin.x+visibleRect.size.width/2, visibleRect.origin.y+visibleRect.size.height).y - 30); scene->addChild(label, -1); //add the menu item for back to main menu label = LabelTTF::create("MainMenu", "Marker Felt.ttf", 32); auto menuItem = MenuItemLabel::create(label); menuItem->setCallback([&](cocos2d::Ref *sender) { Director::getInstance()->replaceScene(Chapter7::createScene()); }); auto menu = Menu::create(menuItem, nullptr); menu->setPosition(Vec2::ZERO); menuItem->setPosition(Vec2(visibleRect.origin.x+visibleRect.size.width - 80, visibleRect.origin.y + 25)); scene->addChild(menu, 1); // TileMap auto map = TMXTiledMap::create("isometric_grass_and_water.tmx"); map->setPosition(Vec2(visibleSize.width/2 - map->getContentSize().width/2, 0)); auto listener1 = EventListenerTouchOneByOne::create(); listener1->onTouchBegan = [](Touch* touch, Event* event){ return true; // if you are consuming it }; listener1->onTouchEnded = [=](Touch* touch, Event* event){ auto layer = map->getLayer("layer0"); Size viewSize = Director::getInstance()->getWinSize(); Vec2 mapCordinate = map->convertToNodeSpace(Director::getInstance()->convertToGL(touch->getLocationInView())); int tileX = mapCordinate.x / map->getTileSize().width; int tileY = (viewSize.height - mapCordinate.y) / map->getTileSize().height; int id = layer->getTileGIDAt(Vec2(tileX, tileY)); Sprite* tileSprite = layer->getTileAt(Vec2(tileX, tileY)); std::cout << "Tile GID: " << id << std::endl; }; Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener1, map); scene->addChild(map, 0, 99); // with a tag of '99' return scene; }
void TopdownTileRenderer::renderTile(const TilePos& tile_pos, RGBAImage& tile) { int texture_size = images->getTextureSize(); tile.setSize(getTileSize(), getTileSize()); for (int x = 0; x < tile_width; x++) { for (int z = 0; z < tile_width; z++) { mc::ChunkPos chunkpos(tile_pos.getX() * tile_width + x, tile_pos.getY() * tile_width + z); current_chunk = world->getChunk(chunkpos); if (current_chunk != nullptr) renderChunk(*current_chunk, tile, texture_size*16*x, texture_size*16*z); } } }
Point HelloWorld::convertto2dSimple(float x,float y) { auto map = static_cast<TMXTiledMap*>( getChildByTag(1)); int mapWidth = map->getMapSize().width * map->getTileSize().width; int mapHeight = map->getMapSize().height * map->getTileSize().height; double mystatic5 = sqrt(5.0); int tileWidthratio = 2; int tileHeightratio = 1; int deltaX = x - mapWidth/2; int deltaY = y - mapHeight; int d2x = (tileWidthratio * deltaY + tileHeightratio * deltaX) / (tileWidthratio * tileHeightratio * map->getTileSize().width * mystatic5 / 2) + 13; int d2y = (tileWidthratio * deltaY - tileHeightratio * deltaX) / (tileWidthratio * tileHeightratio * map->getTileSize().width * mystatic5 / 2) + 13; return Point(d2x,d2y); }
//------------------------------------------------------------------------- // // Requests a map image from Google Static Maps. // URL example: // OLD: http://maps.google.com/staticmap?center=59.4,18.4&zoom=13&size=640x640&key=MAPS_API_KEY // http://maps.google.com/maps/api/staticmap?parameterscenter=59.4,18.4&zoom=13&size=640x640&key=MAPS_API_KEY // http://maps.google.com/maps/api/staticmap?center=59.4,18.4&zoom=13&size=640x640&sensor=false&maptype=streetmap&format=png8&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSsTL4WIgxhMZ0ZK_kHjwHeQuOD4xQJpBVbSrqNn69S6DOTv203MQ5ufA // void GoogleMapSource::getTileUrl( char* buffer, MapTileCoordinate tileXY ) //------------------------------------------------------------------------- { const int bottomCrop = 30; int tileSize = getTileSize( ); LonLat centerpoint = this->tileCenterToLonLat( tileSize, tileXY, 0, bottomCrop/2 ); const char* maptype = ""; switch( mMapKind ) { case GoogleMapKind_StreetMap: maptype = "roadmap"; break; case GoogleMapKind_Aerial: maptype = "satellite"; break; case GoogleMapKind_Hybrid: maptype = "hybrid"; break; default: BIG_PHAT_ERROR; } sprintf( buffer, "http://maps.google.com/maps/api/staticmap?center=%f,%f&zoom=%d&size=%dx%d&sensor=false&maptype=%s&format=png8&key=%s", centerpoint.lat, centerpoint.lon, tileXY.getMagnification( ), tileSize, tileSize + bottomCrop, // this will cut out the source notice at the bottom of each tile maptype, ApiKey ); }
bool HelloWorld::init() { if ( !LayerColor::initWithColor(Color4B(255, 255, 255, 255) )) { return false; } auto map = TMXTiledMap::create("TileMaps/iso-test-zorder.tmx"); this->addChild(map, 0, 1); Size s = map->getContentSize(); log("ContentSize : %f, %f", s.width, s.height); map->setPosition(Vec2(-s.width/2 , 0)); m_tamara = Sprite::create("Images/grossinis_sister1.png"); map->addChild(m_tamara, map->getChildren().size()); int mapWidth = map->getMapSize().width * map->getTileSize().width; m_tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Vec2(mapWidth / 2, 0))); m_tamara->setAnchorPoint(Vec2(0.5f, 0)); auto move = MoveBy::create(10, Vec2(300, 250)); auto back = move->reverse(); auto seq = Sequence::create(move, back, nullptr); m_tamara->runAction(RepeatForever::create(seq)); schedule(schedule_selector(HelloWorld::repositionSprite)); return true; }
//------------------------------------------------------------------ // // TMXUncompressedTestNew // //------------------------------------------------------------------ TMXUncompressedTestNew::TMXUncompressedTestNew() { auto color = LayerColor::create( Color4B(64,64,64,255) ); addChild(color, -1); auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); // move map to the center of the screen auto ms = map->getMapSize(); auto ts = map->getTileSize(); map->runAction(MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 ) )); //unsupported // // testing release map // TMXLayer* layer; // // auto& children = map->getChildren(); // for(const auto &node : children) { // layer= static_cast<TMXLayer*>(node); // layer->releaseMap(); // } }
//------------------------------------------------------------------------- MapTileCoordinate GoogleMapSource::lonLatToTile( LonLat lonlat, MagnificationType magnification ) //------------------------------------------------------------------------- { double meterX, meterY; int tileX, tileY; LonLatToMeters( lonlat.lon, lonlat.lat, meterX, meterY ); MetersToTile( getTileSize( ), meterX, meterY, magnification, tileX, tileY ); return MapTileCoordinate( tileX, tileY, magnification ); }
float OsmAnd::AtlasMapRenderer_OpenGL::getReferenceTileSizeOnScreen( const MapRendererState& state ) { const auto& rasterMapProvider = state.rasterLayerProviders[static_cast<int>(RasterMapLayerId::BaseLayer)]; if(!rasterMapProvider) return static_cast<float>(DefaultReferenceTileSizeOnScreen) * setupOptions.displayDensityFactor; auto tileProvider = std::static_pointer_cast<IMapBitmapTileProvider>(rasterMapProvider); return tileProvider->getTileSize() * (setupOptions.displayDensityFactor / tileProvider->getTileDensity()); }
/** * Will construct a BenchmarkControl instance from an index between 0 an kNumBenchmarks. */ static BenchmarkControl Make(size_t i) { SkASSERT(kNumBenchmarks > i); BenchmarkControl benchControl; benchControl.fTileSize = getTileSize(i); benchControl.fType = getBenchmarkType(i); benchControl.fFunction = getBenchmarkFunc(i); benchControl.fName = getBenchmarkName(i); return benchControl; }
void OgreDetourTileCache::getTileAtPos(const float* pos, int& tx, int& ty) { // if (!m_geom) return; // TODO is it correct to read from OgreRecast cfg here? const float* bmin = m_recast->m_cfg.bmin; const float ts = getTileSize(); tx = (int)((pos[0] - bmin[0]) / ts); ty = (int)((pos[2] - bmin[2]) / ts); }
//------------------------------------------------------------------ // // TMXIsoTestNew // //------------------------------------------------------------------ TMXIsoTestNew::TMXIsoTestNew() { auto color = LayerColor::create( Color4B(64,64,64,255) ); addChild(color, -1); auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test.tmx"); addChild(map, 0, kTagTileMap); // move map to the center of the screen auto ms = map->getMapSize(); auto ts = map->getTileSize(); map->runAction( MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 )) ); }
int main (int argc, char *argv[]) { Array breakPoints; BreakPoint *currBP; BreakPointRead *currBPR; int i,j,k; int readLength; int tileSize; char *breakPointSequence; if ((Conf = confp_open(getenv("FUSIONSEQ_CONFPATH"))) == NULL) return EXIT_FAILURE; bp_init ("-"); breakPoints = bp_getBreakPoints (); for (i = 0; i < arrayMax (breakPoints); i++) { currBP = arrp (breakPoints,i,BreakPoint); tileSize = getTileSize (currBP->tileCoordinate1,currBP->tileCoordinate2); breakPointSequence = getBreakPointSequence (currBP->tileCoordinate1,currBP->tileCoordinate2); printf ("Tile 1: %s\n",currBP->tileCoordinate1); printf ("Tile 2: %s\n",currBP->tileCoordinate2); printf ("Number of reads spanning breakpoint: %d\n\n\n",arrayMax (currBP->breakPointReads)); for (j = 0; j < arrayMax (currBP->breakPointReads); j++) { currBPR = arrp (currBP->breakPointReads,j,BreakPointRead); readLength = strlen (currBPR->read); for (k = 0; k < currBPR->offset; k++) { printf (" "); } for (k = 0; k < readLength; k++) { if (((currBPR->offset + k) % tileSize) == 0 && (currBPR->offset + k) != 0) { printf ("%s",TILE_SEPARATOR); } printf ("%c",currBPR->read[k]); } printf ("\n"); } for (k = 0; k < (2 * tileSize); k++) { if ((k % tileSize) == 0 && k != 0) { printf ("%s",TILE_SEPARATOR); } printf ("%c",breakPointSequence[k]); } printf ("\n\n\n\n\n"); } bp_deInit (); confp_close(Conf); return EXIT_SUCCESS; }
//------------------------------------------------------------------ // // TMXIsoTest2 // //------------------------------------------------------------------ TMXIsoTest2::TMXIsoTest2() { auto color = LayerColor::create( Color4B(64,64,64,255) ); addChild(color, -1); auto map = TMXTiledMap::create("TileMaps/iso-test2.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); // move map to the center of the screen auto ms = map->getMapSize(); auto ts = map->getTileSize(); map->runAction( MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 ) )); }
//------------------------------------------------------------------------- // // Convert tile center plus pixel offset to lat/lon. Offset increases right and down // LonLat GoogleMapSource::tileCenterToLonLat( const int tileSize, const MapTileCoordinate& tile, const double offsetX, const double offsetY ) //------------------------------------------------------------------------- { double meterX, meterY; TileCenter( getTileSize( ), tile.getX( ), tile.getY( ), tile.getMagnification( ), meterX, meterY ); double pixelX, pixelY; MetersToPixels( meterX, meterY, tile.getMagnification( ), pixelX, pixelY ); pixelX += offsetX; pixelY -= offsetY; // google maps y coords increase up PixelsToMeters( pixelX, pixelY, tile.getMagnification( ), meterX, meterY ); double lon, lat; MetersToLonLat( meterX, meterY, lon, lat ); return LonLat( lon, lat ); }
void UniformResamplingRecursiveMISBPTRenderer::buildDirectImportanceSampleTilePartitionning() { ThreadRNG rng(*this, 0u); m_DirectImportanceSampleTilePartitionning.build( m_LightPathBuffer.size(), getScene(), getSensor(), getFramebufferSize(), getTileSize(), getTileCount2(), [&](std::size_t i) { return m_LightPathBuffer[i].m_Intersection; }, [&](std::size_t i) { return m_LightPathBuffer[i].m_Intersection && m_LightPathBuffer[i].m_fPathPdf > 0.f; }, rng); }
bool ForestOrthoLayer::doCreateTile(int level, int tx, int ty, TileStorage::Slot *data) { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "OrthoForest tile " << getProducerId() << " " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("ORTHO", oss.str()); } if (level >= displayLevel) { ptr<FrameBuffer> fb = SceneManager::getCurrentFrameBuffer(); TileCache::Tile * t = graphProducer->findTile(level, tx, ty); assert(t != NULL); ObjectTileStorage::ObjectSlot *graphData = dynamic_cast<ObjectTileStorage::ObjectSlot*>(t->getData()); GraphPtr g = graphData->data.cast<Graph>(); if (g != NULL) { vec3d q = getTileCoords(level, tx, ty); float scale = 2.0f * (1.0f - getTileBorder() * 2.0f / getTileSize()) / q.z; vec3d tileOffset = vec3d(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale); //offsetU->set(vec3f(q.x + q.z / 2.0f, q.y + q.z / 2.0f, scale)); offsetU->set(vec3f(0.0, 0.0, 1.0)); colorU->set(vec4f(color.x, color.y, color.z, color.w)); mesh->setMode(TRIANGLES); mesh->clear(); ptr<Graph::AreaIterator> ai = g->getAreas(); while (ai->hasNext()) { AreaPtr a = ai->next(); tess->beginPolygon(mesh); drawArea(tileOffset, a, *tess); tess->endPolygon(); } fb->draw(layerProgram, *mesh); } else { if (Logger::DEBUG_LOGGER != NULL) { ostringstream oss; oss << "NULL Graph : " << level << " " << tx << " " << ty; Logger::DEBUG_LOGGER->log("GRAPH", oss.str()); } } } return true; }
void HelloWorld::createMapAndAddChild() { auto map = TMXTiledMap::create("test-zorder.tmx"); addChild(map, 0, 1); auto s = map->getContentSize(); map->setPosition(Point(-480,0)); m_testSp = Sprite::create("grossinis_sister1.png"); map->addChild(m_testSp, map->getChildren().size() ); m_testSp->retain(); int mapWidth = map->getMapSize().width * map->getTileSize().width; m_testSp->setPosition(CC_POINT_PIXELS_TO_POINTS(Point(mapWidth/2,0))); m_testSp->setAnchorPoint(Point(0.5f,0)); auto move = MoveBy::create(10, Point(300,250)); auto back = move->reverse(); auto seq = Sequence::create(move, back,NULL); m_testSp->runAction( RepeatForever::create(seq) ); schedule( schedule_selector(HelloWorld::repositionSprite) ); }
Ogre::AxisAlignedBox OgreDetourTileCache::getTileBounds(int tx, int ty) { const float* bmin = m_recast->m_cfg.bmin; const float ts = getTileSize(); Ogre::AxisAlignedBox result; result.setMinimum( bmin[0] + tx * ts, bmin[1], bmin[2] + ty * ts ); result.setMaximum( bmin[0] + (tx+1) * ts, m_recast->m_cfg.bmax[1], bmin[2] + (ty+1) * ts ); return result; }
//------------------------------------------------------------------ // // TMXIsoZorder // //------------------------------------------------------------------ TMXIsoZorder::TMXIsoZorder() { auto map = TMXTiledMap::create("TileMaps/iso-test-zorder.tmx"); addChild(map, 0, kTagTileMap); auto s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); map->setPosition(Point(-s.width/2,0)); _tamara = Sprite::create(s_pathSister1); map->addChild(_tamara, map->getChildren().size() ); _tamara->retain(); int mapWidth = map->getMapSize().width * map->getTileSize().width; _tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Point( mapWidth/2,0))); _tamara->setAnchorPoint(Point(0.5f,0)); auto move = MoveBy::create(10, Point(300,250)); auto back = move->reverse(); auto seq = Sequence::create(move, back,NULL); _tamara->runAction( RepeatForever::create(seq) ); schedule( schedule_selector(TMXIsoZorder::repositionSprite) ); }
//------------------------------------------------------------------ // // TMXIsoZorderNew // //------------------------------------------------------------------ TMXIsoZorderNew::TMXIsoZorderNew() { auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test-zorder.tmx"); addChild(map, 0, kTagTileMap); auto s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); map->setPosition(Vec2(-s.width/2,0)); _tamara = Sprite::create(s_pathSister1); map->addChild(_tamara, (int)map->getChildren().size() ); _tamara->retain(); int mapWidth = map->getMapSize().width * map->getTileSize().width; _tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Vec2( mapWidth/2,0))); _tamara->setAnchorPoint(Vec2(0.5f,0)); auto move = MoveBy::create(10, Vec2(300,250)); auto back = move->reverse(); auto seq = Sequence::create(move, back,nullptr); _tamara->runAction( RepeatForever::create(seq) ); schedule( CC_SCHEDULE_SELECTOR(TMXIsoZorderNew::repositionSprite) ); }
void TileManager::update() { static Tile * clicked = nullptr; //the mouse in the window. sf::Vector2i mousePos = Controller::mousePosition; Scene & scene = Scene::instance(); sf::Vector2f worldMousePos = scene.getWindow().mapPixelToCoords(mousePos, scene.getView()); //transform the mouse position in to tile space sf::Vector2f transformedPosition = tiledWorld_->getTransform().getInverse().transformPoint(worldMousePos.x, worldMousePos.y); sf::Vector2i coordinates = sf::Vector2i(transformedPosition.x / getTileSize().x, transformedPosition.y / getTileSize().y); if(coordinatesAreIn(coordinates)) { //the tile that the mouse is currently hovering over Tile * hoverTile = getTile(coordinates); assert(hoverTile != nullptr); if(Controller::getButton(sf::Mouse::Button::Right)) { for(auto * tile : hoverTile->getAllNeighbours()) { tile->setColor(sf::Color::Red); tile->setText(""); coloredTiles_.push_back(tile); } } if(Controller::getButton(sf::Mouse::Button::Middle)) { if(Controller::getKey(sf::Keyboard::Key::LShift))hoverTile->setTraversable(true); else hoverTile->setTraversable(false); hoverTile->recolor(); } if(Controller::getButtonDown(sf::Mouse::Button::Left)) { clicked = getTile(coordinates); } else if(Controller::getButtonUp(sf::Mouse::Button::Left) && clicked != nullptr) { TileManager::instance().forEachTile([](Tile & tile) { tile.g_ = 0; tile.h_ = 0; tile.f_ = 0; tile.recolor(); tile.setText(""); }); path_ = Pathfinder::instance().getPath(clicked, hoverTile); clicked = nullptr; // auto steps = path.size(); TileManager::instance().forEachTile([&](Tile & tile) { std::stringstream sstream; if(tile.f_ > 0) { sstream << tile.g_ << "\n" << tile.h_ << "\n" << tile.f_; tile.setText(sstream.str()); } //tile.setColor(sf::Color(r, g, b)); } ); for(auto * pn : path_) { auto * tile = static_cast<Tile*>(pn); tile->setColor(sf::Color::Yellow); //coloredTiles_.push_back(tile); } } Scene::instance().debugText_.setString(hoverTile->getTilePropertiesString()); } }
void BinarySwapComposer::composeViewport(ViewportPtr port) { // setup viewport GLint pl=port->getPixelLeft(), pr=port->getPixelRight(), pb=port->getPixelBottom(), pt=port->getPixelTop(); GLint pw=pr-pl+1,ph=pt-pb+1; bool full = port->isFullWindow(); glViewport(pl, pb, pw, ph); glScissor(pl, pb, pw, ph); if(! full) glEnable(GL_SCISSOR_TEST); GLboolean depth = glIsEnabled(GL_DEPTH_TEST); GLboolean blend = glIsEnabled(GL_BLEND); glDisable(GL_DEPTH_TEST); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0, port->getPixelWidth(), 0, port->getPixelHeight(),-1,1); // printf("max %x,%x\n",_intDepthMax,_shortDepthMax); if(getAlpha()) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } _tilesX = port->getPixelWidth() / getTileSize() + 1; _tilesY = port->getPixelHeight() / getTileSize() + 1; _tileBufferSize = getTileSize()*getTileSize()*8+sizeof(TileBuffer); _readTile.resize(_tileBufferSize); _statistics.bytesIn = 0; _statistics.bytesOut = 0; if(isClient()) { if(getShort()) { UInt16 colorDummy; UInt32 depthDummy; recvFromServers(depthDummy,colorDummy, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, port); } else { if(getAlpha()) { UInt32 colorDummy; UInt32 depthDummy; recvFromServers(depthDummy,colorDummy, GL_RGBA, GL_UNSIGNED_BYTE, port); } else { RGBValue colorDummy; UInt32 depthDummy; recvFromServers(depthDummy,colorDummy, GL_RGB, GL_UNSIGNED_BYTE, port); } } if(getStatistics()) { UInt32 maxIn = _statistics.bytesIn; UInt32 maxOut = _statistics.bytesOut; UInt32 maxIO = maxIn + maxOut; UInt32 sumOut = _statistics.bytesOut; UInt32 missing = _usableServers; double composeTime = 1e32; Connection *server; Statistics statistics; for(UInt32 i=0 ; i<_usableServers ;++i) { server = clusterWindow()->getNetwork()->getConnection(i); server->selectChannel(); server->get(&statistics,sizeof(Statistics)); sumOut += statistics.bytesOut; if(statistics.composeTime < composeTime) composeTime = statistics.composeTime; if(statistics.bytesOut > maxOut) maxOut = statistics.bytesOut; if(statistics.bytesIn > maxIn) maxIn = statistics.bytesIn; if(statistics.bytesIn + statistics.bytesOut > maxIO) maxIO = statistics.bytesIn + statistics.bytesOut; missing--; } printf("compose Time : %1.5lf\n",composeTime); printf("Transfered bytes : %10d\n",sumOut); printf("Max out : %10d\n",maxOut); printf("Max in : %10d\n",maxIn); printf("Max io : %10d\n",maxIO); } } else { if(clusterId() < _usableServers) { _statistics.composeTime = -getSystemTime(); _tile.resize(_tileBufferSize * _tilesX * _tilesY); if(getShort()) { UInt16 colorDummy; UInt32 depthDummy=_shortDepthMax; // UInt32 depthDummy=_intDepthMax; startReader(depthDummy,colorDummy, // GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, port); } else { if(getAlpha()) { UInt32 colorDummy; UInt32 depthDummy=_intDepthMax; startReader(depthDummy,colorDummy, GL_UNSIGNED_INT, GL_RGBA, GL_UNSIGNED_BYTE, port); } else { RGBValue colorDummy; UInt32 depthDummy=_intDepthMax; startReader(depthDummy,colorDummy, GL_UNSIGNED_INT, GL_RGB, GL_UNSIGNED_BYTE, port); } } _statistics.composeTime += getSystemTime(); if(getStatistics()) { Connection *client = clusterWindow()->getNetwork()->getConnection(serverCount()); client->put(&_statistics,sizeof(Statistics)); client->flush(); } } /* // max depth value !! find a better way glClear(GL_DEPTH_BUFFER_BIT); glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, &_intDepthMax); glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, &_shortDepthMax); */ } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glEnable(GL_DEPTH_TEST); // reset state if(depth && !glIsEnabled(GL_DEPTH_TEST)) glEnable(GL_DEPTH_TEST); if(!blend && glIsEnabled(GL_BLEND)) glDisable(GL_BLEND); }
TileSelection OgreDetourTileCache::getTileSelection(const Ogre::AxisAlignedBox &selectionArea) { // TODO Account for origin? Have a look at dtTileCache::queryTiles() TileSelection result; // Verify whether area to select falls within tilecache bounds, otherwise clip Ogre::Vector3 min = selectionArea.getMinimum(); if (min.x < m_cfg.bmin[0]) min.x = m_cfg.bmin[0]; if (min.z < m_cfg.bmin[2]) min.z = m_cfg.bmin[2]; if (min.x > m_cfg.bmax[0]) min.x = m_cfg.bmax[0]; if (min.z > m_cfg.bmax[2]) min.z = m_cfg.bmax[2]; Ogre::Vector3 max = selectionArea.getMaximum(); if (max.x < m_cfg.bmin[0]) max.x = m_cfg.bmin[0]; if (max.z < m_cfg.bmin[2]) max.z = m_cfg.bmin[2]; if (max.x > m_cfg.bmax[0]) max.x = m_cfg.bmax[0]; if (max.z > m_cfg.bmax[2]) max.z = m_cfg.bmax[2]; // Width of one tile in world units float tileWidth = getTileSize(); // Calculate tile index range that falls within bounding box result.minTx = (min.x - m_cfg.bmin[0]) / tileWidth; result.maxTx = (max.x - m_cfg.bmin[0]) / tileWidth; result.minTy = (min.z - m_cfg.bmin[2]) / tileWidth; result.maxTy = (max.z - m_cfg.bmin[2]) / tileWidth; // TODO you can also go the other route: using cellsize and tilesize // Let's assume these will be correct for a small performance gain /* // Assert tx and ty are within index bounds, otherwise clip if (result.minTx < 0) result.minTx = 0; if (result.maxTx < 0) result.maxTx = 0; if (result.minTx > m_tw) result.minTx = m_tw; if (result.maxTx > m_tw) result.maxTx = m_tw; if (result.minTy < 0) result.minTy = 0; if (result.maxTy < 0) result.maxTy = 0; if (result.minTy > m_th) result.minTy = m_th; if (result.maxTy > m_th) result.maxTy = m_th; */ // Calculate proper bounds aligned to tile bounds min.x = m_cfg.bmin[0] + (result.minTx * tileWidth); min.y = m_cfg.bmin[1]; min.z = m_cfg.bmin[2] + (result.minTy * tileWidth); max.x = m_cfg.bmin[0] + ((result.maxTx+1) * tileWidth); max.y = m_cfg.bmax[1]; max.z = m_cfg.bmin[2] + ((result.maxTy+1) * tileWidth); // TODO does this box need to be offset a little further with borders? // Return result result.bounds.setMinimum(min); result.bounds.setMaximum(max); return result; }
sf::Vector2f coordsToWorld(sf::Vector2i const& coords) { return {coords.x * getTileSize().x + 0.5f * getTileSize().x, coords.y * getTileSize().y + 0.5f * getTileSize().y}; }
NMap() { mTileSize = getTileSize(); mLayerSize = getLayerSize(); }
void Source::Impl::updateTiles(const UpdateParameters& parameters) { if (!loaded) { return; } const uint16_t tileSize = getTileSize(); const Range<uint8_t> zoomRange = getZoomRange(); // Determine the overzooming/underzooming amounts and required tiles. int32_t overscaledZoom = util::coveringZoomLevel(parameters.transformState.getZoom(), type, tileSize); int32_t tileZoom = overscaledZoom; std::vector<UnwrappedTileID> idealTiles; if (overscaledZoom >= zoomRange.min) { int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom); // Make sure we're not reparsing overzoomed raster tiles. if (type == SourceType::Raster) { tileZoom = idealZoom; } idealTiles = util::tileCover(parameters.transformState, idealZoom); } // Stores a list of all the tiles that we're definitely going to retain. There are two // kinds of tiles we need: the ideal tiles determined by the tile cover. They may not yet be in // use because they're still loading. In addition to that, we also need to retain all tiles that // we're actively using, e.g. as a replacement for tile that aren't loaded yet. std::set<OverscaledTileID> retain; auto retainTileFn = [&retain](Tile& tile, Resource::Necessity necessity) -> void { retain.emplace(tile.id); tile.setNecessity(necessity); }; auto getTileFn = [this](const OverscaledTileID& tileID) -> Tile* { auto it = tiles.find(tileID); return it == tiles.end() ? nullptr : it->second.get(); }; auto createTileFn = [this, ¶meters](const OverscaledTileID& tileID) -> Tile* { std::unique_ptr<Tile> tile = cache.get(tileID); if (!tile) { tile = createTile(tileID, parameters); if (tile) { tile->setObserver(this); } } if (!tile) { return nullptr; } return tiles.emplace(tileID, std::move(tile)).first->second.get(); }; auto renderTileFn = [this](const UnwrappedTileID& tileID, Tile& tile) { renderTiles.emplace(tileID, RenderTile{ tileID, tile }); }; renderTiles.clear(); algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn, idealTiles, zoomRange, tileZoom); if (type != SourceType::Annotations && cache.getSize() == 0) { size_t conservativeCacheSize = std::max((float)parameters.transformState.getSize().width / util::tileSize, 1.0f) * std::max((float)parameters.transformState.getSize().height / util::tileSize, 1.0f) * (parameters.transformState.getMaxZoom() - parameters.transformState.getMinZoom() + 1) * 0.5; cache.setSize(conservativeCacheSize); } removeStaleTiles(retain); const PlacementConfig config { parameters.transformState.getAngle(), parameters.transformState.getPitch(), parameters.debugOptions & MapDebugOptions::Collision }; for (auto& pair : tiles) { pair.second->setPlacementConfig(config); } }
void MapLayer::update(float dt) { // 根据路径移动 if(_stepIndex >= 1) { if(_smallStepIndex == 0) { int ncol = ((AstarItem*)_path->getObjectAtIndex(_stepIndex))->getCol(); int nrow = ((AstarItem*)_path->getObjectAtIndex(_stepIndex))->getRow(); int pcol = ((AstarItem*)_path->getObjectAtIndex(_stepIndex - 1))->getCol(); int prow = ((AstarItem*)_path->getObjectAtIndex(_stepIndex - 1))->getRow(); if(pcol == ncol) { if(prow > nrow) { _vmove = 2; } else if(prow <nrow) { _vmove = 3; } else { _vmove = -1; } } else if(prow == nrow) { if(pcol > ncol) { _vmove = 1; } else if(pcol < ncol) { _vmove = 0; } else { _vmove = -1; } } else { _vmove = -1; } } Point herop = _tamara->getPosition(); switch(_vmove) { case 0: herop.x += 1; herop.y -= 0.5; break; case 1: herop.x -= 1; herop.y += 0.5; break; case 2: herop.x += 1; herop.y += 0.5; break; case 3: herop.x -= 1; herop.y -= 0.5; break; case 4: herop.x += 1; break; case 5: herop.x -= 1; break; case 6: herop.y += 0.5; break; case 7: herop.y -= 0.5; break; default: break; } _smallStepIndex++; if(_smallStepIndex >= 32) { _smallStepIndex = 0; if(_stepIndex >= _path->count() - 1) { // 移动到终点 _stepIndex = -1; _vmove = -1; _path->removeAllObjects(); _path->release(); _path = nullptr; } else { _stepIndex++; _vmove = -1; } } _tamara->setPosition(herop); // 地图随主角移动 auto map = (TMXTiledMap*)this->getChildByTag(kTagTileMap); int mapWidth = map->getMapSize().width * map->getTileSize().width; int mapHeight = map->getMapSize().height * map->getTileSize().height; float deltaX = herop.x - mapWidth/2; float deltaY = herop.y - 112; auto winSize = Director::getInstance()->getWinSize(); map->setPosition((winSize.width - map->getContentSize().width)/2 - deltaX, -deltaY); } }
bool OsmAnd::HeightmapTileProvider_P::obtainData( const TileId tileId, const ZoomLevel zoom, std::shared_ptr<MapTiledData>& outTiledData, const IQueryController* const queryController) { // Obtain raw data from DB QByteArray data; bool ok = _tileDb.obtainTileData(tileId, zoom, data); if (!ok || data.length() == 0) { // There was no data at all, to avoid further requests, mark this tile as empty outTiledData.reset(); return true; } // We have the data, use GDAL to decode this GeoTIFF const auto tileSize = getTileSize(); bool success = false; QString vmemFilename; vmemFilename.sprintf("/vsimem/heightmapTile@%p", data.data()); VSIFileFromMemBuffer(qPrintable(vmemFilename), reinterpret_cast<GByte*>(data.data()), data.length(), FALSE); auto dataset = reinterpret_cast<GDALDataset*>(GDALOpen(qPrintable(vmemFilename), GA_ReadOnly)); if (dataset != nullptr) { bool bad = false; bad = bad || dataset->GetRasterCount() != 1; bad = bad || dataset->GetRasterXSize() != tileSize; bad = bad || dataset->GetRasterYSize() != tileSize; if (bad) { if (dataset->GetRasterCount() != 1) LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %d bands instead of 1", tileId.x, tileId.y, zoom, dataset->GetRasterCount()); if (dataset->GetRasterXSize() != tileSize || dataset->GetRasterYSize() != tileSize) { LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %dx%x size instead of %d", tileId.x, tileId.y, zoom, dataset->GetRasterXSize(), dataset->GetRasterYSize(), tileSize); } } else { auto band = dataset->GetRasterBand(1); bad = bad || band->GetColorTable() != nullptr; bad = bad || band->GetRasterDataType() != GDT_Int16; if (bad) { if (band->GetColorTable() != nullptr) LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has color table", tileId.x, tileId.y, zoom); if (band->GetRasterDataType() != GDT_Int16) LogPrintf(LogSeverityLevel::Error, "Height tile %dx%d@%d has %s data type in band 1", tileId.x, tileId.y, zoom, GDALGetDataTypeName(band->GetRasterDataType())); } else { auto buffer = new float[tileSize*tileSize]; auto res = dataset->RasterIO(GF_Read, 0, 0, tileSize, tileSize, buffer, tileSize, tileSize, GDT_Float32, 1, nullptr, 0, 0, 0); if (res != CE_None) { delete[] buffer; LogPrintf(LogSeverityLevel::Error, "Failed to decode height tile %dx%d@%d: %s", tileId.x, tileId.y, zoom, CPLGetLastErrorMsg()); } else { outTiledData.reset(new ElevationDataTile(buffer, sizeof(float)*tileSize, tileSize, tileId, zoom)); success = true; } } } GDALClose(dataset); } VSIUnlink(qPrintable(vmemFilename)); return success; }
int OsmAndMapView::getMapXForPoint(double longitude) const { double tileX = OsmAnd::Utilities::getTileNumberX(getZoom(), longitude); return (int) ((tileX - getXTile()) * getTileSize() + getCenterPointX()); }
int OsmAndMapView::getMapYForPoint(double latitude) const { double tileY = OsmAnd::Utilities::getTileNumberY(getZoom(), latitude); return (int) ((tileY - getYTile()) * getTileSize() + getCenterPointY()); }