Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I would like to create a 2D right triangle grid for a game I am working on. Currently I am creating creating a 2D square grid, and each square contains 2 triangles.

I am wondering, is there a way to create and manage a right-triangle grid without having to contain 2 triangles in each square?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

At first I thought you wanted to switch to equilateral triangles like below

Courtesy wikipedia.

Then you can index into this grid in the exact same way as a rectangular grid.

The top left triangle will be (0,0), and the one to the right of it will be (1,0) then to the right of that will be (2,0), etc.

The row below is (1, j).


However, I see now that you question is about right triangles.

That is just as easy, because two right triangles form a rectangle. So your coordinates will clearly still be rectangular, the same as above.

If you have a 2D array storing your grid of triangles, you can just index directly into any triangle using a rectangular coordinate system (i.e., pretend that you just have a grid of squares).

Right triangles in a grid.

So you'll have a 2D array that stores one triangle each. array[0,0] stores nothing, to make the coordinate system simpler.

There are multiple ways to index into these triangles, so I've just chosen the coordinate system that I think is easiest.

This corresponds to a rectangular coordinate system that you're used to pretty closely. If it's still not clear, just ask me to elaborate.

share|improve this answer
    
+1 For illustrations. You explained the idea well, but an ellaboration is still welcome :) –  onedayitwillmake Jun 4 '11 at 20:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.