Ciao a tutti,
ho un piccolo probelma in c++ con l'utilizzo delle matrici. Posto subito il codice:
codice:
void draw_model(string file, float** coordinate, float** texture, float** normal){
ifstream input(file);
string riga="";
glEnable(GL_TEXTURE_2D);
glBegin(GL_POLYGON);
while(getline(input,riga)){
if(riga.empty()) continue;
if(isTexture(riga)!=""){
char* param=isTexture(riga);
LoadGLTextures(param);
glBindTexture(GL_TEXTURE_2D,tex);
}
if(riga[0]=='f'){
for(int scelta_f=1;scelta_f<riga.size();scelta_f++){
if(riga[scelta_f]!=' '){
int n_pos=0;
string vertex="";
string texture="";
string normal="";
while(scelta_f<riga.size() && riga[scelta_f]!=' ' && riga[scelta_f]!='/'){
vertex+=riga[scelta_f]; n_pos++; scelta_f++;
}
if(scelta_f<riga.size() && riga[scelta_f]=='/'){
scelta_f++;
while(scelta_f<riga.size() && riga[scelta_f]!=' ' && riga[scelta_f]!='/'){
texture+=riga[scelta_f]; scelta_f++;
}
scelta_f++;
while(scelta_f<riga.size() && riga[scelta_f]!=' '){
normal+=riga[scelta_f]; scelta_f++;
}
}
int v=stoi(vertex)-1;
int t=stoi(texture)-1;
int n=stoi(normal)-1;
glTexCoord2f(texture[t][0],texture[t][1]);
glNormal3f(normal[n][0],normal[n][1],normal[n][2]);
glVertex3f(coordinate[v][0],coordinate[v][1],coordinate[v][2]);
}
}
}
}
glEnd();
input.close();
}
Questa funzione disegna un poligono 3D tramite OpenGL leggendo i dati da un file .obj e avente in input 3 matrici: coordinate[n° vertici][3], texture[n° vertici texture][2], normal[n° vertici normali][3]. Il problema si presenta nelle ultime 2 righe, esattamente in
codice:
glTexCoord2f(texture[t][0],texture[t][1]);
glNormal3f(normal[n][0],normal[n][1],normal[n][2]);
L'errore è: subscript requires array or pointer type.
Premettendo che io di c++ non sono un esperto, dove sbaglio? Il mio potrebbe anche essere un errore banalissimo, ma io non lo capisco! Cosa dovrei scrivere di preciso? contando che le matrici vengono create tutte e 3 in questo modo:
codice:
float** coord=new float*[vertici];
for(int i=0; i<vertici; i++){
coord[i]=new float[3];
for(int j=0; j<3; j++){
coord[i][j]=0.0;
}
}
Dov'è l'errore?