[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] Re: Get Viewport for converting coordinates



Are you having trouble getting the model to show up with the transform you're expecting?  I was having those sorts of problems and thought it was in my model view matrix, but it turns out there was a disconnect about how the viewport was handled by webkit and the size of the canvas.

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.  If you're basing your calculations on widths and heights that you think it should have, and/or canvas.clientWidth, then check with canvas.width is. I found that webkit would only let me display canvas.width x canvas.height pixels in the viewport, not matter what I set the viewport to be. The consequence was that the image looked grainy and translated up and to the right.

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.

- 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: