Quantcast
Channel: bugs, errors - openFrameworks
Viewing all articles
Browse latest Browse all 636

Generating a Cube of Points using a for loop

$
0
0

Hi, I’m trying to draw a cube in 3D space using points rendered at each vertex. I am currently trying to figure out a system which draws them without me having to copy code and manually enter vertex positions, but I am having trouble.
The for loop I am using is:

    for(int i = 0; i < 8; i++){
        int j = i % 4;
        if(j == 0){ //then i = 0 || 4.
            int k = (i/2) - 1; // k is -1 or 1.
            mesh.addVertex(ofVec3f(-15, 0, -15 * k));
        } else if (j == 1){ //then i = 1 || 5.
            int k = ((i-1)/2) - 1; //k is -1 or 1.
            mesh.addVertex(ofVec3f(15, 0, -15 * k));
        } else if (j == 2){ //then i = 2 || 6.
            int k = ((i-2)/2) - 1; //k is -1 or 1.
            mesh.addVertex(ofVec3f(-15, -30, -15 * k));
        } else if (j == 3){ //then i = 3 || 7.
            int k = ((i-3)/2) - 1; //k is -1 or 1.
            mesh.addVertex(ofVec3f(15, -30, -15 * k));
            //this should always output 0 and 2.
            std::cout << "value: " << (i-3)/2 << endl;
        }
        mesh.addIndex(i);
    }

Effectively making a 2D square with vertices, and then using the modulo operator and k value to draw one in front and one behind. The overall cube dimensions are 30x30x30. I thought this code was correct, however only 6 vertices render in the window. Can anyone help me figure out what might be going wrong?

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 636

Trending Articles