Texcoordinates problem

http://i.imgur.com/Tt9CK.png


this is the texture:
http://i.imgur.com/tmRhq.png

I have a box which I build by hand, trying to create the textcoordinates for the top face of the box using top1 - top4 coordinates.

I build all faces according to https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

like this:

22 --3
| | Counter-clockwise
| |
0--1 1

and indices like { 2,0,1, 1,3,2 };

for all other faces I use t1 - t4 and I dont see any problem, but for topface I run into problems which you see in the screenshot. Any ideas why this doesn't work?



Vector2f t1 = new Vector2f(0, 0);
Vector2f t2 = new Vector2f(0.5f, 0);
Vector2f t3 = new Vector2f(0, 0.5f);
Vector2f t4 = new Vector2f(0.5f, 0.5f);

Vector2f top1 = new Vector2f(0.5f, 0.5f);
Vector2f top2 = new Vector2f(1.0f, 0.0f);
Vector2f top3 = new Vector2f(0.0f, 1.0f);
Vector2f top4 = new Vector2f(1.0f, 1.0f);

later in the code...

if(faces[topFace] == 1)
{
verticesSize = vertices.size();

vertices.add(pc);
vertices.add(pd);
vertices.add(pg);
vertices.add(ph);

normals.add(normal);
texCoord.add(top1);
texCoord.add(top2);
texCoord.add(top3);
texCoord.add(top4);

indexes.add(verticesSize+2);
indexes.add(verticesSize+0);
indexes.add(verticesSize+1);
indexes.add(verticesSize+1);
indexes.add(verticesSize+3);
indexes.add(verticesSize+2);
}

[java]Vector2f top1 = new Vector2f(0.5f, 0.5f);

Vector2f top2 = new Vector2f(1.0f, 0.0f);

Vector2f top3 = new Vector2f(0.0f, 1.0f);

Vector2f top4 = new Vector2f(1.0f, 1.0f);[/java]



Based on the first texture coordinate, you are getting exactly what I’d expect. What is that you want to happen here?



You have one edge of the triangle that goes from one texture corner to the other, and the other triangle corner in the middle of the texture… which of course that other edge went right through also. So it just gets stretched out from the diagonal to those other edges.



Edit: Can you somehow indicate which portion of the texture you want to be on top of the cube?

I wanted to top right part of the texture from (0.5, 0.5) to (1, 1) asuming that texture coordinates go from bottom left to top right.



after some debugging I had to modify it too look likt this:



top1 = (0.5f, 0.5f)

top2 = (1.0f, 0.5f)

top3 = (0.5f, 1.0f)

top4 = (1.0f, 0.5f)



so now its giving me the correct part of texture top right part. I missunderstud how to go about this.