[javascript-dev] screentoworld misunderstanding
Emmanuel Jourdan
c74-mailinglists at e--j.com
Wed Nov 7 15:07:42 MST 2007
- Previous message: [javascript-dev] screentoworld misunderstanding
- Next message: [javascript-dev] Re: screentoworld misunderstanding
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 7 nov. 07, at 19:18, gusanomaxlist wrote:
> In vertical mode, I have this working perfectly:
> --------------------------------------------
> function ondrag(x,y,....)
> {
> var f,a;
> a=sketch.screentoworld(x,y);
> f=(a[1]+1)*0.5;
> msg_float(f);
> }
> --------------------------------------------
> I thought that replacing a[1] with a[0] would be enough to deal
> with x coordinates, but for example, if my object is 100x10 pixels,
> dragging will work horizontally only within 10 pixels around the
> center (5 left and 5 right) and not on the whole 100...
Your problem is that on the y axis the value are from -1 to 1 (with 0
being the center of the vertical axis). But for the x axis the
location is from -aspect to +aspect (where aspect is the box width/
box height). Have a look to the "jsui_screentoworld-example.pat"
example in the examples/javascript/ui folder.
something like that should work, although I didn't test it:
function ondrag(x,y,....)
{
var width = box.rect[2] - box.rect[0];
var height = box.rect[3] - box.rect[1];
var aspect = width/height;
var a = sketch.screentoworld(x,y);
var f = (a[0] + aspect) * aspect * 0.5;
msg_float(f);
}
HTH,
ej
- Previous message: [javascript-dev] screentoworld misunderstanding
- Next message: [javascript-dev] Re: screentoworld misunderstanding
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
