Page 1 of 1

Tiled Polygons - how to make tiled world smooth

Posted: Sun May 28, 2023 11:13 pm
by darkfrei
Hi all!

Here is a small tool to make the world, where the tile has size 1x1 tile and the polygon has the same size.
So it's possible to make tiles with polygons:
Screenshot 2023-05-29 010639.png
Screenshot 2023-05-29 010639.png (36.27 KiB) Viewed 11479 times
Screenshot 2023-05-29 010211.png
Screenshot 2023-05-29 010211.png (43.39 KiB) Viewed 11479 times
The idea was from isolines and isobands, each isoband is actually several polygons in tile with interpolation of corners.

Code: Select all

-- License CC0 (Creative Commons license) (c) darkfrei, 2023

-- tiled polygons

local tp = {}

tp.maxValue = 4

function tp.newWorld (width, height, scale)
	local w = 0
	local weigths = {}
	local minX, maxX = 1, width
	local minY, maxY = 1, height
	for y = minY, maxY+1 do
		weigths[y] = {}
		for x = minX, maxX+1 do
--			weigths[y][x] = tp.maxValue-1
			weigths[y][x] = love.math.random (tp.maxValue-1)+1
--			weigths[y][x] = 0
--			weigths[y][x] = w
--			w = (w+(x^2)*(x+width)+3*(x*y)^2+y)%tp.maxValue+1
		end
	end
	tp.minX, tp.maxX = minX, maxX
	tp.minY, tp.maxY = minY, maxY
	tp.weigths = weigths
	tp.scale = scale
	
	local world = {}
	for y = minY, maxY do
		world[y] = {}
		for x = minX, maxX do
			local tile = {x=x, y=y, w=1, h=1, polygon = nil}
			world[y][x] = tile
			
		end
	end
	

	
	tp.world = world
	
	for y = minY, maxY do
		for x = minX, maxX do
			tp.updateTile (x, y)
		end
	end
end

function tp.drawWeights ()
	local weigths, scale = tp.weigths, tp.scale
	love.graphics.push()
	love.graphics.scale (scale)
	love.graphics.setLineWidth (1/scale)
	for y = tp.minY, tp.maxY+1 do
		for x = tp.minX, tp.maxX+1 do
			local value = weigths[y][x]
			love.graphics.circle ('line', x-1, y-1, 0.5*(value+1)/(tp.maxValue+1))
		end
	end
	love.graphics.pop()
end

function tp.drawTiles ()
	local world, scale = tp.world, tp.scale
	love.graphics.push()
	love.graphics.scale (scale)
	love.graphics.setLineWidth (1/scale)
	for y = tp.minY, tp.maxY do
		for x = tp.minX, tp.maxX do
			local tile = world[y][x]
			if tile.fill then
				love.graphics.rectangle ('line', x-1, y-1, 1, 1)
			elseif tile.polygon then
--				love.graphics.polygon ('fill', tile.polygon)
				love.graphics.polygon ('line', tile.polygon)
			else
--				love.graphics.rectangle ('line', x-1, y-1, 1, 1)
			end
		end
	end
	love.graphics.pop()
end

function tp.drawCursor ()
	local world, scale = tp.world, tp.scale
	local weigths = tp.weigths
	love.graphics.push()
	love.graphics.scale (scale)
	love.graphics.setLineWidth (4/scale)
--	love.graphics.circle ('line', tp.cursor.x-1, tp.cursor.y-1, 0.5)
	local value = weigths[tp.cursor.y][tp.cursor.x]
	love.graphics.circle ('line', tp.cursor.x-1, tp.cursor.y-1, 0.5*(value+1)/(tp.maxValue+1))
	love.graphics.pop()
end

function tp.drawWorld (world, scale)
--	tp.drawWeights ()
	tp.drawTiles ()
	tp.drawCursor ()
end


tp.cursor = {x=1, y=1}

function tp.getCursorPosition (x, y)
	local scale = tp.scale
	x = math.min (math.floor((x)/scale+0.5), tp.maxX)+1
	y = math.min (math.floor((y)/scale+0.5), tp.maxY)+1
	love.window.setTitle (x..' '..y)
	return x, y
end


local function calculateValue(x, y, base)
  local result
  if x < base then
    result = (base - x) / (base + 1)
  else
    result = (y + 1) / (base + 1)
  end
  return result
end


function tp.updateTile (x, y)
	local tile = tp.world and tp.world[y] and tp.world[y][x]
	if not tile then return end
	
	local weigths = tp.weigths
	local w1 = weigths[y][x]
	local w2 = weigths[y][x+1]
	local w3 = weigths[y+1][x+1]
	local w4 = weigths[y+1][x]
	local b1 = (w1 == tp.maxValue) and true or false
	local b2 = (w2 == tp.maxValue) and true or false
	local b3 = (w3 == tp.maxValue) and true or false
	local b4 = (w4 == tp.maxValue) and true or false
	
	
	if b1 and b2 and b3 and b4 then
		tile.polygon = nil
		tile.fill = true
		return
	elseif not (b1 or b2 or b3 or b4) then
		tile.polygon = nil
		tile.fill = false
		return
	end
	
	local polygon = {}
	if b1 then
		table.insert (polygon, x-1)
		table.insert (polygon, y-1)
	end
	if (b1 and not b2) or (not b1 and b2) then
		table.insert (polygon, x-1+calculateValue(w1, w2, tp.maxValue))
		table.insert (polygon, y-1)
	end
	if b2 then
		table.insert (polygon, x)
		table.insert (polygon, y-1)
	end
	
	if (b2 and not b3) or (not b2 and b3) then
		table.insert (polygon, x)
		table.insert (polygon, y-1+calculateValue(w2, w3, tp.maxValue))
	end
	
	if b3 then
		table.insert (polygon, x)
		table.insert (polygon, y)
	end
	
	
	if (b3 and not b4) or (not b3 and b4) then
		table.insert (polygon, x-1+calculateValue(w4, w3, tp.maxValue))
		table.insert (polygon, y)
	end
	
	if b4 then
		table.insert (polygon, x-1)
		table.insert (polygon, y)
	end
	
	if (b1 and not b4) or (not b1 and b4) then
		table.insert (polygon, x-1)
		table.insert (polygon, y-1+calculateValue(w1, w4, tp.maxValue))
	end
	
--	print (#polygon)
	tile.fill = false
	if #polygon > 5 then
--		print (table.concat (polygon, ", "))
		tile.polygon = polygon
	else
		tile.polygon = nil
	end
end

function tp.updateWeight (x, y)
	tp.updateTile (x, y)
	tp.updateTile (x-1, y-1)
	tp.updateTile (x-1, y)
	tp.updateTile (x, y-1)
end

function tp.wheelmoved (wx, wy)
	local cx, cy = tp.cursor.x, tp.cursor.y
	local value = tp.weigths[cy][cx]
	tp.weigths[cy][cx] = math.max (0, math.min(tp.maxValue,value + wy))
	tp.updateWeight (cx, cy)
end

function tp.mousemoved (mx, my)
	local cx, cy = tp.getCursorPosition (mx, my)
	tp.cursor.x, tp.cursor.y = cx, cy
end

return tp
Select the weight point and move the mouse wheel.

Re: Tiled polygons

Posted: Thu Jun 22, 2023 9:31 am
by darkfrei
The list of polygons with side 2:

Code: Select all

local tpSet2 = {
	side = 2,

	vertices = {
		{0,0},
		{1,0},
		{2,0},
		{2,1},
		{2,2},
		{1,2},
		{0,2},
		{0,1},
	},
	
	polygons = {
		{1, 3, 5, 7}, -- full
		--1a
		{1, 3, 4},
		{1, 3, 5},
		{1, 3, 5, 6},
		--1b
		{1, 4, 5, 7},
		{1, 5, 7},
		{1, 6, 7},
		
		--2a
		{2, 3, 4},
		{2, 3, 5},
		{2, 3, 5, 6},
		{2, 3, 5, 7},
		{2, 3, 5, 7, 8},
		--2b
		{2, 8, 1},
		{2, 7, 1},
		{2, 6, 7, 1},
		{2, 5, 7, 1},
		{2, 4, 5, 7, 1},
		
		--3a
		{3, 5, 6},
		{3, 5, 7},
		{3, 5, 7, 8},
		--3b
		{3, 6, 7, 1},
		{3, 7, 1},
		{3, 8, 1},
		
		--4a
		{4, 5, 6},
		{4, 5, 7},
		{4, 5, 7, 8},

		--4b
		{4, 8, 1, 3},
		{4, 7, 1, 3},
		{4, 6, 7, 1, 3},

		-- atually both 8:
		--5a
		{5, 7, 8},
		--5b
		{5, 8, 1, 3},
		
		--6a
		{6, 7, 8},
		--6b
		{6, 8, 1, 3, 5},
		
	},
}

return tpSet2
2023-06-22T11_26_48-tpSet2.png
2023-06-22T11_26_48-tpSet2.png (36.31 KiB) Viewed 11294 times

Re: Tiled polygons

Posted: Sun Jul 02, 2023 2:22 pm
by tourgen
pretty neat, thanks for posting

Re: Tiled polygons

Posted: Tue Jul 04, 2023 3:28 pm
by darkfrei
tile polygons size 4 is too big, it looks like we need 40 polygons + mirrored versions of them + 4 rotations of all of them.
And also square.

So here is a code how to make just one set of 40 polygons:

Code: Select all

-- tpSet4
-- Set of Tiled Polygons with size 4

local function createTpSet4Procedural()
	-- Define the surrounding vertices
	local size = 4
	local vertices = {}
	for i = 1, size do
		local t1 = i - 1
		vertices[i] = {t1, 0}
		vertices[i + size] = {size, t1}
		local t2 = size - i + 1
		vertices[i + size * 2] = {t2, size}
		vertices[i + size * 3] = {0, t2}
	end
	print (#vertices .. ' vertices')

	local sides = {{},{},{},{}}
	for i = 1, size + 1 do
		table.insert(sides[1], i)
		table.insert(sides[2], i + size)
		table.insert(sides[3], i + 2 * size)
		table.insert(sides[4], i + 3 * size)
	end

	local corners = {{},{},{},{}}
	for i = 1, 2 * size + 1 do
		table.insert(corners[1], i)
		table.insert(corners[2], i + size)
		table.insert(corners[3], i + 2 * size)
		table.insert(corners[4], i + 3 * size)
	end

	local edges = {1, size + 1, 2 * size + 1, 3 * size + 1}
	local amount = #vertices

	local polygons = {}
	local polygonHash = {}

	local v2 = size + 1 -- 5
	local v3 = 2*size + 1 -- 9
	local v4 = 3*size + 1 -- 13

	-- first is from corner along side:
	for v1 = 1, size do

		

		local v_to = #vertices
		if v1 == 1 then
			v_to = v4-1
		end

		for v_last = v2+1, v_to do
			
			local polygon = {v1}

			if v_last > v2 then 
				table.insert (polygon, v2)
				if v_last > v3 then 
					table.insert (polygon, v3)
					if v_last > v4 then 
						table.insert (polygon, v4)
					end
				end
			end

			table.insert (polygon, v_last)

			table.insert(polygons, polygon)
		end

	end

	local tpSet4 = {
		side = size,
		vertices = vertices,
		polygons = polygons,
	}
	return tpSet4
end


------------------------
------------------------

local function showVertices (tpSet)
	local vertices = tpSet.vertices
	print ('#vertices:', #vertices)
	print ('vertices = {')
	for i, vertice in ipairs (vertices) do
		print ('	{'..table.concat(vertice, ',')..'}, --' .. i)
	end
	print ('}')
end

local function showPolygons (tpSet)
	local polygons = tpSet.polygons
	print ('#polygons:', #polygons)
	print ('polygons = {')
	for i, polygon in ipairs (polygons) do
		print ('	{'..table.concat(polygon, ',')..'}, --' .. i)
	end
	print ('}')
end

------------------------
------------------------

-- Usage:
local tpSet4 = createTpSet4Procedural()

showVertices (tpSet4)
showPolygons (tpSet4)

return tpSet4
Console output:

Code: Select all

16 vertices
#vertices:	16
vertices = {
	{0,0}, --1
	{1,0}, --2
	{2,0}, --3
	{3,0}, --4
	{4,0}, --5
	{4,1}, --6
	{4,2}, --7
	{4,3}, --8
	{4,4}, --9
	{3,4}, --10
	{2,4}, --11
	{1,4}, --12
	{0,4}, --13
	{0,3}, --14
	{0,2}, --15
	{0,1}, --16
}
#polygons:	40
polygons = {
	{1,5,6}, --1
	{1,5,7}, --2
	{1,5,8}, --3
	{1,5,9}, --4
	{1,5,9,10}, --5
	{1,5,9,11}, --6
	{1,5,9,12}, --7
	{2,5,6}, --8
	{2,5,7}, --9
	{2,5,8}, --10
	{2,5,9}, --11
	{2,5,9,10}, --12
	{2,5,9,11}, --13
	{2,5,9,12}, --14
	{2,5,9,13}, --15
	{2,5,9,13,14}, --16
	{2,5,9,13,15}, --17
	{2,5,9,13,16}, --18
	{3,5,6}, --19
	{3,5,7}, --20
	{3,5,8}, --21
	{3,5,9}, --22
	{3,5,9,10}, --23
	{3,5,9,11}, --24
	{3,5,9,12}, --25
	{3,5,9,13}, --26
	{3,5,9,13,14}, --27
	{3,5,9,13,15}, --28
	{3,5,9,13,16}, --29
	{4,5,6}, --30
	{4,5,7}, --31
	{4,5,8}, --32
	{4,5,9}, --33
	{4,5,9,10}, --34
	{4,5,9,11}, --35
	{4,5,9,12}, --36
	{4,5,9,13}, --37
	{4,5,9,13,14}, --38
	{4,5,9,13,15}, --39
	{4,5,9,13,16}, --40
}
2023-07-04T17_17_06-tpSet4.png
2023-07-04T17_17_06-tpSet4.png (42.58 KiB) Viewed 10736 times

Re: Tiled polygons

Posted: Tue Jul 04, 2023 3:51 pm
by darkfrei
Actually just 160 tiles + full polygon as rectangle:

Code: Select all

#polygons:	160
polygons = {
	{1,5,6}, --1
	{1,5,7}, --2
	{1,5,8}, --3
	{1,5,9}, --4
	{1,5,9,10}, --5
	{1,5,9,11}, --6
	{1,5,9,12}, --7
	{2,5,6}, --8
	{2,5,7}, --9
	{2,5,8}, --10
	{2,5,9}, --11
	{2,5,9,10}, --12
	{2,5,9,11}, --13
	{2,5,9,12}, --14
	{2,5,9,13}, --15
	{2,5,9,13,14}, --16
	{2,5,9,13,15}, --17
	{2,5,9,13,16}, --18
	{3,5,6}, --19
	{3,5,7}, --20
	{3,5,8}, --21
	{3,5,9}, --22
	{3,5,9,10}, --23
	{3,5,9,11}, --24
	{3,5,9,12}, --25
	{3,5,9,13}, --26
	{3,5,9,13,14}, --27
	{3,5,9,13,15}, --28
	{3,5,9,13,16}, --29
	{4,5,6}, --30
	{4,5,7}, --31
	{4,5,8}, --32
	{4,5,9}, --33
	{4,5,9,10}, --34
	{4,5,9,11}, --35
	{4,5,9,12}, --36
	{4,5,9,13}, --37
	{4,5,9,13,14}, --38
	{4,5,9,13,15}, --39
	{4,5,9,13,16}, --40
	{5,9,10}, --41
	{5,9,11}, --42
	{5,9,12}, --43
	{5,9,13}, --44
	{5,9,13,14}, --45
	{5,9,13,15}, --46
	{5,9,13,16}, --47
	{6,9,10}, --48
	{6,9,11}, --49
	{6,9,12}, --50
	{6,9,13}, --51
	{6,9,13,14}, --52
	{6,9,13,15}, --53
	{6,9,13,16}, --54
	{1,6,9,13}, --55
	{1,2,6,9,13}, --56
	{1,3,6,9,13}, --57
	{1,4,6,9,13}, --58
	{7,9,10}, --59
	{7,9,11}, --60
	{7,9,12}, --61
	{7,9,13}, --62
	{7,9,13,14}, --63
	{7,9,13,15}, --64
	{7,9,13,16}, --65
	{1,7,9,13}, --66
	{1,2,7,9,13}, --67
	{1,3,7,9,13}, --68
	{1,4,7,9,13}, --69
	{8,9,10}, --70
	{8,9,11}, --71
	{8,9,12}, --72
	{8,9,13}, --73
	{8,9,13,14}, --74
	{8,9,13,15}, --75
	{8,9,13,16}, --76
	{1,8,9,13}, --77
	{1,2,8,9,13}, --78
	{1,3,8,9,13}, --79
	{1,4,8,9,13}, --80
	{9,13,14}, --81
	{9,13,15}, --82
	{9,13,16}, --83
	{1,9,13}, --84
	{1,2,9,13}, --85
	{1,3,9,13}, --86
	{1,4,9,13}, --87
	{10,13,14}, --88
	{10,13,15}, --89
	{10,13,16}, --90
	{1,10,13}, --91
	{1,2,10,13}, --92
	{1,3,10,13}, --93
	{1,4,10,13}, --94
	{1,5,10,13}, --95
	{1,5,6,10,13}, --96
	{1,5,7,10,13}, --97
	{1,5,8,10,13}, --98
	{11,13,14}, --99
	{11,13,15}, --100
	{11,13,16}, --101
	{1,11,13}, --102
	{1,2,11,13}, --103
	{1,3,11,13}, --104
	{1,4,11,13}, --105
	{1,5,11,13}, --106
	{1,5,6,11,13}, --107
	{1,5,7,11,13}, --108
	{1,5,8,11,13}, --109
	{12,13,14}, --110
	{12,13,15}, --111
	{12,13,16}, --112
	{1,12,13}, --113
	{1,2,12,13}, --114
	{1,3,12,13}, --115
	{1,4,12,13}, --116
	{1,5,12,13}, --117
	{1,5,6,12,13}, --118
	{1,5,7,12,13}, --119
	{1,5,8,12,13}, --120
	{1,2,13}, --121
	{1,3,13}, --122
	{1,4,13}, --123
	{1,5,13}, --124
	{1,5,6,13}, --125
	{1,5,7,13}, --126
	{1,5,8,13}, --127
	{1,2,14}, --128
	{1,3,14}, --129
	{1,4,14}, --130
	{1,5,14}, --131
	{1,5,6,14}, --132
	{1,5,7,14}, --133
	{1,5,8,14}, --134
	{1,5,9,14}, --135
	{1,5,9,10,14}, --136
	{1,5,9,11,14}, --137
	{1,5,9,12,14}, --138
	{1,2,15}, --139
	{1,3,15}, --140
	{1,4,15}, --141
	{1,5,15}, --142
	{1,5,6,15}, --143
	{1,5,7,15}, --144
	{1,5,8,15}, --145
	{1,5,9,15}, --146
	{1,5,9,10,15}, --147
	{1,5,9,11,15}, --148
	{1,5,9,12,15}, --149
	{1,2,16}, --150
	{1,3,16}, --151
	{1,4,16}, --152
	{1,5,16}, --153
	{1,5,6,16}, --154
	{1,5,7,16}, --155
	{1,5,8,16}, --156
	{1,5,9,16}, --157
	{1,5,9,10,16}, --158
	{1,5,9,11,16}, --159
	{1,5,9,12,16}, --160
}
2023-07-04T17_49_33-tpSet4.png
2023-07-04T17_49_33-tpSet4.png (101.77 KiB) Viewed 10728 times

Re: Tiled Polygons - how to make tiled world smooth

Posted: Mon Jul 17, 2023 6:16 am
by darkfrei
(from code doodles viewtopic.php?p=255759#p255759)

Code: Select all

{1,5,9,13}, -- 1
{1,4,10,13}, -- 2
{1,3,11,13}, -- 3
{1,2,12,13}, -- 4
{1,5,8,14}, -- 5
{1,5,8,10,13}, -- 6
{1,5,7,10,13}, -- 7
{1,5,6,10,13}, -- 8
{1,5,10,13}, -- 9
{1,5,7,15}, -- 10
{1,5,8,11,13}, -- 11
{1,5,7,11,13}, -- 12
{1,5,6,11,13}, -- 13
{1,5,11,13}, -- 14
{1,4,11,13}, -- 15
{1,5,6,16}, -- 16
{1,5,8,12,13}, -- 17
{1,5,7,12,13}, -- 18
{1,5,6,12,13}, -- 19
{1,5,12,13}, -- 20
{1,4,12,13}, -- 21
{1,3,12,13}, -- 22
{1,5,8,13}, -- 23
{1,5,7,13}, -- 24
{1,5,6,13}, -- 25
{1,5,13}, -- 26
{1,4,13}, -- 27
{1,3,13}, -- 28
{1,2,13}, -- 29
{1,5,7,14}, -- 30
{1,5,6,14}, -- 31
{1,5,14}, -- 32
{1,4,14}, -- 33
{1,3,14}, -- 34
{1,2,14}, -- 35
{1,5,6,15}, -- 36
{1,5,15}, -- 37
{1,4,15}, -- 38
{1,3,15}, -- 39
{1,2,15}, -- 40
{1,5,16}, -- 41
{1,4,16}, -- 42
{1,3,16}, -- 43
{1,2,16}, -- 44
2023-07-17T08_18_21-Tiled Polygons 2023-07-12.png
2023-07-17T08_18_21-Tiled Polygons 2023-07-12.png (15.15 KiB) Viewed 9932 times

Re: Tiled Polygons - how to make tiled world smooth

Posted: Thu Jan 18, 2024 3:10 am
by knorke
Hi
darkfrei, you make very good code doodles. You should make an actual game or whatever-thing sometime!

It looked like an interesting alternative to my level editor because making caves/tunnels is very quick and easy. (In my editor I have to create each polygon by hand by clicking their corners)
In another thread somehow had asked how to turn these polygons into physical shapes. Maybe this can be a starting point.
For testing I hacked the draw-function into a save-function.

Code: Select all

function tp.dumpTiles ()
	print "dumpTiles"
	local saveT = {walls = {}}	
	local world, scale = tp.world, tp.scale
--[[
	love.graphics.push()
	love.graphics.scale (scale)
	love.graphics.setLineWidth (1/scale)
--]]
	for y = tp.minY, tp.maxY do
		for x = tp.minX, tp.maxX do
			local tile = world[y][x]
			if tile.fill then
				--love.graphics.rectangle ('line', x-1, y-1, 1, 1)
				print "solid tile"
			elseif tile.polygon then
	--				love.graphics.polygon ('fill', tile.polygon)
					--love.graphics.polygon ('line', tile.polygon)
				local sw = {}
				local swpi = 1
				for pi=1,#tile.polygon,2 do
					sw[swpi] = {x=tile.polygon[pi]*scale, y=tile.polygon[pi+1]*scale}
					swpi = swpi + 1
				end
				--sw.pcount = #tile.polygon
				sw.bodyType = "dynamic"
					--print (dump(sw))
				
				table.insert (saveT.walls, sw)
			else
--				love.graphics.rectangle ('line', x-1, y-1, 1, 1)
			end
		end
	end
	--print (dump(saveT))
		love.filesystem.write("zzz", dump (saveT))

	--love.graphics.pop()
end

function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ',\n'
      end
      return s .. '} '
   else
      if type(o) == 'string' then
		return '"'..o..'"'
      else
		return tostring(o)
	  end
   end
end
It creates files like this:

Code: Select all

{ ["walls"] = { [1] = { [1] = { ["y"] = 12.8,
["x"] = 64,
} ,
[2] = { ["y"] = 64,
["x"] = 64,
} ,
[3] = { ["y"] = 64,
["x"] = 12.8,
} ,
["bodyType"] = "dynamic",
} ,
[2] = { [1] = { ["y"] = 64,
...
Basically it just saves the corners of all polygons. When loading the map those tables can be feed into love.physics.newPolygonShape.

Only after seeing a testlevel ingame did I actually read what this doodle was about. (The editing with this thing was so fun that I had not bothered with reading.) It is about tiles. So the created polygons are sadly very inefficient. Often multiple polygons could be combined into one. (For example the three triangles in top left could be one polygon with 4 points) Surprisingly, performance is still good. The map in screenshot has 176 polygons, some might be offscreen, I did not bother with checking the scaling-stuff too much. :o:
Box2D physics uses shapes that are convex and use 8 points maximal.
So it would be useful to somehow combine those polygons into lowest possible number of suitable polygons.

Re: Tiled Polygons - how to make tiled world smooth

Posted: Sat Jan 20, 2024 3:48 pm
by darkfrei
knorke wrote: Thu Jan 18, 2024 3:10 am Only after seeing a testlevel ingame did I actually read what this doodle was about. (The editing with this thing was so fun that I had not bothered with reading.) It is about tiles. So the created polygons are sadly very inefficient. Often multiple polygons could be combined into one. (For example the three triangles in top left could be one polygon with 4 points) Surprisingly, performance is still good. The map in screenshot has 176 polygons, some might be offscreen, I did not bother with checking the scaling-stuff too much. :o:
Box2D physics uses shapes that are convex and use 8 points maximal.
So it would be useful to somehow combine those polygons into lowest possible number of suitable polygons.
Thanks for your reply!
1. Tiles are very good to check what you agent can collide, just as grid[y][x] and don't need to check tiles where collision is impossible.
2. Also you call load and unload tiles just a little bit more than on the screen, just one-two extra more rows and columns.
3. The highest possible amount of vertices is 5, 6 or 8, the lowest is 3, as a triangle.
4. You can make pseudo destructible world, just by replacing polygon with other one, it looks like digging.

Re: Tiled Polygons - how to make tiled world smooth

Posted: Wed Feb 07, 2024 11:02 am
by Nikki
I made a little physics test thing using your 'tiled-polygons-01'

controls are the same (using the mousehweel to grow/shrink the terrain an position)
click will add a bunch of balls