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

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);
			Float x = Float.parseFloat(xExp.toString());
			Float y = Float.parseFloat(yExp.toString());
			Float z = Float.parseFloat(zExp.toString());
			camera.transform.setPosition(x, y, z);
		}
	}

}