Board index FlightGear Development Canvas

Changing setScale origin/center  Topic is solved

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Changing setScale origin/center

Postby Gijs » Thu Aug 29, 2013 9:39 pm

For the 744's EICAS, I'm trying to make a line (or rectangle) grow in one direction.It's the red area in the image below. I thought simply scaling the area in the Y direction, with the objects origin at the bottom line would work, but apparently not.

Code: Select all
eng1n1refLine.setScale(4*getprop("controls/engines/engine/throttle"),1);

setScale() scales from the origin of the canvas instead of the object's center (or origin). This results in a red area moving up/down over the entire canvas. I've tried running .setCenter() on the object, but that has no effect. What did I miss?

Cheers,
Gijs

Image
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9401
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Changing setScale origin/center

Postby TheTom » Fri Aug 30, 2013 9:02 am

I will think about how to best handle a center and different transformations. For now do it just how transformations are normally combined (move to center, apply transformation, move back):
Code: Select all
# initialize
var c = eng1n1refLine.getCenter();
eng1n1refLine.createTransform().setTranslation(-c[0], -c[1]);
var tf_scale = eng1n1refLine.createTransform();
eng1n1refLine.createTransform().setTranslation(c[0], c[1]);

# update
tf_scale.setScale(4*getprop("controls/engines/engine/throttle"), 1);
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am

Re: Changing setScale origin/center

Postby Gijs » Fri Aug 30, 2013 12:16 pm

Your code gives the exact same behaviour :shock:
The blue area is scaled in the image below. From left to right, the throttle property (and thus the scale factor) is increasing from 0 on the most left image. You can see that it scales as if the top of the canvas is the origin of the blue area.

Image

My complete code (the blue area is "path3104"): http://pastebin.com/npz9aE5K

Cheers,
Gijs
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9401
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Changing setScale origin/center  

Postby TheTom » Fri Aug 30, 2013 12:48 pm

Gijs wrote in Fri Aug 30, 2013 12:16 pm:Your code gives the exact same behaviour :shock:

The your object probably has no center offset specified in which case it defaults to [0, 0]. Either call updateCenter() before retrieving the center, calculate it somehow on your own or set it using inkscape (drag around the rotation center using MMB). In the SVG file you can specifiy the offset from the objects origin with center-offset-x/y respectively.
TheTom
 
Posts: 321
Joined: Sun Oct 09, 2011 10:20 am

Re: Changing setScale origin/center

Postby Gijs » Fri Aug 30, 2013 1:07 pm

Cool, updateCenter() did the trick! Thanks!
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9401
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10

Re: Changing setScale origin/center

Postby zakalawe » Fri Aug 30, 2013 1:28 pm

Gijs, I'm looking forward to stealing all of these for the 737NG :)
zakalawe
 
Posts: 1152
Joined: Sat Jul 19, 2008 4:48 pm
Location: Edinburgh, Scotland
Callsign: G-ZKLW
Version: next
OS: Mac

Re: Changing setScale origin/center

Postby Gijs » Fri Aug 30, 2013 1:46 pm

That's ok, if I can steal your CDU for my 744 :-)
Airports: EHAM, EHLE, KSFO
Aircraft: 747-400
User avatar
Gijs
Moderator
 
Posts: 9401
Joined: Tue Jul 03, 2007 2:55 pm
Location: Amsterdam/Delft, the Netherlands
Callsign: PH-GYS
Version: Git
OS: Windows 10


Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests