Forum

> > CS2D > Scripts > Rotate and scale image relative in top-left corner
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Rotate and scale image relative in top-left corner

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Rotate and scale image relative in top-left corner

MikuAuahDark
User Off Offline

Zitieren
CS2D does image positioning relative to image center position. Assume that I know the image width and height as
iw
and
ih
, the image rotation as
angle
radians, and the image scale X and Y as
sx
and
sy
respectively, what coordinates do I need to pass to cs2d lua cmd imagepos so that it does rotate and scale relative to top-left corner of the image?

EDIT: To make it clear.
1× editiert, zuletzt 29.05.17 15:34:52

alt Re: Rotate and scale image relative in top-left corner

Gaios
Reviewer Off Offline

Zitieren
You want to use the rotation too, so it's complicated.

IMG:https://i.stack.imgur.com/7hczA.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
function getSize(width, height, rot)
	rot = math.pi * rot / 180

	local NWL = width * math.cos(rot)
	local NHL = width * math.sin(rot)

	local NHU = height * math.cos(rot)
	local NWR = height * math.sin(rot)

	return math.floor(NWL + NWR), math.floor(NHU + NHL)
end

print(getSize(200, 80, 30))
3× editiert, zuletzt 29.05.17 15:19:31

alt Re: Rotate and scale image relative in top-left corner

Gaios
Reviewer Off Offline

Zitieren
Credits: user EnderCrypt's library.

x, y - top-left image pos
power - rectangle diagonal

1
2
3
4
5
6
7
8
9
function pos_trigger(x, y, rot, power)
    rot = (rot < -90) and rot + 360 or rot
   
    local angle = math.rad(math.abs(rot + 90)) - math.pi
    local new_x = math.floor((x + math.cos(angle) * power))
    local new_y = math.floor((y + math.sin(angle) * power))
   
    return new_x, new_y
end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht