package de.rico.adventure.entity.hotspot;

import java.util.Comparator;

import de.rico.engine.camera.Camera;
import de.rico.engine.geometry.Point3D;

/**
 * This is a comparator class that can be used to compare
 * the distances to the camera of two interactive hotspots. Because this comparator
 * uses only the center points of the hotspots and not
 * their expansion into the world to perform the
 * sorting, the result are not garanteed to be correct in any case.
 * This is just some kind of rough sorting.
 * @author Frank Bruns
 *
 */
public class HotspotDistanceToCameraComparator implements Comparator<AbstractInteractiveHotspot>
{

	/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(AbstractInteractiveHotspot hot1, AbstractInteractiveHotspot hot2)
	{

		// calculates distance to the camera
		float hot1DistSq = Point3D.getDistanceSquared(
				Camera.getInstance().getPosition(),
				hot1.getPosition());

		float hot2DistSq = Point3D.getDistanceSquared(
				Camera.getInstance().getPosition(),
				hot2.getPosition());

		if(hot1DistSq > hot2DistSq) return 1;
		if(hot1DistSq == hot2DistSq) return 0;
		if(hot1DistSq < hot2DistSq) return -1;
		return 0;
	}

}
