1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-06-08 17:42:05 +00:00

Cleanup to world<->window coord conversion; add toWorldFromWindow() Lua func

This commit is contained in:
fgenesis 2024-04-28 00:03:51 +02:00
parent be99840c6a
commit d47aeea2ce
3 changed files with 23 additions and 14 deletions

View file

@ -8651,15 +8651,16 @@ luaFunc(resetContinuity)
luaFunc(toWindowFromWorld) luaFunc(toWindowFromWorld)
{ {
float x = lua_tonumber(L, 1); Vector p(lua_tonumber(L, 1), lua_tonumber(L, 2));
float y = lua_tonumber(L, 2); p = core->getWindowPosition(p);
x = x - core->screenCenter.x; luaReturnVec2(p.x, p.y);
y = y - core->screenCenter.y; }
x *= core->globalScale.x;
y *= core->globalScale.x; luaFunc(toWorldFromWindow)
x = 400+x; {
y = 300+y; Vector p(lua_tonumber(L, 1), lua_tonumber(L, 2));
luaReturnVec2(x, y); p = core->getGamePosition(p);
luaReturnVec2(p.x, p.y);
} }
luaFunc(setMousePos) luaFunc(setMousePos)
@ -10463,6 +10464,7 @@ static const struct {
luaRegister(warpNaijaToSceneNode), luaRegister(warpNaijaToSceneNode),
luaRegister(toWindowFromWorld), luaRegister(toWindowFromWorld),
luaRegister(toWorldFromWindow),
luaRegister(toggleDamageSprite), luaRegister(toggleDamageSprite),

View file

@ -620,14 +620,19 @@ bool Core::initSoundLibrary(const std::string &defaultDevice)
return sound != 0; return sound != 0;
} }
Vector Core::getGameCursorPosition() Vector Core::getGameCursorPosition() const
{ {
return getGamePosition(mouse.position); 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) bool Core::getMouseButtonState(int m)

View file

@ -273,8 +273,10 @@ public:
void updateWindowDrawSize(int w, int h); void updateWindowDrawSize(int w, int h);
Vector getGameCursorPosition(); Vector getGameCursorPosition() const;
Vector getGamePosition(const Vector &v); Vector getGamePosition(const Vector &winpos) const;
Vector getWindowPosition(const Vector& worldpos) const;
Vector screenCenter; Vector screenCenter;