Jump to content




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


2 replies to this topic

#1 Agent Silence

  • Members
  • 319 posts
  • Location[string "FindMe"]:23143: bad argument #1 to 'returnPos' (vector expected, got nil)

Posted 17 June 2016 - 08: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).

#2 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 17 June 2016 - 09: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

#3 Agent Silence

  • Members
  • 319 posts
  • Location[string "FindMe"]:23143: bad argument #1 to 'returnPos' (vector expected, got nil)

Posted 17 June 2016 - 09: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 by Agent Silence, 17 June 2016 - 09:15 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users