# Community Forum

## Rotate image overlay

Forum Overview >> Scripting

 Category Scripting Created 24.10.2010 12:27

Andreas Großschedl (Unknown) 24.10.2010 12:27
Hi!

Is it possible to rotate an ImageOverlay?

Thank you
Andi

Friedrich L. (Unknown) 25.10.2010 21:51
Rotate the pic ?

Christian Ammann - GIANTS Software 25.10.2010 22:40
Hi Andreas,

You can set the UV coordinates of the overlay so that its rotated. Sin and Cos are your friends;-)

Cheers

Simon Broggi (Unknown) 26.10.2010 14:44
maybe this code is usefull...

--initial uv coordinates:
--v = horizontal
--u = vertical
local v0=0; local u0=0;--bottom Left
local v1=0; local u1=1;--top left
local v2=1; local u2=0;--bottom right
local v3=1; local u3=1;--top right

--center of rotation (cannot be changed unless considered in the rotate block)
local centerU = 0.5;
local centerV = 0.5;

--center coordinate system around centerX/centerY
local v0c=v0-centerV; local u0c=u0-centerU;--bottom Left
local v1c=v1-centerV; local u1c=u1-centerU;--top left
local v2c=v2-centerV; local u2c=u2-centerU;--bottom right
local v3c=v3-centerV; local u3c=u3-centerU;--top right

--assuming the center of rotation is 0.5 0.5:
local r = math.cos(45*math.pi/180);

--rotate
v0c = r*math.cos(((45+180)*math.pi/180)+angle); u0c = r*math.sin(((45+180)*math.pi/180)+angle);--bottom left
v1c = r*math.cos(((45+90)*math.pi/180)+angle); u1c = r*math.sin(((45+90)*math.pi/180)+angle);--top left
v2c = r*math.cos(((45+270)*math.pi/180)+angle); u2c = r*math.sin(((45+270)*math.pi/180)+angle);--bottom right
v3c = r*math.cos(((45)*math.pi/180)+angle); u3c = r*math.sin(((45)*math.pi/180)+angle);--top right

v0 = v0c+centerV; u0 = u0c+centerU;
v1 = v1c+centerV; u1 = u1c+centerU;
v2 = v2c+centerV; u2 = u2c+centerU;
v3 = v3c+centerV; u3 = u3c+centerU;

setOverlayUVs(overlayId, v0, u0, v1, u1, v2, u2, v3, u3);

Andreas Großschedl (Unknown) 27.10.2010 10:01
I tried you code:

the overlay is still rectangle - it does not rotate, only the image in it. Is this ok? When i rotate the image it will be cut at the edges!

Thank you for help.
Andreas

Milan Lekše (Unknown) 17.03.2011 15:01
Hi great code!! work well but I have one question - problem the East and West are ok but North and South are replaced.

Can you help me what to do?

The code that I use:

local Overlay = createImageOverlay(self.helpOverlay);
local x,y,z = localDirectionToWorld(CurrentVehicle.rootNode, 0, 0, 1);
local length = Utils.vector2Length(x,z);
local dX = x/length;
local dZ = z/length;
local angle = math.deg(math.atan2(dX,dZ)) ;
if angle < 0 then
angle = 360 - (angle * -1);
end;

angle = angle * math.pi/180 ;

--initial uv coordinates:
--v = horizontal
--u = vertical
local v0=0; local u0=0;--bottom Left
local v1=0; local u1=1;--top left
local v2=1; local u2=0;--bottom right
local v3=1; local u3=1;--top right

--center of rotation (cannot be changed unless considered in the rotate block)
local centerU = 0.5;
local centerV = 0.5;

--center coordinate system around centerX/centerY
local v0c=v0-centerV; local u0c=u0-centerU;--bottom Left
local v1c=v1-centerV; local u1c=u1-centerU;--top left
local v2c=v2-centerV; local u2c=u2-centerU;--bottom right
local v3c=v3-centerV; local u3c=u3-centerU;--top right

--assuming the center of rotation is 0.5 0.5:
local r = math.cos(45*math.pi/180);

--rotate
v0c = r*math.cos(((45+180)*math.pi/180)+angle); u0c = r*math.sin(((45+180)*math.pi/180)+angle);--bottom left
v1c = r*math.cos(((45+90)*math.pi/180)+angle); u1c = r*math.sin(((45+90)*math.pi/180)+angle);--top left
v2c = r*math.cos(((45+270)*math.pi/180)+angle); u2c = r*math.sin(((45+270)*math.pi/180)+angle);--bottom right
v3c = r*math.cos(((45)*math.pi/180)+angle); u3c = r*math.sin(((45)*math.pi/180)+angle);--top right

v0 = v0c+centerV; u0 = u0c+centerU;
v1 = v1c+centerV; u1 = u1c+centerU;
v2 = v2c+centerV; u2 = u2c+centerU;
v3 = v3c+centerV; u3 = u3c+centerU;

setOverlayUVs(OverlayID, v0, u0, v1, u1, v2, u2, v3, u3);
renderOverlay(OverlayID, buttonX, buttonZ, 0.051, 0.051);

button x and y are generated by code and position works OK
What am I traying to do is similar like green arrow in FS 11

Milan Lekše (Unknown) 17.03.2011 20:31
I found the solution sorry to border you:

v0c = r*math.cos(((45+180)*math.pi/180)+angle); u0c = r*math.sin(((45+180)*math.pi/180)+angle);--bottom left
v1c = r*math.cos(((45+270)*math.pi/180)+angle); u1c = r*math.sin(((45+270)*math.pi/180)+angle);--bottom right
v2c = r*math.cos(((45+90)*math.pi/180)+angle); u2c = r*math.sin(((45+90)*math.pi/180)+angle);--top left
v3c = r*math.cos(((45)*math.pi/180)+angle); u3c = r*math.sin(((45)*math.pi/180)+angle);--top right

for calculating V1C and U1C and V2C and U2C was replaced ange in degres 207 with 90

Have a nice day MILAN