[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Public WebGL] Re: Get Viewport for converting coordinates
hi
2010/8/18 Dan Lecocq <dan.lecocq@kaust.edu.sa>:
> Are you having trouble getting the model to show up with the transform you're expecting?
No, models are rendered as they should.
>
> If the canvas has fixed width and height it shouldn't be a problem, but if the canvas is getting resized to fit the window or something along those lines, this is something to check.
yes, the canvas has fixed width and height (700x530px)
>
> Not sure if yours could be a related problem or not, but it took me a while to figure out so I thought i'd at least mention it. The solution ended up being to change canvas.width to canvas.clientWidth, etc. in my resize function.
>
thank you for answering :)
..i think it must have something to do with the viewport. because when
i remove the part of multiplying the viewport-matrix at least some
values of the calculated object-coordinates are changed. but they are
not correctly converted.
And i dont understand the part with transformations:
For example I klick on a blue point in my webgl scene. the converted
coordinates are 2000,3000. when i do a translate and then again klick
on that blue point the coordinates would not be again 2000,3000, they
will change.
..something is going wrong with all of this :D
> - Dan
>
> Sent from my iPad
>
> On Aug 18, 2010, at 6:34 AM, Mehmet Sirin <m.sirin07@googlemail.com> wrote:
>
>>> First question: Which value is represented in view[0],view[1],.. if my
>>> viewport is 700x500px of size ?
>> Ok, forget this question. Of course it is an array that first
>> represents the origin and then the width and height.
>>
>> But it that case, the maths I posted is correct?
>>
>> Then it is even more strange that it is not working properly..
>>
>>> mvPushMatrix();
>>> ... //stuff like rotate and translate
>>>
>>> //Viewport and Pixel
>>> var v1=(2*(xCoord-0)/700)-1; //xCoord= pixelcoordinate
>>> var v2=(2*(yCoord-0)/530)-1; //yCoord= pixelcoordinate
>>> var v3=2*(-1)-1
>>>
>>> //4D-Vector
>>> var v = Vector.create([v1,v2,v3,1]);
>>> //Projection and mvMatrix
>>> var pM=pMatrix;
>>> var mvM=mvMatrix;
>>> var temp= pM.multiply(mvM);
>>>
>>> var temp_inv=temp.inverse().multiply(v);
>>> ...
>>> The alerted value is the one that i used for the last translation.
>>> Then when changing the position pixel, all that changes is the value
>>> after the comma in the alerted result.
>>
>> The values are changed a lot (numbers in front of comma) only if I
>> interact with the models like rotating or translating them. When
>> klicking somewhere on the canvas after such a transformation the
>> values still won't change correctly.
>>
>> I am confused :)
>>
>> -----------------------------------------------------------
>> You are currently subscribed to public_webgl@khronos.org.
>> To unsubscribe, send an email to majordomo@khronos.org with
>> the following command in the body of your email:
>>
>
-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email: