mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-24 17:26:41 +00:00
Cleanup to world<->window coord conversion; add toWorldFromWindow() Lua func
This commit is contained in:
parent
be99840c6a
commit
d47aeea2ce
3 changed files with 23 additions and 14 deletions
|
@ -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),
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue