I have been working on a level-of-detail program. Right now I have the rough structure down (splitting of quads without condensing of quads). But the problem is that when you try to split certain quads after they are 1/8 the size of the original they sometimes do not split and the quads that should have been placed in that spot are in another place. I think I just need someone else to look at this code, I believe the problem rests in the index of the quads... Here is the main code:

``````public Quad(Vector3f v1, Vector3f v2, Vector3f v3, Vector3f v4,float size,int x, int y,boolean has,float pI, float pI2){
first = v1;
second = v2;
third = v3;
fourth = v4;
width = size;
index1 = x;
index2 = y;
children = has;
parentIn1 = pI;
parentIn2 = pI2;

}
public static ArrayList<Vector3f> makeVerts(Vector3f p, int x, int y, float increment){
ArrayList<Vector3f> list = new ArrayList<Vector3f>();
Vector3f back_left = new Vector3f ((float)x*increment, 0 , (float)y*increment).add(p);
Vector3f front_right = new Vector3f ((float)(x*increment) + increment, 0, (float)(y*increment)+increment).add(p);
Vector3f front_left = new Vector3f ((float)x*increment, 0 , (float)(y*increment)+increment).add(p);
Vector3f back_right = new Vector3f((float)(x*increment) + increment, 0, (float)y*increment).add(p);

return list;
}

System.out.println(i+ " "+ii);
for(int x = 0; x<2; x++){
for(int y = 0; y<2; y++){
ArrayList<Vector3f> points = makeVerts(parent,x,y,growth);
Vector3f p1 = points.get(0);
Vector3f p2 = points.get(1);
Vector3f p3 = points.get(2);
Vector3f p4 = points.get(3);
}

}
}

}
``````

In addition here is the code that creates the first quad and divides it into four:

``````Vector3f v1 = new Vector3f(0,0,0);
Vector3f v2 = new Vector3f(0,0,32);
Vector3f v3 = new Vector3f(32,0,32);
Vector3f v4 = new Vector3f(32,0,0);
``````

And the code that divides quads depending on one's distance:

``````   for(int i = 0; i<Quad.list.size(); i++){
float width = q.width;
float distance = center.distance(cam.getLocation());
if(width/distance >= .85 && !q.children){
VertexBuffer vb = mesh.getBuffer(Type.Position);
v.clear();
verts = new Vector3f[v.size()];
v.toArray(verts);
vb.updateData(BufferUtils.createFloatBuffer(verts));
``````

parentIn1&2 are the indices of the parent quad. Index1&2 are the indices of the quad. Each time a quad needs to divided the "create" method is run... Just for an idea of what is happening here is a shot of the actual scene. On this run I zoomed in exactly on the center of the quad and this was the result.. Thanks for any and all help, it is much appreciated.

-

## closed as too localized by Byte56♦, Sean Middleditch, bummzack, Tetrad♦Mar 13 '13 at 23:19

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

What values are you using to instantiate your structure, and what do you think you should be seeing instead of what you are seeing? – Seth Battin Mar 13 '13 at 2:24
the initial values for the quad are (0,0,0) (0,0,32) (32,0,32) (32,0,0) and all four of those quads around the center should be subdivided and the ones even closer to the center should be further subdivided. Instead only one of the quads is subdivided and as you can see a quad within that one is also divided pointlessly... – pl12 Mar 13 '13 at 2:43
How about the other values that you pass to the constructor. Would you post the code you use to create it, including your calls to `makeVerts` and `create`? – Seth Battin Mar 13 '13 at 2:52
Just added it...I suppose the error could exist in the Quad.create() method called in the distance-based subdivision algorithm... – pl12 Mar 13 '13 at 3:41
This feels like a "fix my code" type question, which is really too localized for the site. Chances are you'll just have to step through the code with a debugger and see exactly what is going wrong with the data. – Tetrad Mar 13 '13 at 16:42

I fixed the problem... Here is the revised code for the method "create()" if anyone is interested, Thanks for the time:

``````public static void create(Quad quad, int i, int ii){
i*=2;
ii*=2;
for(int x = 0; x<2; x++){
for(int y = 0; y<2; y++){
ArrayList<Vector3f> points = makeVerts(parent,x,y,growth);
Vector3f p1 = points.get(0);
Vector3f p2 = points.get(1);
Vector3f p3 = points.get(2);
Vector3f p4 = points.get(3);