Quantcast using both :SetTexCoord and :SetRotation() - WoWInterface
Thread Tools Display Modes
03-26-18, 02:25 AM   #1
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
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
  Reply With Quote
03-26-18, 12:07 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,541
I think kgPanels allows you to both crop and rotate a texture. You could see how it does it.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-26-18, 12:55 PM   #3
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
Originally Posted by Seerah View Post
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
  Reply With Quote
03-26-18, 01:03 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,051
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.
  Reply With Quote
03-26-18, 01:17 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,541
Originally Posted by semlar View Post
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.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-26-18, 05:57 PM   #6
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 284
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
03-27-18, 01:07 AM   #7
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
Thanks all, I'm impressed with the math knowledge a lot of you have, I guess I should have paid better attention at class

Originally Posted by Vrul View Post
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
  Reply With Quote
03-27-18, 01:46 PM   #8
Tim
A Cobalt Mageweaver
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 237
Not sure if zork's oUF_RingThing will help you at all but here: https://www.wowinterface.com/downloa...RingThing.html
__________________
AddOns: [email protected]
Website: Ciraxe' Shenanigans
Chars: Monk, Viskaz, Mage, Shaman
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » using both :SetTexCoord and :SetRotation()

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off