package logic.nodes.lod.blocks;
import gameStates.absGamesStates.AbsIngameState;
import logic.nodes.collision.CollidableNode;
import com.jme.math.Vector3f;
public class Block extends AbstractBlock {
private static final long serialVersionUID = 1L;
private AbstractBlock blockA, blockB;
public Block(Vector3f center, float xExtend, float yExtend, float zExtend, AbsIngameState ingameState) {
super(center, xExtend, yExtend, zExtend, ingameState);
}
public Block(Vector3f center, float size, AbsIngameState ingameState) {
super(center, size, ingameState);
}
public void addBlock(AbstractBlock block) {
assert(intersectsWith(block));
if(blockA == null) blockA = block;
else {
assert(blockB == null);
blockB = block;
}
block.setParentBlock(this);
}
public AbstractBlock getNearestBlock(Vector3f location) {
assert(blockA != null && blockB != null);
float distA = blockA.getCenter().distance(location);
float distB = blockB.getCenter().distance(location);
return (distA < distB ? blockA : blockB);
}
public LeafBlock getLeafOf(CollidableNode node) {
if(!ingameState.isInRootBlock(node)) return ingameState.getOuterLeafBlock();
Vector3f nodeLoc = node.getLocalTranslation();
if(node.getBound() != null) nodeLoc = node.getBound().getCenter();
AbstractBlock nextBlock = getNearestBlock(nodeLoc);
if(nextBlock instanceof LeafBlock) return (LeafBlock)nextBlock;
return ((Block)nextBlock).getLeafOf(node);
}
public AbstractBlock getBlockA() { return blockA; }
public AbstractBlock getBlockB() { return blockB; }
}
|