View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Binary Triangle Trees and Terrain

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1Divega  Members

Posted 17 October 2012 - 08:01 PM

[THIS STUPID EDITOR WILL NOT FORMAT THE TEXT CORRECTLY]

Hey there GameDevs,

I'm having trouble grasping a few concepts about using binary triangle trees for representing terrain data. Lets say I'm working with a 17x17 square grid of vertices and i have a class as follows:

public class Terrain {
private int maxWidth;
private int numVertices;
private float[][] heightmap;
public Terrain(int gridWidth) { // 16 assuming each grid cell's length and width = 1;
this.maxWidth = gridWidth + 1; // 17
this.numVertices = this.maxWidth * this.maxWidth; // 289
System.out.println(this.numVertices);
this.heightmap = new float[this.maxWidth][this.maxWidth]; // 17x17
for(int x = 0; x < this.maxWidth; x++) {
for(int z = 0; z < this.maxWidth; z++) {
this.heightmap[x][z] = 0; // Zero out height data;
}
}
}
}

Bounds of terrain:

The vertices would be contained in a vertex buffer from 0 - 289; Each 1x1 cell contains 2 triangles and total of 4 vertices / 6 indices.

So what I am not grasping is how to represent this data using a BTT. The way I understand a BTT is

BTT {
data
leftchild
rightchild
}

Now I'm assuming the data variable in each tree would be an index buffer of the 3 indices for the triangle. This biggest thing i struggle with is how do I keep track of the left, right, and bottom neighbor of each triangle without being able to pass data by reference. Please let me know if you need anymore information from me, this is all i can think up right now.

Edited by Divega, 17 October 2012 - 09:25 PM.

### #2Ashaman73  Members

Posted 18 October 2012 - 12:12 AM

[THIS STUPID EDITOR WILL NOT FORMAT THE TEXT CORRECTLY]

It formats
the text
the way
the user want
it....


Back to your problem: take a look here.

Ashaman

### #3Divega  Members

Posted 18 October 2012 - 12:38 AM

Thanks for the reply however, I've already read through that link a few times. It does not answer my question

The biggest thing i struggle with is how do I keep track of the left, right, and bottom neighbor of each triangle without being able to pass data by reference.

Nor does it supply the source that it says is included with the article.

### #4MrOMGWTF  Members

Posted 18 October 2012 - 05:33 AM

[THIS STUPID EDITOR WILL NOT FORMAT THE TEXT CORRECTLY]

public class Terrain {
private int maxWidth;
private int numVertices;
private float[][] heightmap;

public Terrain(int gridWidth) { // 16 assuming each grid cell's length and width = 1;
this.maxWidth = gridWidth + 1; // 17
this.numVertices = this.maxWidth * this.maxWidth; // 289
System.out.println(this.numVertices);
this.heightmap = new float[this.maxWidth][this.maxWidth]; // 17x17

for(int x = 0; x < this.maxWidth; x++) {
for(int z = 0; z < this.maxWidth; z++) {
this.heightmap[x][z] = 0; // Zero out height data;
}
}
}
}


It works... lrn2bbcode ;_;

### #5Divega  Members

Posted 18 October 2012 - 08:33 AM

Extremely helpful, high five sir. Please try again.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.