diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 8622d85..ea0afa2 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -8651,15 +8651,16 @@ luaFunc(resetContinuity) luaFunc(toWindowFromWorld) { - float x = lua_tonumber(L, 1); - float y = lua_tonumber(L, 2); - x = x - core->screenCenter.x; - y = y - core->screenCenter.y; - x *= core->globalScale.x; - y *= core->globalScale.x; - x = 400+x; - y = 300+y; - luaReturnVec2(x, y); + Vector p(lua_tonumber(L, 1), lua_tonumber(L, 2)); + p = core->getWindowPosition(p); + luaReturnVec2(p.x, p.y); +} + +luaFunc(toWorldFromWindow) +{ + Vector p(lua_tonumber(L, 1), lua_tonumber(L, 2)); + p = core->getGamePosition(p); + luaReturnVec2(p.x, p.y); } luaFunc(setMousePos) @@ -10463,6 +10464,7 @@ static const struct { luaRegister(warpNaijaToSceneNode), luaRegister(toWindowFromWorld), + luaRegister(toWorldFromWindow), luaRegister(toggleDamageSprite), diff --git a/BBGE/Core.cpp b/BBGE/Core.cpp index e40fc34..cb4a7e7 100644 --- a/BBGE/Core.cpp +++ b/BBGE/Core.cpp @@ -620,14 +620,19 @@ bool Core::initSoundLibrary(const std::string &defaultDevice) return sound != 0; } -Vector Core::getGameCursorPosition() +Vector Core::getGameCursorPosition() const { return getGamePosition(mouse.position); } -Vector Core::getGamePosition(const Vector &v) +Vector Core::getGamePosition(const Vector &winpos) const { - return cameraPos + (v * invGlobalScale); + return cameraPos + (winpos * invGlobalScale); +} + +Vector Core::getWindowPosition(const Vector &worldpos) const +{ + return (worldpos - cameraPos) * globalScale.x; } bool Core::getMouseButtonState(int m) diff --git a/BBGE/Core.h b/BBGE/Core.h index 7d158b4..fc7228c 100644 --- a/BBGE/Core.h +++ b/BBGE/Core.h @@ -273,8 +273,10 @@ public: void updateWindowDrawSize(int w, int h); - Vector getGameCursorPosition(); - Vector getGamePosition(const Vector &v); + Vector getGameCursorPosition() const; + Vector getGamePosition(const Vector &winpos) const; + Vector getWindowPosition(const Vector& worldpos) const; + Vector screenCenter;