java - Drawing texture on Polygon Shape -


i drawing polygon shapes , trying draw textures on it.

    polygonshape shape = new polygonshape(); shape.set(new vector2[]{         new vector2(0, 0)         , new vector2(x1 - x2, y1 - y2)         , new vector2(x1 - x2, y1 - y2 - p)         , new vector2(0, 0 - p)});           float[] vertices = new float[]{         0,         0,         (x1 - x2) * constants.ppm ,         (y1 - y2) * constants.ppm ,         (x1 - x2) * constants.ppm,         (y1 - y2 - p) * constants.ppm,         0,         (0 - p) * constants.ppm };          earclippingtriangulator triangulator = new earclippingtriangulator();         shortarray triangleindices = triangulator.computetriangles(vertices);         polygonregion polyreg = new polygonregion(new textureregion(texture), vertices, triangleindices.toarray());         polygonsprite poly = new polygonsprite(polyreg);         poly.setposition(posoffset, tmpbody.getposition().y);        // polysprites.add(poly); 

in draw() method,

poly.draw(polybatch);  

the problem: polygon shape varies in length width constant. trying fill polygonshape texture not able fill/stretch size , shape.

not sure if describing well, here's image detailing trying achieve. enter image description here

in case, 'polygons' still quads. don't need complicate things here.

all there's set rotation , translation transformations sprites and/or container polygon.

read more here: opengl transformation matrices it's not you'll need implement. hope gist.

it can following depending on how implementation of polysprite is:

polygonsprite poly = new polygonsprite(polyreg); poly.setposition(posoffset, tmpbody.getposition().y); // poly.setrotation(slope); polysprites.add(poly); 

Comments