package cactusServer.models; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.ntlab.radishforandroidstudio.framework.model3D.CollisionResult; import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; import org.ntlab.radishforandroidstudio.framework.physics.PhysicsUtility; import cactusServer.entities.Character; import cactusServer.entities.Instance; import cactusServer.entities.Object; public class CollisionManager { private static CollisionManager theInstance; private List<CollisionResult> result; private HashMap<String, Instance> instances; private CollisionManager() { result = new ArrayList<CollisionResult>(); instances = Instances.getInstance().getInstances(); } public static CollisionManager getCollision() { if (theInstance == null) { theInstance = new CollisionManager(); } return theInstance; } public List<CollisionResult> getResult() { return result; } public void collisionRun() { for (Map.Entry<String, Instance> instance : instances.entrySet()) { result.clear(); HashMap<String, Object> objects = instance.getValue().getObjects(); HashMap<String, Character> characters = instance.getValue().getCharacters(); for (Map.Entry<String, Object> object : objects.entrySet()) { for (Map.Entry<String, Character> character : characters.entrySet()) { result.add(PhysicsUtility.checkCollision(character.getValue().getObject(), "", object.getValue().getObject(), "")); objectmove(instance.getValue(), object.getValue(), character.getValue()); } } } } public void objectmove(Instance instance, Object object, Character character) { int size = result.size() - 1; CollisionResult current = result.get(size); Position3D position = object.getPosition(); position.setX(position.getX() + current.length * current.normal.x); position.setY(position.getY() + current.length * current.normal.y); position.setZ(position.getZ() + current.length * current.normal.z); object.setPosition(position); } }