1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
class GameObject
{
public:
vector<GLfloat> floatV;
vector<GLfloat> floatVN;
vector<GLfloat> index;
void loadModel(string filename)
{
ifstream file;
string ligne;
file.open(filename);
if (file.fail())
{
window.close();
}
if (!file.eof())
{
while (getline(file, ligne))
{
if (ligne.substr(0, 2) == "v ")
{
stringstream stream(ligne);
float xv, yv, zv;
string strv;
stream >> strv >> xv >> yv >> zv;
this->floatV.push_back(xv);
this->floatV.push_back(yv);
this->floatV.push_back(zv);
}
else if (ligne.substr(0, 2) == "vn")
{
stringstream stream(ligne);
float xvn, yvn, zvn;
string strvn;
stream >> strvn >> xvn >> yvn >> zvn;
this->floatVN.push_back(xvn);
this->floatVN.push_back(yvn);
this->floatVN.push_back(zvn);
}
else if (ligne.substr(0, 2) == "f ")
{
stringstream stream(ligne);
float xf, yf, zf;
string slash;
stream >> slash >> xf >> slash >> yf >> slash >> zf;
this->index.push_back(xf);
this->index.push_back(yf);
this->index.push_back(zf);
}
}
}
}
void renderModel()
{
glPushMatrix();
glEnable(GL_DEPTH_TEST);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, floatV.data());
glDrawElements(GL_TRIANGLES, 3, GL_INT, index.data());
glDrawArrays(GL_TRIANGLES, 0, 24);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
}; |
Partager