View Single Post
03-26-18, 05:57 PM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by saxitoxin View Post
Any way to fix this without using animGroup and rotate
Maybe, maybe not. Since it is a round texture with something close above you may see a portion you don't want since you are basically rotating a square (tex coords) around a circle.
Code:
local pi_4 = math.pi / 4
local cos, sin, sqrt = math.cos, math.sin, math.sqrt

local function SetTexRotationWithCoord(region, radians, L, R, T, B)
	radians = pi_4 - radians
	local Cx, Cy = (L + R) / 2, (T + B) / 2
	local Z = sqrt((R - Cx)^2 + (B - Cy)^2)
	local Zcos, Zsin = Z * cos(radians), Z * sin(radians)
	region:SetTexCoord(Cx - Zsin, Cy - Zcos, Cx - Zcos, Cy + Zsin, Cx + Zcos, Cy - Zsin, Cx + Zsin, Cy + Zcos)
end
Quick little test addon (mouse wheel to rotate):
Code:
local TEXTURE = [[Interface\Artifacts\ArtifactUIHunter]]
local L, R, T, B = 3/1024, 209/1024, 688/1024, 892/1024
local WINDOW_SIZE = 256

local pi_4 = math.pi / 4
local cos, sin, sqrt = math.cos, math.sin, math.sqrt

local function SetTexRotationWithCoord(region, radians, L, R, T, B)
	radians = pi_4 - radians
	local Cx, Cy = (L + R) / 2, (T + B) / 2
	local Z = sqrt((R - Cx)^2 + (B - Cy)^2)
	local Zcos, Zsin = Z * cos(radians), Z * sin(radians)
	region:SetTexCoord(Cx - Zsin, Cy - Zcos, Cx - Zcos, Cy + Zsin, Cx + Zcos, Cy - Zsin, Cx + Zsin, Cy + Zcos)
end

local frame = CreateFrame('Frame', nil, UIParent)
frame:SetPoint('CENTER', UIParent:GetWidth() / 4, UIParent:GetHeight() / 4)
frame:SetSize(WINDOW_SIZE + 8, WINDOW_SIZE + 8)
frame:SetBackdrop({
    bgFile = [[Interface\BUTTONS\WHITE8X8]],
    edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
    tileSize = 16, tile = true,
    insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
frame:SetBackdropColor(0.05, 0.1, 0.15, 1)
frame:SetBackdropBorderColor(1, 1, 1, 1)
frame:EnableMouse(true)

local texture = frame:CreateTexture(nil, 'ARTWORK')
texture:SetTexture(TEXTURE)
texture:SetSize(WINDOW_SIZE, WINDOW_SIZE)
texture:SetPoint('CENTER')

do
	local pi_16, rotation = math.pi / 16, 0

	frame:SetScript('OnMouseWheel', function(self, delta)
		rotation = rotation - delta * pi_16
		SetTexRotationWithCoord(texture, rotation, L, R, T, B)
	end)
end

SetTexRotationWithCoord(texture, 0, L, R, T, B)
  Reply With Quote