Lua Code:
function RotateRadian(self, radian)
if type(radian) ~= "number" then
error("Usage: Texture:RotateRadian(radian) - 'radian' must be number.", 2)
end
if not self.__OriginTexCoord then
self.__OriginTexCoord = {self:GetTexCoord()}
self.__OriginWidth = self.Width
self.__OriginHeight = self.Height
end
while radian < 0 do
radian = degree + 2 * math.pi
end
radian = radian % (2 * math.pi)
local angle = radian % (math.pi /2)
local left = self.__OriginTexCoord[1]
local top = self.__OriginTexCoord[2]
local right = self.__OriginTexCoord[7]
local bottom = self.__OriginTexCoord[8]
local dy = self.__OriginWidth * math.cos(angle) * math.sin(angle) * (bottom-top) / self.__OriginHeight
local dx = self.__OriginHeight * math.cos(angle) * math.sin(angle) * (right - left) / self.__OriginWidth
local ox = math.cos(angle) * math.cos(angle) * (right-left)
local oy = math.cos(angle) * math.cos(angle) * (bottom-top)
local newWidth = self.__OriginWidth*math.cos(angle) + self.__OriginHeight*math.sin(angle)
local newHeight = self.__OriginWidth*math.sin(angle) + self.__OriginHeight*math.cos(angle)
local ULx -- Upper left corner X position, as a fraction of the image's width from the left (number)
local ULy -- Upper left corner Y position, as a fraction of the image's height from the top (number)
local LLx -- Lower left corner X position, as a fraction of the image's width from the left (number)
local LLy -- Lower left corner Y position, as a fraction of the image's height from the top (number)
local URx -- Upper right corner X position, as a fraction of the image's width from the left (number)
local URy -- Upper right corner Y position, as a fraction of the image's height from the top (number)
local LRx -- Lower right corner X position, as a fraction of the image's width from the left (number)
local LRy -- Lower right corner Y position, as a fraction of the image's height from the top (number)
if radian < math.pi / 2 then
-- 0 ~ 90
ULx = left - dx
ULy = bottom - oy
LLx = right - ox
LLy = bottom + dy
URx = left + ox
URy = top - dy
LRx = right + dx
LRy = top + oy
elseif radian < math.pi then
-- 90 ~ 180
URx = left - dx
URy = bottom - oy
ULx = right - ox
ULy = bottom + dy
LRx = left + ox
LRy = top - dy
LLx = right + dx
LLy = top + oy
newHeight, newWidth = newWidth, newHeight
elseif radian < 3 * math.pi / 2 then
-- 180 ~ 270
LRx = left - dx
LRy = bottom - oy
URx = right - ox
URy = bottom + dy
LLx = left + ox
LLy = top - dy
ULx = right + dx
ULy = top + oy
else
-- 270 ~ 360
LLx = left - dx
LLy = bottom - oy
LRx = right - ox
LRy = bottom + dy
ULx = left + ox
ULy = top - dy
URx = right + dx
URy = top + oy
newHeight, newWidth = newWidth, newHeight
end
self:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
self.Width = newWidth
self.Height = newHeight
end
Well, I made a Rotate method for my Texture class before. It can keep the origin cut(left, right, top, bottom), and then rotate it for any degree, also it would change the Size(if not setallpoints()) base on the radian. I try an OnUpdate animation on a triangle, works fine. You may have a try.