GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


crashing function by baldurk
int Model::GenNormals()
{
    FUNC("Model::GenNormals");
    vector<size_t> *vertcnts = new vector<size_t>[Vertices.size()];

    for(size_t i=0; i < Triangles.size(); i++)
    {
    Triangles[i].normal =
        (Vertices[Triangles[i].vertices[1]].pos -
         Vertices[Triangles[i].vertices[0]].pos) |
        (Vertices[Triangles[i].vertices[2]].pos -
         Vertices[Triangles[i].vertices[0]].pos);
    Triangles[i].normal.normalise();
    vertcnts[Triangles[i].vertices[0]].push_back(i);
    vertcnts[Triangles[i].vertices[1]].push_back(i);
    vertcnts[Triangles[i].vertices[2]].push_back(i);
    }

    for(size_t i=0; i < Vertices.size(); i++)
    {
    for(size_t j=0; j < vertcnts[i].size(); j++)
        Normals[i] += Triangles[vertcnts[i][j]].normal;

    Normals[i] /= vertcnts[i].size();
    Normals[i].normalise();
    }

    for(size_t i=0; i < Triangles.size(); i++)
    {
    Triangles[i].normals[0] = Triangles[i].vertices[0];
    Triangles[i].normals[1] = Triangles[i].vertices[1];
    Triangles[i].normals[2] = Triangles[i].vertices[2];
    }

    delete[] vertcnts;

    ENDRETURN(0);
}