Fixed QuadTreeImage
This commit is contained in:
@@ -333,12 +333,12 @@ public class LodQuadTree {
|
||||
* @return
|
||||
*/
|
||||
public List<AbstractMap.SimpleEntry<LodQuadTree, Integer>> getLevelToGenerate(int x, int z, byte targetLevel, int maxDistance, int minDistance) {
|
||||
int distance = (int) Math.sqrt(Math.pow(x + lodNodeData.centerX, 2) + Math.pow(z + lodNodeData.centerZ, 2));
|
||||
int distance = (int) Math.sqrt(Math.pow(x - lodNodeData.centerX, 2) + Math.pow(z - lodNodeData.centerZ, 2));
|
||||
List<AbstractMap.SimpleEntry<LodQuadTree, Integer>> nodeList = new ArrayList<>();
|
||||
if (distance > maxDistance || distance < minDistance || targetLevel > lodNodeData.level || lodNodeData.real) {
|
||||
if (distance > maxDistance || distance < minDistance || targetLevel > lodNodeData.level) {
|
||||
return nodeList;
|
||||
}
|
||||
if(isThereAnyChild()) {
|
||||
if(isNodeFull()) {
|
||||
//THIS LEVEL HAS CHILD SO IT'S GENERATED.
|
||||
if (targetLevel != lodNodeData.level) {
|
||||
for (int NS = 0; NS <= 1; NS++) {
|
||||
@@ -353,6 +353,23 @@ public class LodQuadTree {
|
||||
}
|
||||
} else {
|
||||
nodeList.add(new AbstractMap.SimpleEntry<>(this, distance));
|
||||
/*
|
||||
if(isThereAnyChild()){
|
||||
for (int NS = 0; NS <= 1; NS++) {
|
||||
for (int WE = 0; WE <= 1; WE++) {
|
||||
if (children[NS][WE] == null) {
|
||||
setChild(NS,WE);
|
||||
LodQuadTree child = children[NS][WE];
|
||||
distance = (int) Math.sqrt(Math.pow(x - child.lodNodeData.centerX, 2) + Math.pow(z - child.lodNodeData.centerZ, 2));
|
||||
nodeList.add(new AbstractMap.SimpleEntry<>(child, distance));
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
nodeList.add(new AbstractMap.SimpleEntry<>(this, distance));
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
return nodeList;
|
||||
}
|
||||
@@ -400,6 +417,8 @@ public class LodQuadTree {
|
||||
|
||||
public String toString(){
|
||||
String s = lodNodeData.toString();
|
||||
return s;
|
||||
/*
|
||||
if(isThereAnyChild()){
|
||||
for (int NS = 0; NS <= 1; NS++) {
|
||||
for (int WE = 0; WE <= 1; WE++) {
|
||||
@@ -411,5 +430,6 @@ public class LodQuadTree {
|
||||
}
|
||||
}
|
||||
return s;
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -65,8 +65,9 @@ public class QuadTreeImage extends JPanel {
|
||||
|
||||
private static void createAndShowGui( ) {
|
||||
LodQuadTree lodQuadTree = new LodQuadTree(0,0);
|
||||
for(int i = 0; i<9; i++){
|
||||
List<AbstractMap.SimpleEntry<LodQuadTree, Integer>> levelToGenerate= lodQuadTree.getLevelToGenerate(0,0,(byte) (9-i),1000,0);
|
||||
|
||||
for(int i = 0; i<6; i++){
|
||||
List<AbstractMap.SimpleEntry<LodQuadTree, Integer>> levelToGenerate= lodQuadTree.getLevelToGenerate(0,0,(byte) (7),350,0);
|
||||
boolean bw= true;
|
||||
System.out.println(levelToGenerate);
|
||||
for(AbstractMap.SimpleEntry<LodQuadTree, Integer> levelDist : levelToGenerate){
|
||||
@@ -80,25 +81,28 @@ public class QuadTreeImage extends JPanel {
|
||||
bw = true;
|
||||
}
|
||||
|
||||
int posZ = level.getLodNodeData().startX/LodNodeData.BLOCK_WIDTH;
|
||||
int posX = level.getLodNodeData().startZ/LodNodeData.BLOCK_WIDTH;
|
||||
System.out.println(posX + " " + posZ);
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(LodNodeData.BLOCK_LEVEL, posX, posZ, 0, 0, color,true),true);
|
||||
int startX = level.getLodNodeData().startX;
|
||||
int startZ = level.getLodNodeData().startZ;
|
||||
int endX = level.getLodNodeData().endX;
|
||||
int endZ = level.getLodNodeData().endZ;
|
||||
int width = level.getLodNodeData().width;
|
||||
byte otherLevel = LodNodeData.BLOCK_LEVEL;
|
||||
int otherWidth = LodNodeData.BLOCK_WIDTH;
|
||||
int posZ = 2*startX/otherWidth;
|
||||
int posX = 2*startZ/otherWidth;
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(otherLevel, posX, posZ, 0, 0, color,true),true);
|
||||
|
||||
posZ = level.getLodNodeData().endX/LodNodeData.BLOCK_WIDTH;
|
||||
posX = level.getLodNodeData().startZ/LodNodeData.BLOCK_WIDTH;
|
||||
System.out.println(posX + " " + posZ);
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(LodNodeData.BLOCK_LEVEL, posX, posZ, 0, 0, color,true),true);
|
||||
posZ = 2*endX/otherWidth;
|
||||
posX = 2*startZ/otherWidth;
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(otherLevel, posX, posZ, 0, 0, color,true),true);
|
||||
|
||||
posZ = level.getLodNodeData().startX/LodNodeData.BLOCK_WIDTH;
|
||||
posX = level.getLodNodeData().endX/LodNodeData.BLOCK_WIDTH;
|
||||
System.out.println(posX + " " + posZ);
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(LodNodeData.BLOCK_LEVEL, posX, posZ, 0, 0, color,true),true);
|
||||
posZ = 2*startX/otherWidth;
|
||||
posX = 2*endZ/otherWidth;
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(otherLevel, posX, posZ, 0, 0, color,true),true);
|
||||
|
||||
posZ = level.getLodNodeData().endX/LodNodeData.BLOCK_WIDTH;
|
||||
posX = level.getLodNodeData().endZ/LodNodeData.BLOCK_WIDTH;
|
||||
System.out.println(posX + " " + posZ);
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(LodNodeData.BLOCK_LEVEL, posX, posZ, 0, 0, color,true),true);
|
||||
posZ = 2*endX/otherWidth;
|
||||
posX = 2*endZ/otherWidth;
|
||||
lodQuadTree.setNodeAtLowerLevel(new LodNodeData(otherLevel, posX, posZ, 0, 0, color,true),true);
|
||||
}
|
||||
}
|
||||
System.out.println(lodQuadTree.getNodeList(false,false,false));
|
||||
|
||||
Reference in New Issue
Block a user