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 am trying to generate a grid of cubes in 3D space and It aint workin...

All im doing is for looping YXZ (in that order) (nested for loops) then im doing cubes[x][y][z] = ... (new Location(x,y,z))

But when I render them they are in this weird line that curves every X cubes... What am I doing wrong?

RENDERING:

public void render() {
    Cube[][][] temp = testchunk.getCubes();
    for (int z = 0; z<temp[0].length;z++) {
        for (int y = 0; y<temp[0][0].length; y++) {
            for (int x = 0; x<temp.length; x++) {
                Cube b = temp[x][z][y];
                if (b != null) {
                    GL11.glTranslatef(b.getPosition().x, b.getPosition().y, b.getPosition().z);
                    GL11.glCallList(cubes.get(b.getCubeId()));
                }
            }
        }
    }

}

GENERATING:

    for (int z = 0; z<cubes[0].length;z++) {
        for (int y = 0; y<cubes[0][0].length; y++) {
            for (int x = 0; x<cubes.length; x++) {
                cubes[x][z][y] = (Cube.dirt.getInstance()).setPosition(new Vector3f(position.x+(x*Cube.CUBE_SIZE),position.z+(z*Cube.CUBE_SIZE),position.y+(y*Cube.CUBE_SIZE)));
            }
        }
    }
share|improve this question
    
Try looping in ZYX order, otherwise we will need to see some more context: How are you rendering your cubes (i.e. code snippets) –  Mokosha Apr 29 '13 at 17:55
    
Doesnt work and im adding snippets now –  gopgop Apr 29 '13 at 18:13
1  
I think this is actually a "how to fix my code" question. –  Byte56 Apr 30 '13 at 1:14
add comment

closed as too localized by Byte56, msell, bummzack, Trevor Powell, Anko Apr 30 '13 at 15:31

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.

1 Answer

up vote 5 down vote accepted

You aren't resetting the modelview matrix, so each cube's translation is added to all further cubes. Use glPushMatrix and glPopMatrix around each translate-and-call.

share|improve this answer
    
To add to this question, understand you are not doing this so instead of pushing and popping just add to your current location is a valid solution also. –  Chris Condy Apr 30 '13 at 1:21
    
@ChrisCondy That can lead to accumulation of rounding error. –  Kevin Reid Apr 30 '13 at 1:32
add comment

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