Newer
Older
CactusServer / src / main / java / cactusServer / models / CollisionManager.java
y-ota on 11 Oct 2018 1 KB 設計ミスはつらいよ
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;
import cactusServer.entities.Player;

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(long interval) {
		for (Instance instance : instances.values()) {
			instance.getUniverse().update(interval);
			result.clear();
			for (Object object : instance.getObjects().values()) {
				for (Player player : Instances.getInstance().getPlayers().values()) {
					// result.add(PhysicsUtility.checkCollision(character.getObject(), "",
					// object.getObject(), ""));
					// System.out.println(result.get(result.size()-1).length);
					// objectmove(instance, object, character);
				}
			}
		}
	}

	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);

	}

}