Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / simulator / interfaces / CameraPositionReceiver.java
package gameEngine.simulator.interfaces;

import gameEngine.entites.Camera;
import models.algebra.Expression;
import models.algebra.Term;
import simulator.Event;
import simulator.SystemState;
import simulator.interfaces.INativeReceiver;

public class CameraPositionReceiver implements INativeReceiver {
	private Camera camera;

	public CameraPositionReceiver(Camera camera) {
		this.camera = camera;
	}

	@Override
	public void onReceiveFromModel(Event event, SystemState nextSystemState) {
		Expression message = event.getMessage();
		if (message instanceof Term) {
			Expression xExp = ((Term) message).getChild(0);
			Expression yExp = ((Term) message).getChild(1);
			Expression zExp = ((Term) message).getChild(2);
			if (xExp instanceof Term) {
				xExp = ((Term) xExp).reduce();
			}
			if (yExp instanceof Term) {
				yExp = ((Term) yExp).reduce();
			}
			if (zExp instanceof Term) {
				zExp = ((Term) zExp).reduce();
			}
			Float x = Float.parseFloat(xExp.toString());
			Float y = Float.parseFloat(yExp.toString());
			Float z = Float.parseFloat(zExp.toString());
			camera.transform.setPosition(x, y, z);
		}
	}

}