Suppose I have a Texture and I want to split it in half on a line rotated with a given angle.
In result I expect to get two Texture objects with the corresponding halfs of the original texture. Would be very nice if it could be done with some kind of transformation/masking so that I wouldn't have to store copies of two new textures at runtime.
Is this even possible?
I tried to work around Gdx.gl.glSsisors() but couldn't make it work as it requires screen coords to be passed as parameters.
Also I tried to go with Pixmap but couldn't find anything that would indicate it's even possible.
This can be achieved by manually calculating two skewed quads and render those using a SpriteBatch.
Cutting a sprite along angle angle we get a directional vector representing the cut by
public void cut(float angle) {
Vector2 d = (new Vector2(1.0f, 0.0f)).rotate(angle);
if we also define the four corners for the UV Mapping of the Texture, along with the center and one vector la going d away from the center and lb going -d
Vector2 c = new Vector2(0.5f, 0.5f);
Vector2 la = (new Vector2(d)).scl( 1.0f).add(c);
Vector2 lb = (new Vector2(d)).scl(-1.0f).add(c);
Vector2 tl = new Vector2(0, 1);
Vector2 tr = new Vector2(1, 1);
Vector2 bl = new Vector2(0, 0);
Vector2 br = new Vector2(1, 0);
we can then calculate the intersection of the cut
Vector2 i1 = new Vector2();
Vector2 i2 = new Vector2();
if (Intersector.intersectSegments(c, la, tl, tr, i1) || Intersector.intersectSegments(c, lb, tl, tr, i1))
i2.set(1.0f - i1.x, 1.0f - i1.y);
else {
if (Intersector.intersectSegments(c, la, tl, bl, i1) || Intersector.intersectSegments(c, lb, tl, bl, i1))
i2.set(1.0f - i1.x, 1.0f - i1.y);
}
At this point we know that one half of the cut will consist of vertices i1, i2 and two of tl, tr, bl and br, so if we sort them by angle away from the cut and then take the first 4 from i1 we get the vertices required to build the skewed quad:
Vector2[] vertexList = new Vector2[] {
tl, tr, bl, br, i1, i2
};
Array<VertexAngle> vas = new Array<>();
for (Vector2 v : vertexList) {
Vector2 vd = (new Vector2(v)).sub(c);
float a = d.angle(vd);
VertexAngle va = new VertexAngle();
va.v = v;
va.a = a;
vas.add(va);
}
vas.sort(new Comparator<VertexAngle>() {
#Override
public int compare(VertexAngle a, VertexAngle b) {
return Float.compare(a.a, b.a);
}
});
Array<Vector2> nv = new Array<>();
for (VertexAngle va : vas)
nv.add(va.v);
int index = nv.indexOf(i1, true);
The a float array containing the vertex data for the draw call can be constructed and rendered with a call to draw on SpriteBatch.
For example:
Full source code for the above example is:
package com.bornander.sandbox;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import java.util.Comparator;
public class SandboxGame extends ApplicationAdapter {
OrthographicCamera camera;
SpriteBatch batch;
Texture texture;
CutTexture cutTexture;
public static class CutTexture
{
public static class VertexAngle {
public Vector2 v;
public float a;
}
public static class CutHalf {
public float[] vertices = new float[4 * 5];
public void translate(float x, float y) {
for(int i = 0; i < vertices.length; i += 5) {
vertices[i + 0] += x;
vertices[i + 1] += y;
}
}
}
public Vector2 position = new Vector2();
public Vector2 driftDirection = new Vector2();
public float drift = 0.0f;
public Texture source;
public CutHalf halfA = new CutHalf();
public CutHalf halfB = new CutHalf();
public void cut(float angle) {
Vector2 d = (new Vector2(1.0f, 0.0f)).rotate(angle);
Vector2 c = new Vector2(0.5f, 0.5f);
driftDirection.set(d).rotate(90.0f);
Vector2 la = (new Vector2(d)).scl( 1.0f).add(c);
Vector2 lb = (new Vector2(d)).scl(-1.0f).add(c);
Vector2 tl = new Vector2(0, 1);
Vector2 tr = new Vector2(1, 1);
Vector2 bl = new Vector2(0, 0);
Vector2 br = new Vector2(1, 0);
Vector2 i1 = new Vector2();
Vector2 i2 = new Vector2();
if (Intersector.intersectSegments(c, la, tl, tr, i1) || Intersector.intersectSegments(c, lb, tl, tr, i1))
i2.set(1.0f - i1.x, 1.0f - i1.y);
else {
if (Intersector.intersectSegments(c, la, tl, bl, i1) || Intersector.intersectSegments(c, lb, tl, bl, i1))
i2.set(1.0f - i1.x, 1.0f - i1.y);
}
Vector2[] vertexList = new Vector2[] {
tl, tr, bl, br, i1, i2
};
Array<VertexAngle> vas = new Array<>();
for (Vector2 v : vertexList) {
Vector2 vd = (new Vector2(v)).sub(c);
float a = d.angle(vd);
VertexAngle va = new VertexAngle();
va.v = v;
va.a = a;
vas.add(va);
}
vas.sort(new Comparator<VertexAngle>() {
#Override
public int compare(VertexAngle a, VertexAngle b) {
return Float.compare(a.a, b.a);
}
});
Array<Vector2> nv = new Array<>();
for (VertexAngle va : vas)
nv.add(va.v);
int index = nv.indexOf(i1, true);
int idx = 0;
int lastIndex = 0;
for(int j = 0; j < 4; ++j) {
lastIndex = (index + j) % nv.size;
Vector2 vertex = nv.get(lastIndex);
float width = source.getWidth();
float height = source.getWidth();
float fx2 = position.x + width * vertex.x - width / 2.0f;
float fy2 = position.y + height * vertex.y - height / 2.0f;
halfA.vertices[idx++] = fx2;
halfA.vertices[idx++] = fy2;
halfA.vertices[idx++] = Color.WHITE_FLOAT_BITS;
halfA.vertices[idx++] = vertex.x;
halfA.vertices[idx++] = 1.0f - vertex.y;
}
idx = 0;
for(int j = 0; j < 4; ++j) {
Vector2 vertex = nv.get((lastIndex + j) % nv.size);
float width = source.getWidth();
float height = source.getWidth();
float fx2 = position.x + width * vertex.x - width / 2.0f;
float fy2 = position.y + height * vertex.y - height / 2.0f;
halfB.vertices[idx++] = fx2;
halfB.vertices[idx++] = fy2;
halfB.vertices[idx++] = Color.WHITE_FLOAT_BITS;
halfB.vertices[idx++] = vertex.x;
halfB.vertices[idx++] = 1.0f - vertex.y;
}
}
public void render(SpriteBatch batch) {
float dx = driftDirection.x * drift;
float dy = driftDirection.y * drift;
halfA.translate(dx, dy);
halfB.translate(-dx, -dy);
batch.draw(source, halfA.vertices, 0, 20);
batch.draw(source, halfB.vertices, 0, 20);
halfA.translate(-dx, -dy);
halfB.translate(dx, dy);
}
}
#Override
public void create () {
float aspectRatio = (float)Gdx.graphics.getHeight()/(float)Gdx.graphics.getWidth();
camera = new OrthographicCamera(800, 800 * aspectRatio);
camera.position.set(camera.viewportWidth / 2.0f, camera.viewportHeight / 2.0f, 0.0f);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("badlogic.jpg"));
Gdx.gl.glCullFace(0);
cutTexture = new CutTexture();
cutTexture.position.set(camera.viewportWidth / 2.0f, camera.viewportHeight / 2.0f);
cutTexture.source = texture;
cutTexture.cut(0);
}
float[] cutAngles = new float[] { 0.0f, -22.5f, -45.0f, -12.0f, -75.0f, -90.0f};
int ai = 0;
#Override
public void render () {
if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE))
{
cutTexture.drift = 0.0f;
cutTexture.cut(cutAngles[(ai++) % cutAngles.length]);
}
cutTexture.drift -= 64.0f * Gdx.graphics.getDeltaTime();
Gdx.gl.glClearColor(0.6f, 0.6f, 1.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.gl.glCullFace(GL20.GL_NONE);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
cutTexture.render(batch);
batch.end();
}
}
Related
I am new to libgdx and trying to move a circle vy draging it. But its not working properly.
class deceleration is as follows -
public class gScreen1 extends ScreenAdapter
implements GestureDetector.GestureListener {
private static final float WORLD_WIDTH = 640;
private static final float WORLD_HEIGHT = 480;
...
#Override
public void show() {
super.show();
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(WORLD_WIDTH / 2, WORLD_HEIGHT / 2, 0);
camera.update();
viewport = new FitViewport(WORLD_WIDTH, WORLD_HEIGHT, camera);
shapeRenderer = new ShapeRenderer();
batch = new SpriteBatch();
}
private void drawGrid() {
Gdx.gl.glLineWidth(2);
shapeRenderer.setProjectionMatrix(camera.projection);
shapeRenderer.setTransformMatrix(camera.view);
shapeRenderer.setColor(Color.YELLOW);
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
size = points.length;
for (int i = 0; i < size; i++) {
shapeRenderer.circle(pointsr[i].x , pointsr[i].y ,10);
}
shapeRenderer.end();
}
#Override
public void render(float delta) {
super.render(delta);
clearScreen();
drawGrid();
}
#Override
public boolean pan(float x1, float y1, float deltaX, float deltaY) {
Vector3 tmpCoords = new Vector3(x1,y1, 0);
camera.unproject(tmpCoords);
int x = (int)tmpCoords.x;
int y = (int)tmpCoords.y;
for( i = 0; i < size ; i++) {
int x2 = pointsr[i].x;
int y2 = pointsr[i].y;
if( ((x2 -x)*(x2 -x) + (y2 -y)*(y2 -y) ) < 400 )
break;
}
if( i < size ) {
pointsr[i].x += deltaX;
pointsr[i].y += deltaY;
}
}
Circles are not following movement of finger, some time they move a little bit but in opposite y direction of touch movement.
I am trying to make a simple example using the friction joints of box2d. I have created a circle that can be controlled with the mouse or arrow keys. There is also a box which is meant to be pushed with the circle. The problem is that when I push the box it keeps moving forever. I have added an auxiliary static box so I can join both boxes with a friction joint to simulate top-down friction. But it doesn't work. Here is the code.
public class MyGdxGame extends ApplicationAdapter {
Camera camera;
int windowWidth, windowHeight;
World physicsWorld;
Box2DDebugRenderer debugRenderer;
Body frictionerBox;
Body boxBody;
Body circleBody;
#Override
public void create () {
camera = new OrthographicCamera(2, 2);
Box2D.init();
physicsWorld = new World(new Vector2(0, 0), true);
debugRenderer = new Box2DDebugRenderer();
// frictioner box
BodyDef bDef = new BodyDef();
bDef.type = BodyDef.BodyType.StaticBody;
bDef.position.set(0, 0);
frictionerBox = physicsWorld.createBody(bDef);
PolygonShape fShape = new PolygonShape();
fShape.setAsBox(10, 10);
FixtureDef fixDef = new FixtureDef();
fixDef.shape = fShape;
fixDef.density = 1.f;
fixDef.friction = 1.f;
//Fixture fix =
frictionerBox.createFixture(fixDef);
// box
bDef = new BodyDef();
bDef.type = BodyDef.BodyType.DynamicBody;
bDef.position.set(0, 50);
boxBody = physicsWorld.createBody(bDef);
PolygonShape bShape = new PolygonShape();
bShape.setAsBox(25, 25);
fixDef = new FixtureDef();
fixDef.shape = bShape;
fixDef.density = 1.f;
fixDef.friction = 1.f;
boxBody.createFixture(fixDef);
// circle
BodyDef cDef = new BodyDef();
cDef.type = BodyDef.BodyType.DynamicBody;
cDef.position.set(20, 20);
circleBody = physicsWorld.createBody(cDef);
CircleShape cShape = new CircleShape();
cShape.setRadius(12);
fixDef = new FixtureDef();
fixDef.shape = cShape;
fixDef.density = 1.f;
circleBody.createFixture(fixDef);
FrictionJointDef frictionJointDef = new FrictionJointDef();
frictionJointDef.maxForce = 10;
frictionJointDef.maxTorque = 10;
frictionJointDef.initialize(frictionerBox, boxBody, new Vector2(0, 0));
physicsWorld.createJoint(frictionJointDef);
bShape.dispose();
cShape.dispose();
fShape.dispose();
}
#Override
public void render () {
handleInput();
physicsWorld.step(Gdx.graphics.getDeltaTime(), 6, 2);
Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
debugRenderer.render(physicsWorld, camera.combined);
}
#Override
public void resize(int width, int height)
{
camera.viewportWidth = width;
camera.viewportHeight = height;
camera.update();
windowWidth = width;
windowHeight = height;
System.out.println("resized");
}
private void handleInput()
{
final float ARROW_SPEED = 60.0f;
final float MAX_SPEED = 200.f;
final float MIN_SPEED = 20.f;
float vx, vy;
if(Gdx.input.isTouched() || Gdx.input.isButtonPressed(Input.Buttons.LEFT))
{
int tx = (Gdx.input.getX() - windowWidth/2);
int ty = -Gdx.input.getY() + windowHeight/2;
float cx = camera.position.x;
float cy = camera.position.y;
float px = circleBody.getPosition().x;
float py = circleBody.getPosition().y;
px = px - cx;
py = py - cy;
vx = tx - px;
vy = ty - py;
float speed = (float) Math.sqrt(vx*vx + vy*vy);
if( speed > MAX_SPEED )
{
vx = (vx/speed) * MAX_SPEED;
vy = (vy/speed) * MAX_SPEED;
}
if( speed > 0 && speed < MIN_SPEED )
{
vx = (vx/speed) * MIN_SPEED;
vy = (vy/speed) * MIN_SPEED;
}
}
else
{
vx = vy = 0;
if(Gdx.input.isKeyPressed(Input.Keys.W))
{
vy += 1;
}
if(Gdx.input.isKeyPressed(Input.Keys.S))
{
vy -= 1;
}
if(Gdx.input.isKeyPressed(Input.Keys.A))
{
vx -= 1;
}
if(Gdx.input.isKeyPressed(Input.Keys.D))
{
vx += 1;
}
float speed = (float) Math.sqrt(vx*vx + vy*vy);
if(speed > 0.f)
{
vx = (vx/speed) * ARROW_SPEED;
vy = (vy/speed) * ARROW_SPEED;
}
}
circleBody.setLinearVelocity(vx, vy);
}
}
What am I doing wrong?
I figured it out. It seems that for the friction to be noticeable you have to set very high values to maxForce and maxTorque.
frictionJointDef.maxForce = 1000000;
frictionJointDef.maxTorque = 10000000;
I am building a 3D game in LibGDX, I have used the following code to work out if I touch a object, but how do I find out at what point it collides. I am not using Bullet as I want to make a HTML5 port
public int getObject (int screenX, int screenY) {
int result = -1;
float distance = -1;
Ray ray = camera.getPickRay(screenX, screenY);
Vector3 pos = new Vector3(camera.position);
for (int i = 0; i < boxInstance.size; i++) {
GameObject instance = boxInstance.get(i);
instance.transform.getTranslation(pos);
float dist2 = ray.origin.dst2(pos);
if (distance >= 0f && dist2 > distance) continue;
if (Intersector.intersectRayBoundsFast(ray, pos, instance.dimensions)) {
result = i;
distance = dist2;
Vector3 v = new Vector3();
if (Intersector.intersectRayBounds(ray, instance.bounds, v))
{
boxInstance.get(result).materials.get(0).set(ColorAttribute.createDiffuse(Color.RED));
}
}
}
if (result > -1)
{
//boxInstance.removeIndex(result);
}
return 1;
};
The reason I need this is if I touch a large plane, I want to be able to plane a object where I touch.
Update
I found intersectRayBounds which should do what I want but it never fires
Here is my GameObject class. Maybe my BoundingBox is wrong?
public class GameObject extends ModelInstance {
public final Vector3 center = new Vector3();
public final Vector3 dimensions = new Vector3();
public static BoundingBox bounds = new BoundingBox();
public GameObject (Model model, float x, float y, float z) {
super(model, x,y,z);
calculateBoundingBox(bounds);
bounds.getCenter(center);
bounds.getDimensions(dimensions);
}
}
I am not sure why this is the fix but it appears you have to compute the Bounding box everytime. See code below.
public int getObject (int screenX, int screenY) {
int result = -1;
float distance = -1;
Ray ray = camera.getPickRay(screenX, screenY);
Vector3 pos = new Vector3(camera.position);
for (int i = 0; i < boxInstance.size; i++) {
GameObject instance = boxInstance.get(i);
instance.transform.getTranslation(pos);
instance.updateBox();
float dist2 = ray.origin.dst2(pos);
if (distance >= 0f && dist2 > distance) continue;
Vector3 v = new Vector3();
if (Intersector.intersectRayBounds(ray, instance.bounds, v))
{
result = i;
distance = dist2;
Gdx.app.log("MyTag 2", "x " + v.x + " z " + v.z);
}
}
if (result > -1)
{
boxInstance.get(result).materials.get(0).set(ColorAttribute.createDiffuse(Color.RED));
}
return 1;
};
public class GameObject extends ModelInstance {
public final Vector3 center = new Vector3();
public final Vector3 dimensions = new Vector3();
public static BoundingBox bounds = new BoundingBox();
private float x,y,z;
public GameObject (Model model, float x, float y, float z) {
super(model, x, y, z);
this.x = x;
this.y = y;
this.z = z;
updateBox();
}
public void updateBox()
{
calculateBoundingBox(bounds);
bounds.getCenter(center);
bounds.getDimensions(dimensions);
bounds.set(bounds.min.add(x,y,z), bounds.max.add(x,y,z));
Gdx.app.log("MyTag 2", "x " + bounds.min + " z " + bounds.max );
}
}
Im trying to create a circle in LWJGL , using VBO's and VAO , and move it using an offset , but it seems one vertex is stuck in the center of the screen . I can't figure out how to move it to the new location . Any help is appreciated , thanks !
P.S : I have already tried debugging the program , but I can't locate the faulty vertex in my array
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.*;
public class Test {
// Setup variables
private int WIDTH = 800;
private int HEIGHT = 600;
private String title = "Circle";
// Quad variables
private int vbo = 0; // Vertex Buffer Object
private int vao = 0; // Vertex Array Object
int SUBDIVISIONS = 100;
float[] vertex = new float[(SUBDIVISIONS + 1) * 4];
public Test() {
// Initialize
setupOpenGL();
setupQuad();
while (!Display.isCloseRequested()) {
loop();
Display.update();
Display.sync(60);
}
Display.destroy();
}
public void setupOpenGL() {
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.setTitle(title);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(-1); // If error , exit program
}
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
public void setupQuad() {
float r = 0.2f;
float x;
float y;
float offSetX = 0.3f;
float offSetY = 0.3f;
vertex[0] = (float) Math.sin(Math.PI*2*0/SUBDIVISIONS) * r + offSetX;
vertex[1] = (float) Math.cos(Math.PI*2*1/SUBDIVISIONS) * r + offSetY;
for (int i = 2; i < 360; i = i + 2) {
double angle = Math.PI * 2 * i / SUBDIVISIONS;
x = (float) Math.cos(angle) * r;
vertex[i] = x + offSetX;
}
for (int i = 3; i < 360; i = i + 2) {
double angle = Math.PI * 2 * i / SUBDIVISIONS;
y = (float) Math.sin(angle) * r;
vertex[i] = y + offSetY;
}
FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(vertex.length);
vertexBuffer.put(vertex);
vertexBuffer.flip();
vao = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vao);
vbo = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER,vertexBuffer,GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 2, GL11.GL_FLOAT, false, 0, 0);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL30.glBindVertexArray(0);
}
public void loop() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
GL30.glBindVertexArray(vao);
GL20.glEnableVertexAttribArray(0);
// Draw the vertices
GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, 0, vertex.length / 2);
// Put everything back to default (deselect)
GL20.glDisableVertexAttribArray(0);
GL30.glBindVertexArray(0);
}
public static void main(String[] args) {
new Test();
}
}
"I think I've found the problem . I was setting the positions of only 359 vertices out of 404 vertices (nr of subdivisions + 1 times 4) . It seems the rest of the vertices were stuck at 0,0 on the screen . Allowing both FOR statements to cycle up to 404 seems to solve the problem"
I'm new in LibGDX.
I created group with actors in show method and add listener (where i calculate rotation matrix) and want to rotate all actors from group with batch.setTransformMatrix(matrixResult); but nothing happens. How can I force to rotate all actors of group?
#Override
public void show() {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0f, 0f, - 120);
camera.lookAt(0,0,0);
camera.near = 0.1f;
camera.far = 300f;
camera.update();
stage = new Stage();
shader = new ShaderProgram(vertexShader, fragmentShader);
myBatch = new SpriteBatch();
shapeRenderer = new ShapeRenderer();
sphere = BuildSphere(5, 100);
group = new Group(){
#Override
public void draw(Batch batch, float parentAlpha) {
batch.setTransformMatrix(matrixResult);
super.draw(batch, parentAlpha);
}
};
group.setTouchable(Touchable.enabled);
group.addListener(new InputListener(){
#Override
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button) {
Gdx.app.log("MOUSE_X_BEG", Float.toString(x));
Gdx.app.log("MOUSE_Y_BEG", Float.toString(y));
begX = x;
begY = y;
return true;
}
#Override
public void touchDragged(InputEvent event, float x, float y,
int pointer) {
endX = x;
endY = y;
//isRotate = true;
float translationX = endX-begX;
float translationY = begY-endY;
float length = (float)Math.sqrt(Math.pow(translationX,2) + Math.pow(translationY,2));
Vector3 axis = new Vector3(0, 0, 0);
if(length>0){
if(begX-endX == 0){
axis.x = 1;
}else{
float angle = (float) (Math.atan(translationY/translationX) + Math.PI/2.0*(translationX <0 ? -1 : 1));
axis.z = 1;
axis.x = (float) Math.cos(angle);
axis.y = (float) Math.sin(angle);
}
}
quaternion = new Quaternion(axis, 0.02f*length);
Matrix4 rotation = new Matrix4(quaternion);
matrixResult = rotation.mul(matrixRotationOld);
matrixRotationOld = matrixResult;
}
});
//group.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
for (CenterCoordinate cenCoordinate : sphere.getPolygonCenterCoordinates()) {
Vector3 vector = cenCoordinate.getCartesianCenter();
Polygon polygon = new Polygon(1, cenCoordinate.getType().getCode(), cenCoordinate.getRadius(), cenCoordinate.getPsi(),
cenCoordinate.getKsi(), vector, cenCoordinate.getRotation());
group.addActor(polygon);
}
stage.addActor(group);
Gdx.input.setInputProcessor(stage);
}
Polygon extends Actor draw method :
#Override
public void draw(Batch batch, float parentAlpha) {
translation.setToTranslation(vertex.x, vertex.y, vertex.z);
matrix.mul(translation);
shader.begin();
shader.setUniformMatrix("u_worldView", matrix);
mesh.render(shader, GL20.GL_LINE_LOOP, 1, mesh.getNumVertices()-1);
shader.end();
matrix.idt();
}
Rotating the batch will not rotate the group. If you want to rotate everything i would suggest to rotate the camera of the Stage and set the Stages SpriteBatchs ProjectionMatrix to cam.combined. But to rotate only the Group use the rotateBy(degrees) or setRotation(degrees) method.
Rotating the SpriteBatch or the camera is actually only a change of the view, but rotating the Actor (in your case the Group) changes the logic of them.
In the draw() method you then will need to take care about this rotation and then you will have the result you want.