Interfering Vector in glBegin()

I am trying to implement code for an assignment to render skeleton and mesh animations. In my glBegin(GL_TRIANGLES) section, I have some vectors that appear to be interfering with my information when it shouldn't.

glBegin(GL_TRIANGLES);
    for (int i = 0; i < mesh->nfaces.size(); i += 1)
      for (int k = 0; k < 3; k += 1) {
          int j = k;//2 - k;

          glm::vec4 myPointPrime;

          myPointPrime.w = 1;



          myPoint.x = ecks = mesh->vertex[mesh->faces[i][j]][0];
          myPoint.y = why = mesh->vertex[mesh->faces[i][j]][1];
          myPoint.z = zed = mesh->vertex[mesh->faces[i][j]][2];



            // Stuff vvvv THIS CAUSES PROBLEMS
          for (int t = 0; t < mySkeleton->vertex.at(i).size(); t++) {
              myPointPrime += mySkeleton->vertex[i][j] * MyXformations * myPoint;
          }

          glNormal3f(mesh->normal[mesh->nfaces[i][j]][0],
                    mesh->normal[mesh->nfaces[i][j]][1],
                    mesh->normal[mesh->nfaces[i][j]][2]);


          glVertex3f(mesh->vertex[mesh->faces[i][j]][0],
                    mesh->vertex[mesh->faces[i][j]][1],
                    mesh->vertex[mesh->faces[i][j]][2]);
         // glVertex3f(myPointPrime.x, myPointPrime.y, myPointPrime.z);
         // glVertex3f(myPoint.x, myPoint.y, myPoint.z);
    }
glEnd();

The myPointPrime += ... code is doing something weird to my Vertex calls, the scene won't render unless I comment out that for loop.

If I comment out the loop, then the scene renders, but I think I kinda need the loop if animating something like 16,000 vertexes is going to have any performance at all.

Is having that there kind of like having it automatically multiply with the glVertex calls?

Edit:

Below is another version of the code I hope should be more clear, instead of calculating the points in the actual drawing code I change the whole mesh to supposedly follow the skeleton each frame, but nothing is rendered.

for (int vertex_i = 0; vertex_i < mesh->nfaces.size(); vertex_i++) {
    for (int k = 0; k < 3; k += 1) {
        int j = k;//2 - k;

        pointp.x = 0;
        pointp.y = 0;
        pointp.z = 0;
        for (int t = 0; t < mySkeleton->vertex.at(vertex_i).size(); t++) {
            point.x = mesh->vertex[mesh->faces[vertex_i][j]][0];
            point.y = mesh->vertex[mesh->faces[vertex_i][j]][1];
            point.z = mesh->vertex[mesh->faces[vertex_i][j]][2];

            //glPushMatrix();
            pointp += mySkeleton->vertex[vertex_i][t] * myTranslationMatrix * myRotationMatrix * point;

            cout << "PointP X: " << pointp.x << " PointP Y: " << pointp.y << " PointP Z: " << pointp.z << endl;
            mesh->vertex[mesh->faces[vertex_i][j]][0] = pointp.x;
            mesh->vertex[mesh->faces[vertex_i][j]][1] = pointp.y;
            mesh->vertex[mesh->faces[vertex_i][j]][2] = pointp.z;
            //myPointPrime += MyXformations * myPoint;
        }
    }
}

My assumption is that maybe the calculations for pointp isn't doing what I think its doing?

mySkeleton->vertex[vertex_i][t] is a vector from my 'skeleton' class, it holds all of the weights for every vertex, there are 17 weights per vertex.

"MyXformations" is a 4x4 matrix passed from my skeleton animation function that holds the last known key frame and this is applied to the vertexes.

point is the current point in the vertex.

Answers


Your loop variable is t. However, you refer to j in the loop. Looks to me like your loop might simply be crashing for larger values of j.


You're not using t inside the for loop. Is this expected?

mySkeleton->vertex[i][j] looks like it's out of bounds since j should be for mesh->faces/mesh->nfaces.

Also you can use glNormal3fv and glVertex3fv with arrays.

With out of bounds memory operations you can get all sorts of weird stuff happening, although I can't see any out of bound writes. Your * operators don't modify the objects do they?

If you're worried about performance. You shouldn't be using immediate mode. Instead, put all your data on the GPU with buffer objects (including join/bone transformations) and animate on the fly in the vertex shader.

This is from a few years ago, but worth a read: http://http.developer.nvidia.com/GPUGems3/gpugems3_ch02.html


Need Your Help

ActiveRecord polymorphic association: making ID long instead of integer?

ruby-on-rails activerecord associations

With this as the seemingly only way to define a polymorphic association:

Hibernate: filter by list using criteria

java hibernate criteria

I have a Doctor entity. Each doctor has a list of HealthInsurance which is another entity.