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

How to emulate (0,0) at a different coordinate on a window

Started by Agent Silence, 17 June 2016 - 07:55 PM
Agent Silence #1
Posted 17 June 2016 - 09:55 PM
I need to rotate things around the center of a window made with the window api, and it would be much easier if I was able to set (0,0) to the center of the window, making it a cartesian system instead of a top left system then using the equation for rotation. However, I have absolutely no idea how to set (0,0) to a different coordinate(the center of window).
TYKUHN2 #2
Posted 17 June 2016 - 10:02 PM
You can replace term.getCursorPos but good luck with that, you'd have to keep an old copy and do math on an uneven plane
Agent Silence #3
Posted 17 June 2016 - 10:14 PM
Got it!
If anyone is curious, I turned it into a cartesian coordinate system using this

local map = window.create(term.native(),0,0,29,20)
local oldCursorPos = map.setCursorPos
local oldGetCP = map.getCursorPos
local maxX, maxY = map.getSize()
map.getCursorPos = function() local x,y = oldGetCP() return x-(math.ceil(maxX/2)),-(y-(math.ceil(maxY/2))) end
map.setCursorPos = function(x,y) oldCursorPos(x+(math.ceil(maxX/2)),-(y-(math.ceil(maxY/2)))) end
Edited on 17 June 2016 - 08:15 PM