Registriert: Fr Jan 04, 2008 21:29 Beiträge: 419 Wohnort: Lübeck
in the first table with your texcoords, the x-coord is growing from left to right, like the x-coord of your vertices. But if you are looking in both tables on your y-coords, you can see, that your y-coord in texture space is gowing from bottom to top, while the y-coord in vertex-space grows from top to bottom. As a result from this, your "range" should be negative for the y-component. Every logic thinking guy thinks it must be absolute, because it's a distance, but the truth is, it's a direction with 1-dimension, so the sign is important for calculus.
Another note: ( range = (lowest - highest) * -1 ) == ( range = (highest - lowest) )
to calc your example:
left = 30
top = 30
right = 60
bottom = 60 <- thats the point: your bottom is bigger than your top, so it's reversed
range x = right - left = 60 - 30 = 30
range y = top - bottom = 30 - 60 = -30
offset x = 0 - left = 0 - 30 = -30
offset y = 0 - bottom = 0 - 60 = -60
for left,top:
s = (left + offset x) / range x = (30 + -30) / 30 = 0
t = (top + offset y) / range y = (30 + -30) / -30 = -0
for right,top
s = (right + offset x) / range x = (60 + -30) / 30 = 1
t = (top + offset y) / range y = (30 + -30) / -30 = -0
for right,bottom
s = (right + offset x) / range x = (60 + -30) / 30 = 1
t = (bottom + offset y) / range y = (60 + -30) / -30 = -1
for left,bottom
s = (left + offset x) / range x = (30 + -30) / 30 = 0
t = (bottom + offset y) / range y = (60 + -30) / -30 = -1
Now the values are the same, but the signs are different. While -0 == 0 the -1 != 1, that means we changed direction on the texture. If you want you can shift the t-coords, by adding 1, back to the positiv range. The graphical-result should be the same.
Registriert: Di Jul 01, 2003 18:59 Beiträge: 887 Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Thanks you are right. But i am back to my original calculations due to the svg coordinate system. I had a small typo there that did not end up in explanation here.
@SellMan Could you make a wiki entrance on calculation of texture coords?
Now i am on to the next challenge(s):
-Rotate the texture around the center of the polygon (almost done)
Code:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5,0.5,0.0); //no need to know the size of the texture
-Keep the texture at its original size. It now stretches, and that is what i told it to do. But as i am working in 2D i would like to keep the texture at its original size.
So if the texture width is 128 and the rectangle width is 200 the texture should draw up to 128 and repeat after that, if the rectangle width is 50 the texture should draw up to 50.
Now here i am uncertain how to solve it. Should i take the texture size into account when calculating the texture coords? Or is there an easier way?
[EDIT]
Solved keeping the texture size at its original size by setting the range to be the texture width and height.
[/EDIT]
Registriert: Di Jul 01, 2003 18:59 Beiträge: 887 Wohnort: (The Netherlands)
Programmiersprache: fpc/delphi/java/c#
Now that i look at your calculations again you get the same outcome as me.
E.g.
for the top left point 30,30 you also get 0,0 and that is incorrect. It should become 0,1 . So somehow the outcome needs to be mirrored over the y axis?
Registriert: Fr Jan 04, 2008 21:29 Beiträge: 419 Wohnort: Lübeck
look closely on my last scentence. the t-coord of the texture must be shifted. to do so you have to add 1 to the t-coord, the result is excactly your expectet values.
After shifting the values of my calculation it looks like this:
for left,top (30,30 => 0,1)
s = 0
t = -0 + 1 = 1
for right,top (60,30 => 1,1)
s = 1
t = -0 + 1 = 1
for right,bottom (60,60 => 1,0)
s = 1
t = -1 + 1 = 0
for left,bottom (30,60 => 0,0)
s = 0
t = -1 + 1 = 0
Mitglieder in diesem Forum: 0 Mitglieder und 2 Gäste
Du darfst keine neuen Themen in diesem Forum erstellen. Du darfst keine Antworten zu Themen in diesem Forum erstellen. Du darfst deine Beiträge in diesem Forum nicht ändern. Du darfst deine Beiträge in diesem Forum nicht löschen. Du darfst keine Dateianhänge in diesem Forum erstellen.