コード例 #1
0
ファイル: tile.cpp プロジェクト: Bercon/BerconMaps
TilePoint Tile::corner(float rX, float rY, float w, float h, TileParam& t) {	
	// Evaluate	maps
	if (t.tileRound) {
		bool inCorner = false;
		float cX=0.0f, cY=0.0f;
		// Detect corner
		if (rX < t.tileCrnrRad) { 
			if (rY < t.tileCrnrRad) { // Bottom left
				cX = t.tileCrnrRad - rX;
				cY = t.tileCrnrRad - rY; 				
				inCorner = true;
			} else if (rY > h - t.tileCrnrRad) { // Top left
				cX = t.tileCrnrRad - rX;
				cY = h - rY - t.tileCrnrRad; 				
				inCorner = true;
			}
		} else if (rX > w - t.tileCrnrRad) {
			if (rY < t.tileCrnrRad) { // Bottom right
				cX = w - rX - t.tileCrnrRad;
				cY = t.tileCrnrRad - rY; 				
				inCorner = true;
			} else if (rY > h - t.tileCrnrRad) { // Top right
				cX = w - rX - t.tileCrnrRad;
				cY = h - rY - t.tileCrnrRad;
				inCorner = true;
			}
		}
		float d = cY*cY + cX*cX;
		if (inCorner) {
			if (d > t.tileCrnrRad*t.tileCrnrRad)
				return TilePoint();
			// Calculate corner blur
			d = t.tileCrnrRad - sqrt(d);
			if (t.tileBlur > 0 && d <t. tileBlurRad)
				return TilePoint(Point3(rX/w, rY/h, 0.f), edgeBlur(d, t.tileBlurRad, t.tileBlur));
		}
	} 
	if (t.tileBlur) {		
		bool inCorner = false;
		float dX = rX;
		float dY = rY;
		// Distance to vertical walls
		if (rX < t.tileBlurRad) {
			inCorner = true;
		} else if (rX > w - t.tileBlurRad) {
			dX = w - rX;
			inCorner = true;
		}
		// Distance to horizontal walls
		if (rY < t.tileBlurRad) {
			inCorner = true;
		} else if (rY > h - t.tileBlurRad) {
			dY = h - rY;
			inCorner = true;
		}
		if (inCorner)
			return dX<dY?TilePoint(Point3(rX/w, rY/h, 0.f), edgeBlur(dX, t.tileBlurRad, t.tileBlur)):TilePoint(Point3(rX/w, rY/h, 0.f), edgeBlur(dY, t.tileBlurRad, t.tileBlur));
	}
	return TilePoint(Point3(rX/w, rY/h, 0.f), 1.f);
}
コード例 #2
0
ファイル: tile.cpp プロジェクト: Bercon/BerconMaps
TilePoint Tile::pat_xBond(Point3 p, TileParam& t) {
	TilePattern* pat = t.pattern;

	if (!pat) return TilePoint();

	float edges[4];
	int id = 0;
	int id2 = 0;
	
	// Tile top and bottom
	float rand = 3.14f;
	int row = rowcol(edges[3], edges[1], id, p.y, pat->totalHeight, pat->heights, t.tileHeight, t.tileHeightVar, rand);
	if (row == -1) return TilePoint();

	// Tile sides
	rand = edges[3] * 1.325f + 31.41213f;
	float offset = pat->rows[row].offset * t.tileWidth;
	if (offset < 0) offset *= -id;

	row = rowcol(edges[0], edges[2], id2, p.x + offset, pat->rows[row].totalWidth, pat->rows[row].tiles, t.tileWidth, t.tileWidthVar, rand);		
	if (row == -1) return TilePoint();

	edges[0] -= offset;
	edges[2] -= offset;

	id = generateID(id2, id);

	// Draw it
	return drawTile(p, edges, t, id);	
}
コード例 #3
0
ファイル: tile.cpp プロジェクト: Bercon/BerconMaps
TilePoint Tile::drawTile(Point3 p, float edges[4], TileParam& t, int id, int dir) {
	float hEdgeW = t.edgeWidth * .5f;
	float hEdgeH = t.edgeHeight * .5f;
			
	float randomSeed = (float)id * 1.23f + 0.1234f;
	if (dir) {
		edges[0] += t.eH_var ? hEdgeH * (1.f + noise(edges[0], randomSeed) * t.edgeHeightVar) : hEdgeH;
		edges[2] -= t.eH_var ? hEdgeH * (1.f + noise(edges[2], randomSeed) * t.edgeHeightVar) : hEdgeH;
		edges[3] += t.eW_var ? hEdgeW * (1.f + noise(edges[3], randomSeed) * t.edgeWidthVar) : hEdgeW;
		edges[1] -= t.eW_var ? hEdgeW * (1.f + noise(edges[1], randomSeed) * t.edgeWidthVar) : hEdgeW;
	} else {
		edges[0] += t.eW_var ? hEdgeW * (1.f + noise(edges[0], randomSeed) * t.edgeWidthVar) : hEdgeW;
		edges[2] -= t.eW_var ? hEdgeW * (1.f + noise(edges[2], randomSeed) * t.edgeWidthVar) : hEdgeW;
		edges[3] += t.eH_var ? hEdgeH * (1.f + noise(edges[3], randomSeed) * t.edgeHeightVar) : hEdgeH;
		edges[1] -= t.eH_var ? hEdgeH * (1.f + noise(edges[1], randomSeed) * t.edgeHeightVar) : hEdgeH;
	}

	if (p.x < edges[0]) return TilePoint();
	if (p.x > edges[2]) return TilePoint();
	if (p.y < edges[3]) return TilePoint();
	if (p.y > edges[1]) return TilePoint();

	float width = edges[2] - edges[0];
	float height = edges[1] - edges[3];
	if (width < 0 || height < 0) return TilePoint();

	TilePoint tp = corner(p.x - edges[0], p.y - edges[3], width, height, t);	
	if (tp.d < 0) return tp; // On edge

	//if (t.tileID || t.mapUV)
		tp.id = id;

	if (t.center || (t.mapUV && dir))
		tp.center = Point3(edges[0] + (edges[2] - edges[0]) * .5f,
		                   edges[3] + (edges[1] - edges[3]) * .5f, p.z);

	if (dir) {
		offsetEdges(edges, -tp.center.x, -tp.center.y);
		rotate90(edges[0], edges[3]);
		rotate90(edges[2], edges[1]);
		offsetEdges(edges, tp.center.x, tp.center.y);
		p -= tp.center; rotate90(p.x, p.y); p += tp.center;
	}
	
	if (t.mapUV)
		uvMapping(tp, p, edges, t, dir);

	if (dir) {
		offsetEdges(edges, -tp.center.x, -tp.center.y);
		rotate270(edges[0], edges[3]);
		rotate270(edges[2], edges[1]);
		offsetEdges(edges, tp.center.x, tp.center.y);
		p -= tp.center; rotate270(p.x, p.y); p += tp.center;
	}

	return tp;	
}
コード例 #4
0
ファイル: XGTile.cpp プロジェクト: ppl3232/XGame
TilePoint TilePoint::createFromIndex(int indexInArray, TileMapSize mapSize)
{
	return TilePoint(indexInArray%mapSize.width, indexInArray/mapSize.width);
}
コード例 #5
0
ファイル: XGTile.cpp プロジェクト: ppl3232/XGame
XGTile* XGTile::createWithXY(int x, int y)
{
	return create(TilePoint(x, y));
}
コード例 #6
0
TilePoint MapModel::tileCoordForMapPoint(MapPoint mapLoc, int level){
	const int MH = _tileMap->getMapSize().height;

	return TilePoint(mapLoc.x, (MH - (mapLoc.y + 1) * 2 - level + 1));
}
コード例 #7
0
TilePoint MapModel::tileCoordForPosition(Point position){
	int x = position.x / _tileMap->getTileSize().width;
	int y = (_tileMap->getMapSize().height *_tileMap->getTileSize().height - position.y) / _tileMap->getTileSize().height;

	return TilePoint(x, y);
}
コード例 #8
0
ファイル: transform.cpp プロジェクト: thdtjsdn/geojson-vt-cpp
TilePoint Transform::transformPoint(
    const ProjectedPoint& p, uint16_t extent, uint32_t z2, uint32_t tx, uint32_t ty) {
    int16_t x = trans(p.x, extent, z2, tx);
    int16_t y = trans(p.y, extent, z2, ty);
    return TilePoint(x, y);
}