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() subRegion:Hide()
end 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 = { local funcs = {
Update = function(self, state) Update = function(self, state)
self.trigger_inverse = state.inverse self.trigger_inverse = state.inverse
@@ -316,8 +323,7 @@ local funcs = {
end end
end, end,
UpdateTickRotation = function(self) UpdateTickRotation = function(self)
local rad = math.rad(self.tick_rotation) self:UpdateTexCoord()
self.texture:SetRotation(rad)
end, end,
SetTickMirror = function(self, mirror) SetTickMirror = function(self, mirror)
if self.mirror ~= mirror then if self.mirror ~= mirror then
@@ -326,11 +332,7 @@ local funcs = {
end end
end, end,
UpdateTickMirror = function(self) UpdateTickMirror = function(self)
if self.mirror then self:UpdateTexCoord()
self.texture:SetTexCoord(0, 1, 1, 1, 0, 0, 1, 0)
else
self.texture:SetTexCoord(0, 0, 1, 0, 0, 1, 1, 1)
end
end, end,
SetTickBlendMode = function(self, mode) SetTickBlendMode = function(self, mode)
if self.tick_blend_mode ~= mode then if self.tick_blend_mode ~= mode then
@@ -345,6 +347,14 @@ local funcs = {
self.texture:SetBlendMode("BLEND") self.texture:SetBlendMode("BLEND")
end end
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) local function modify(parent, region, parentData, data, first)