WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   using both :SetTexCoord and :SetRotation() (https://www.wowinterface.com/forums/showthread.php?t=56128)

saxitoxin 03-26-18 02:25 AM

using both :SetTexCoord and :SetRotation()
 
Hi!

I'm trying as the title says to use both :SetTexCoord and :SetRotation() on the same texture


Lua Code:
  1. CREATING FRAMES AND STUFF UP HERE
  2.  
  3. mainFrame.icon = mainFrame:CreateTexture(nil,"OVERLAY",nil,-8)
  4. mainFrame.icon:SetPoint("CENTER")
  5. mainFrame.icon:SetSize(mainFrame:GetWidth()*iconScale, mainFrame:GetWidth()*iconScale)
  6. mainFrame.icon:SetTexture(unpack(cfg.SXwpClassInfo[cfg.classNumber]))
  7.  
  8. mainFrame.icon:SetTexCoord(unpack(cfg.SXwpClassInfoTexCoord[cfg.classNumber]))
  9. mainFrame.icon:SetRotation(math.rad(0))

what I try to do with this code is to first set the coord for the bottom left emblem on THIS image, then I want to rotate it based on a slidervalue (set longer down in the code), but if I use the mainFrame.icon:SetRotation(math.rad(0)) command the image show uncropped

Any way to fix this without using animGroup and rotate

Seerah 03-26-18 12:07 PM

I think kgPanels allows you to both crop and rotate a texture. You could see how it does it.

saxitoxin 03-26-18 12:55 PM

Quote:

Originally Posted by Seerah (Post 327366)
I think kgPanels allows you to both crop and rotate a texture. You could see how it does it.

I just tested it, and unfortunately I can not both rotate and crop in KGpanels, but thanks a lot for the tip

semlar 03-26-18 01:03 PM

You can rotate the coordinates that you're sending to SetTexCoord with a matrix transformation (rotation matrix), which takes your input coordinates and rotates them around a central point (the middle of your coordinate pairs).

If you're rotating in 90 degree increments, you can skip doing any math and just shift the coordinates over (they're x,y pairs representing the corners of your texture). By moving the order of the SetTexCoord arguments by 2 you're changing which corner of the texture coordinates is being attached to which corner of your texture object.

This page has some lua examples if you need to rotate by an arbitrary amount, but if this all seems overwhelmingly confusing I would probably just use an animation to do it.

I think SetRotation essentially applies SetTexCoord in the background so I don't know that they can be used together.

Seerah 03-26-18 01:17 PM

Quote:

Originally Posted by semlar (Post 327368)
If you're rotating in 90 degree increments, you can skip doing any math and just shift the coordinates over (they're x,y pairs representing the corners of your texture). By moving the order of the SetTexCoord arguments by 2 you're changing which corner of the texture coordinates is being attached to which corner of your texture object.

Yes, this is probably best for 90 degree increments. You put what coordinates you would like as your top left, for example. (:SetTexCoord() can accept 8 arguments rather than 4.) You might even be about to use this for other rotation angles, if your math is correct.

Vrul 03-26-18 05:57 PM

Quote:

Originally Posted by saxitoxin (Post 327361)
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)


saxitoxin 03-27-18 01:07 AM

Thanks all, I'm impressed with the math knowledge a lot of you have, I guess I should have paid better attention at class :confused:

Quote:

Originally Posted by Vrul (Post 327372)
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:

***
Quick little test addon (mouse wheel to rotate):
Code:

***

Thank you so much for this!
But unfortunately as you said it is a round texture with something close. I did not take that into consideration when I wanted to rotate the texture.
Guess I have to try to use the animGroup then :)

Tim 03-27-18 01:46 PM

Not sure if zork's oUF_RingThing will help you at all but here: https://www.wowinterface.com/downloa...RingThing.html


All times are GMT -6. The time now is 08:27 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI