use texcoords to rotate ticks

This commit is contained in:
Bunny67
2022-01-01 18:09:23 +03:00
parent dee287623d
commit 02fe0ca2e6
+17 -7
View File
@@ -122,6 +122,13 @@ local function onRelease(subRegion)
subRegion:Hide()
end
local function getRotatedPoints(degrees)
local angle = rad(135 - degrees)
local vx = math.cos(angle)
local vy = math.sin(angle)
return 0.5+vx, 0.5-vy, 0.5-vy, 0.5-vx, 0.5+vy, 0.5+vx, 0.5-vx, 0.5+vy
end
local funcs = {
Update = function(self, state)
self.trigger_inverse = state.inverse
@@ -316,8 +323,7 @@ local funcs = {
end
end,
UpdateTickRotation = function(self)
local rad = math.rad(self.tick_rotation)
self.texture:SetRotation(rad)
self:UpdateTexCoord()
end,
SetTickMirror = function(self, mirror)
if self.mirror ~= mirror then
@@ -326,11 +332,7 @@ local funcs = {
end
end,
UpdateTickMirror = function(self)
if self.mirror then
self.texture:SetTexCoord(0, 1, 1, 1, 0, 0, 1, 0)
else
self.texture:SetTexCoord(0, 0, 1, 0, 0, 1, 1, 1)
end
self:UpdateTexCoord()
end,
SetTickBlendMode = function(self, mode)
if self.tick_blend_mode ~= mode then
@@ -345,6 +347,14 @@ local funcs = {
self.texture:SetBlendMode("BLEND")
end
end,
UpdateTexCoord = function(self)
local ulx, uly, llx, lly, urx, ury, lrx, lry = getRotatedPoints(self.tick_rotation);
if self.mirror then
self.texture:SetTexCoord(urx, ury, lrx, lry, ulx, uly, llx, lly);
else
self.texture:SetTexCoord(ulx, uly, llx, lly, urx, ury, lrx, lry);
end
end,
}
local function modify(parent, region, parentData, data, first)