This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LDDestroier's profile picture

My minimap's offscreen points don't show up how I want

Started by LDDestroier, 10 June 2015 - 03:00 PM
LDDestroier #1
Posted 10 June 2015 - 05:00 PM
I made a gps minimap program, and it's really been the only thing I've been working on. The way it deals with off-screen waypoints is it draws it on the side it's gone past, but also at it's x position. Let me draw a diagram to explain.


I really need help with this little problem, as I've put it off too long…and don't have quite the skills to fix it myself.

Pastebin is at here: x9ajKSc0
Code:
Spoiler

    if itemX > corner1[1] and itemX < corner2[1] and itemZ < corner2[2] and itemZ > corner1[2] then
	 if not (itemX == midPoint[1] and itemZ == midPoint[2]) then
	  if isConnected then
	   if colormode then
	    term.setTextColor(mapColors[3])
	   else
	    term.setTextColor(colors.white)
	    term.setBackgroundColor(colors.black)
	   end
	   write(waypointChar)
	   else
	   if colormode then
	    term.setTextColor(mapColors[8])
	   else
	    term.setTextColor(colors.black)
	   end
	  end
	 end
    else
	 if colormode then
	  term.setTextColor(mapColors[4])
	  term.setBackgroundColor(mapColors[2])
	 else
	  term.setTextColor(colors.white)
	  term.setBackgroundColor(colors.black)
	 end
	 if itemX <= corner1[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
	  term.setCursorPos(corner1[1],itemZ)
	  write("<")
	 elseif itemX <= corner1[1] and itemZ <= corner1[2] then
	  term.setCursorPos(corner1[1],corner1[2])
	  if itemX * -1 >= itemZ * -1 then
	   write("<")
	  else
	   write("^")
	  end
	 elseif itemX <= corner1[1] and itemZ >= corner2[2] then
	  term.setCursorPos(corner1[1],corner2[2])
	  if itemX * -1 >= itemZ then
	   write("<")
	  else
	   write("v")
	  end
	 elseif itemX >= corner2[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
	  term.setCursorPos(corner2[1],itemZ)
	  write(">")
	 elseif itemX >= corner2[1] and itemZ <= corner1[2] then
	  term.setCursorPos(corner2[1],corner1[2])
	  if itemX >= itemZ * -1 then
	   write(">")
	  else
	   write("^")
	  end
	 elseif itemX >= corner2[1] and itemZ >= corner2[2] then
	  term.setCursorPos(corner2[1],corner2[2])
	  if itemX >= itemZ then
	   write(">")
	  else
	   write("v")
	  end
	 elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ <= corner1[2] then
	  term.setCursorPos(itemX,corner1[2])
	  write("^")
	 elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ >= corner2[2] then
	  term.setCursorPos(itemX,corner2[2])
	  write("v")
	 end
	 setDefaultColors()
    end
Edited on 10 June 2015 - 03:03 PM
KingofGamesYami #2
Posted 10 June 2015 - 06:08 PM
Well, I haven't looked at your code at all, but the way you'd handle this is pretty simple.

First, make two equations for the line: one which gives you y, one that gives you x.

y = (px/py) * x
This is derived from y = mx + b, where we assume the first point is (0, 0) and b is 0.

Then, we can reverse this to get x from y:

x = (px/py) / y

Next, test max / min values of x / y to find a set of coordinates that appear on screen when added to the position on the map.