I managed to modify the function of darkfei in order to apply the rotation around a given point:
Code: Select all
local function rotateTexMesh (mesh, s, n, angle, ox, oy)
ox, oy = ox or 0, oy or 0
local _cos = math.cos(angle)
local _sin = math.sin(angle)
local x1, y1 = 0, 0
local x2, y2 = s, 0
local x3, y3 = 0, s
local x4, y4 = s, s
local u1 = (x1 - ox)*_cos + (y1 - oy)*_sin + ox
local v1 = (x1 - ox)*_sin - (y1 - oy)*_cos + oy
local u2 = (x2 - ox)*_cos + (y2 - oy)*_sin + ox
local v2 = (x2 - ox)*_sin - (y2 - oy)*_cos + oy
local u3 = (x3 - ox)*_cos + (y3 - oy)*_sin + ox
local v3 = (x3 - ox)*_sin - (y3 - oy)*_cos + oy
local u4 = (x4 - ox)*_cos + (y4 - oy)*_sin + ox
local v4 = (x4 - ox)*_sin - (y4 - oy)*_cos + oy
local tex_size = s/n
mesh:setVertex(1, x1, y1, u1/tex_size, v1/tex_size)
mesh:setVertex(2, x2, y2, u2/tex_size, v2/tex_size)
mesh:setVertex(3, x3, y3, u3/tex_size, v3/tex_size)
mesh:setVertex(4, x4, y4, u4/tex_size, v4/tex_size)
end
We can certainly optimize it mathematically but we can now define the origin of rotation, here are examples:
(0,0);
(ox,oy):
Edit: Looking back on it by readapting my first solution, we could have achieved the same thing, to see what is the most efficient, personally I will bet on the meshes although it gives the impression that there are more calculations to do in this case, if someone is brave enough