Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Document that objects have a hidden scale #33

Open
Benjamin-Dobell opened this issue May 1, 2020 · 0 comments
Open

Document that objects have a hidden scale #33

Benjamin-Dobell opened this issue May 1, 2020 · 0 comments

Comments

@Benjamin-Dobell
Copy link
Member

Was just helping a user out on Discord regarding the fact that there's a hidden scale in TTS that's presently not exposed via any UI or any Lua APIs.

However, you can obtain this scale as follows:

local CARD_GUID = 'cafebf'

---@param obj tts__Object
---@return Vector
local function getObjectTransformScale(obj)
    local rotation = obj.getRotation()
    local onesVector = Vector(1, 1, 1):rotateOver('z', rotation.z):rotateOver('x', rotation.x):rotateOver('y', rotation.y)
    local scale = obj.positionToLocal(obj.getPosition():add(onesVector))
    return scale
end

function onLoad()
    local obj = getObjectFromGUID(CARD_GUID)
    print("Public scale:\n" .. logString(obj.getScale()))
    print("Hidden scale:\n" .. logString(getObjectTransformScale(obj)))
end

This scale comes into play most prominently with cards. Basically depending on the aspect ratio of your cards you'll have a different "object transform scale". However, by default, your cards will always report getScale() as Vector(1, 1, 1).

This scale particularly comes into play when you're trying to accurately convert from known pixel coordinates on your cards to in-game coordinates, say if you're trying to place a decal in a precise location on a card face.

Honestly, I'm not even sure how to properly document this without confusing people further, but it really is important in certain situations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant