Incorrect size of images displayed on editor

Report problems here (or use the built-in feedback dialog in the editor)
Post Reply
garfi43
Posts: 6
Joined: Mon Jan 21, 2013 11:00 am

Incorrect size of images displayed on editor

Post by garfi43 »

When dragging and dropping two images (PNG) to the editor, the images are resized/scaled automatically to the same size or a scale completely different. (rube for Mac 10.7.5)
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: Incorrect size of images displayed on editor

Post by iforce2d »

Images will start with a scale of 1, which means that their vertical side is 1 unit high in the physics world - if this is what's happening it's not a bug. See the tutorial video 14 for more info: http://www.youtube.com/watch?v=wwEPKhdzIpk

If something else is happening maybe you could show an example.

If you want to set the scale of images using their pixel dimensions, there needs to be some standard to define how many physics units one pixel should be. You could use a script like this to set image scales:

Code: Select all

float PTM = 20;
image[] imgs = si(); //selected images
for (uint i =0; i < imgs.length; i++)
    imgs[i].setScale( imgs[i].getPixelHeight() / PTM );
This will change the scale of all currently selected images to match a given PTM ratio. The si() function is short for getSelectedImages(), and there is also a getAllImages() or ai() function if you want to do this for every image in the scene.

After using the script panel to check that this does what you want, you can add it to the action menu to be re-used more conveniently, as shown in tutorial video 16: http://www.youtube.com/watch?v=ZVmBrebebEY
I'm hoping to someday add a dialog to the program so that the action menu can be configured without editing the files manually, but for the time being I'm not so sure that many people are even using script at all in these early days :)
headwinds
Posts: 11
Joined: Sat Dec 29, 2012 8:14 pm

Re: Incorrect size of images displayed on editor

Post by headwinds »

nice script! I just tried it and was what I was looking for... I was struggling for a bit while playing with images and got confused by scale until I watched your video. I thought scale was about percentage meaning either 1 or 100% but it means neither - it's 1 unit in the world! :D

I too was surprised at first when I noticed the flip in but realized it's due the inverted cartesian system. Like Flash, the canvas in html5 considers the origin at the top left. This thread on stackover discuss the inverted cartesian coordinate system.

I realized that it's simply best to handle the inversion in Javascript and let RUBE keep it's true cartesian system as it must supply json to many different languages not just javascript. Plus, as you noted, it's only two lines of code ;)
Post Reply