package net.mgsx.game.plugins.box2d.systems;

import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.math.MathUtils;

import net.mgsx.game.core.GamePipeline;
import net.mgsx.game.plugins.box2d.components.Box2DBodyModel;
import net.mgsx.game.plugins.core.components.SlavePhysics;
import net.mgsx.game.plugins.core.components.Transform2DComponent;

public class Box2DSlaveSystem extends IteratingSystem {
	public Box2DSlaveSystem() {
		super(Family.all(Box2DBodyModel.class, Transform2DComponent.class, SlavePhysics.class).get(), GamePipeline.AFTER_LOGIC);
	}

	@Override
	public void processEntity(Entity entity, float deltaTime) {
		Box2DBodyModel physic = entity.getComponent(Box2DBodyModel.class);
		Transform2DComponent t = entity.getComponent(Transform2DComponent.class);
		if(physic.body != null){
			physic.body.setLinearVelocity(t.position.cpy().sub(physic.body.getPosition()).scl(1.f / deltaTime));
			float a1 = t.angle * MathUtils.degreesToRadians;
			float a2 = physic.body.getAngle();
			float delta = a2 - a1; // TODO not good !
			physic.body.setAngularVelocity(delta);
		}
	}
}
@@ -992,21 +992,73 @@
 f / 
-deltaTime));%0A
+30f)); // TODO not good neither ? timestep ?%0A%09%09%09if(t.rotation)%7B%0A%09
 %09%09%09f
@@ -1104,24 +1104,25 @@
 Radians;%0A%09%09%09
+%09
 float a2 = p
@@ -1144,16 +1144,17 @@
 ngle();%0A
+%09
 %09%09%09float
@@ -1189,24 +1189,25 @@
 t good !%0A%09%09%09
+%09
 physic.body.
@@ -1233,16 +1233,21 @@
 delta);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%7D

disable rotation sync if not activated