Thread Tools Display Modes
11-10-10, 04:34 PM   #1
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
How to rotate a frame?

Code:
local addon = CreateFrame("Frame", "Base2", UIParent)
addon:SetHeight(128)
addon:SetWidth(128)
addon:SetUserPlaced(true)
addon:SetPoint("Center", 100, 0)

local tex = addon:CreateTexture(nil, "ARTWORK")
tex:SetTexture(file)
tex:SetAllPoints(addon)
Is what I have right now creating a frame filled with a picture

What I want to do is rotate the picture to a certain angle
What can I do to accomplish this?

I thinkg SetDegrees() only works with animations?
  Reply With Quote
11-10-10, 04:46 PM   #2
Kjado
A Deviate Faerie Dragon
 
Kjado's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 10
You will need to use SetTexCoord() and linear transformations to rotate a texture. This wowpedia link has some mathematical background associated with it, but if you are only interested in grabbing some code to rotate you can probably skip towards the bottom.
__________________
My projects - Primal Defense | EchoPort | QuickTradeskill
  Reply With Quote
11-10-10, 05:05 PM   #3
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Code:
local angle = math.rad(90)
local cos, sin = math.cos(angle), math.sin(angle)
tex:SetTexCoord((sin - cos), -(cos + sin), -cos, -sin, sin, -cos, 0, 0)
Added this code in, except now my texture doesn't show up in game. Am I missing something?
  Reply With Quote
11-10-10, 05:17 PM   #4
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
myTexture:SetRotation(math.rad(90))
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-10-10, 05:26 PM   #5
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Code:
local addon = CreateFrame("Frame", "Base2", UIParent)
addon:SetHeight(128)
addon:SetWidth(128)
addon:SetUserPlaced(true)
addon:SetPoint("Center", 100, 0)

local tex = addon:CreateTexture(nil, "ARTWORK")
tex:SetTexture(file)
tex:SetAllPoints(addon)
tex:SetRotation(math.rad(90))
Rotated it 90 degrees but skews the image slightly, any idea why?

The height and width are the same are they not?

So I assume this shouldn't happen... : /
  Reply With Quote
11-10-10, 05:37 PM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
[quote=lilgulps;217270Rotated it 90 degrees but skews the image slightly, any idea why?[/QUOTE]

Try to add one transparent pixel at all sides of you texture. Without this SetTexCoord can "distort" the texture.
  Reply With Quote
11-10-10, 05:55 PM   #7
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Well... maybe its best if I just show a picture to show what its doing lol

With SetRotation(math.rad(0))


without


So if you can't tell the only part of my image that isn't transparent is the bars and box.

Should I try a different extension than .tga?
  Reply With Quote
11-10-10, 06:04 PM   #8
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Beat me ... but I can't see any differences.
  Reply With Quote
11-10-10, 06:06 PM   #9
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
One is a lot smaller than the other one!!!
  Reply With Quote
11-10-10, 06:11 PM   #10
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
well the increase the size to compensate

also note that :SetRotation goes counter clockwise...

so to go clockwise do

:SetRotation(math.rad(360-degree))

also, if your only gonna rotate it 0 degrees. why rotate?
And if you dont have transparent pixels surrounding the image, your pretty much constrained to 0, 90, 180, and 270
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-10-10, 06:18 PM   #11
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by lilgulps View Post
One is a lot smaller than the other one!!!
Must be a "flaw" in SetRotation.

You could test a "grid" texture without transparent pixels and a frame border to see how the texture actually is transformed.
  Reply With Quote
11-10-10, 06:20 PM   #12
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Originally Posted by Xubera View Post
well the increase the size to compensate

also note that :SetRotation goes counter clockwise...

so to go clockwise do

:SetRotation(math.rad(360-degree))

also, if your only gonna rotate it 0 degrees. why rotate?
And if you dont have transparent pixels surrounding the image, your pretty much constrained to 0, 90, 180, and 270
I'm not rotating by 0, I was just trying to demonstrate the size difference error I don't understand why i'm getting after using that function
  Reply With Quote
11-10-10, 06:27 PM   #13
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
well it might help if you try what zork said in one of his tutorials...

Get a real life sheet of paper and mark the corners UL, UR, LL, LR (upper/lower left/right)

so then :SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
so when it is rightside up (0,0, 0,1, 1,0, 1,1)

so when we rotate the image clockwise 90 degrees (12 oclock to 3oclock) we get upperleft has LL, lower left has LR, upper right has UL and the lower right has the UR

so now we just plug it in

:SetTexCoord(0,1, 1,1, 0,0, 1,0)
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-10-10, 06:39 PM   #14
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Originally Posted by Xubera View Post
well it might help if you try what zork said in one of his tutorials...

Get a real life sheet of paper and mark the corners UL, UR, LL, LR (upper/lower left/right)

so then :SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
so when it is rightside up (0,0, 0,1, 1,0, 1,1)

so when we rotate the image clockwise 90 degrees (12 oclock to 3oclock) we get upperleft has LL, lower left has LR, upper right has UL and the lower right has the UR

so now we just plug it in

:SetTexCoord(0,1, 1,1, 0,0, 1,0)
Yah I will probably end up doing that, but if there is an easier way, using this shortcut function why not use it right? Not to mention I am curious as to why its doing this

I should probably clarify what I am doing... I have a speedometer like picture, and a texture that is effectively the needle for the speedometer. I would like to be able to just "overlay" the needle ontop of the speedometer and use a rotate function to twist the needle to the places on the speedometer I want.



I took these screenies trying out a a grid with and without a border like you suggested. And now I can kind of see how its resizing things... could the main issue here be the
Code:
tex:SetAllPoints(addon)
Command that is interfering?

Thank you guys for all the help by the way

EDIT: Using Zork's method the sizing is not an issue. Do you possibly have a link to the tutorial since I don't think I have ever seen his?

Last edited by lilgulps : 11-10-10 at 06:46 PM.
  Reply With Quote
11-10-10, 06:51 PM   #15
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Means SetRotation resizes the texture so that the transformed texture fits into the texture-widget?

Guess you'll have to use SetTexCoord.

btw, I build a similar addon a while ago: http://www.wowinterface.com/download...25-Speedo.html
  Reply With Quote
11-10-10, 07:01 PM   #16
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
What did you use to rotate your pointer in that addon?

I'm lookin but your file is very large haha
  Reply With Quote
11-10-10, 07:04 PM   #17
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by lilgulps View Post
What did you use to rotate your pointer in that addon?
SetTexCoord
  Reply With Quote
11-10-10, 07:05 PM   #18
lilgulps
A Theradrim Guardian
 
lilgulps's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 62
Time to start reading! Thanks for the help guys, hopefully it comes out well
  Reply With Quote
11-10-10, 10:27 PM   #19
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
http://www.wowinterface.com/download...rRingMod3.html

that is Zork's rRingMod3, he has some documentation inside his .lua file, and i forgot the elitestjerks thread that he mentions the tutorial on, but he goes about on how to make a circluar addon, its quite indepth how it works.
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
11-10-10, 10:35 PM   #20
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
I think you should be able to counteract :SetRotation's size change by making your needle texture sqrt(2) times the size of the meter texture behind it.

Would this work?
Code:
local addon = CreateFrame("Frame", "Base2", UIParent)
addon:SetHeight(128)
addon:SetWidth(128)
addon:SetUserPlaced(true)
addon:SetPoint("Center", 100, 0)

local tex = addon:CreateTexture(nil, "ARTWORK")
tex:SetTexture(file)
tex:SetPoint(addon, "CENTER")
local size = sqrt(2) * addon:GetWidth() -- Assuming a square texture
tex:SetSize(size, size)

tex:SetRotation(theta) -- etc
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to rotate a frame?

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