Skip to content

Day 5 (190909)

Juhwi Eden Kim edited this page Oct 7, 2019 · 1 revision
  • Reversed the code

Wireframe Rendering (Reversing)


1. I analyzed Model class.

I didn't get the exact meaning, but I could guess most of it.

2. I analyzed main.cpp .

Now I can understand furthermore.

3. Questions I've had today

// model.h
class Model {
private:
    std::vector<Vec3f> verts_;
    std::vector<std::vector<int> > faces_;
public:
    ...
};
// model.cpp
Model::Model(const char *filename) : verts_(), faces_() {  // consturctor of Model
    ...
    char trash;
    if (...) {
        ...
        verts_.push_back(v);
    } else if (...) {
        ...
        faces_.push_back(f);
    }
}

I'm guessing verts_ and faces_ is vector variables, and to use them in a class, I have to inherit the constructors of the vectors. But I still don't know why.

char trash; 
if (!line.compare(0, 2, "v ")) { 
    iss >> trash;
    Vec3f v;
    for (int i=0;i<3;i++) iss >> v.raw[i];
    verts_.push_back(v);
} else if (!line.compare(0, 2, "f ")) { 
    std::vector<int> f;
    int itrash, idx;
    iss >> trash;
    while (iss >> idx >> trash >> itrash >> trash >> itrash) {
        idx--; // in wavefront obj all indices start at 1, not zero
        f.push_back(idx);
    }
    faces_.push_back(f);
}

I'm guessing that it means if it is v, push to verts_, else if it is f, push to faces_. I wish I could open the object file as code so that I can figure out what it means.

Other comments are in the code.