java - Wrong origin coordinates logic for polygon -
java - Wrong origin coordinates logic for polygon -
what have in test project, seek prepare problem:
2 polygon objects
2 actors, each of actor contain 1 polygon object
1 array actors, run through in render method , utilize of shaperenderer draw polygons
1 orthographiccamera
1 stage
1 screenviewport
the logic next: create polygon 1 , polygon 2 same size , same position @ 0,0 .
than setposition(gdx.graphics.getwidth()/2, gdx.graphics.getwidth()/2). translate 1 polygon 50 pixel on axis x , run setorigin(gdx.graphics.getwidth()/2, gdx.graphics.getwidth()/2). , added inputlistener first polygon, when click on rotateby on sec actor sec polygon. photographic camera has y-up. on rotation sec polygon think origin point top right corner of screen , rotation around it.
here , gif of result: http://i.imgur.com/cdzqtta.gif
and scheme how behave: http://i.imgur.com/dcb0hdx.jpg
and here gif of behave if maximize window: http://i.imgur.com/6zkn33d.gif . here can see after resize, greenish polygon rotation around point before resize top right cornern of screen.
here test project problem https://www.dropbox.com/s/ti2iiwm2cbom62f/polygonrotation.zip?dl=0
could help find out problem?
thank you.
it seems misuse setorigin
method. in code in polygonrotation.java
:
public void create () { float w = gdx.graphics.getwidth(); float h = gdx.graphics.getheight(); //... p1.setvertices(getvertices(0, 0, 20, 5)); p2.setvertices(getvertices(0, 0, 20, 5)); pactor pa1 = new pactor(); pactor pa2 = new pactor(); actors.add(pa1); actors.add(pa2); //... pa1.setposition(w/2, h/2); //... pa2.setposition(pa1.getx(), pa1.gety()); //... pa2.setorigin(pa1.getx(), pa1.gety()); // <-- line //... drawviewportbox(w, h); }
origin not coordinates of polygon's center, rather offset it.
according code both polygons positioned center of screen (w/2
, h/2
).
then set origin of w/2
, h/2
sec polygon sums it's current position , equals w
, h
. in other words origin set right upper corner of screen, case.
java libgdx
Comments
Post a Comment