[c++] opengl render probleem

Pagina: 1
Acties:

  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
Het is me gelukt om een probleem te crieeren waarover google me niks kon vertellen :)

Ik hoop echter dat jullie dat wel kunnen, want ik heb geen flauw idee meer waar ik het moet zoeken :(

Afbeeldingslocatie: http://www2.hku.nl/~arjan0/plaatjes/screendump.jpg

Ziehier een screendump van linux (debian @ powerpc) met daarin geplakt een screendump van windows xp.
Het beeld zou op beide rendervensters hetzelfde moeten zijn (zoals de windows versie), maar zoals je kan zien is dit niet het geval. Het probleem is dat de vertex coordinaten wel goed ingeladen worden, want als ik ze laat outputten naar textfiles matchen ze perfect. Het gaat dus mis bij het daadwerkelijk op het scherm plaatsen. Heeft iemand enig idee waar dit aan zou kunnen liggen? Zonder goede keywords kom ik namelijk niet ver :(
Er zitten geen verschillen in de code, behalve dan een iets andere aanroep van het rendervenster in linux.

oprecht vertrouwen wordt nooit geschaad


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

Zie je, het bewijs dat linux zuigt :+ ;)

Hoe teken je je triangles precies, zijn dat tri of quad lists? Indexed of niet indexed?

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
.oisyn schreef op zondag 09 juli 2006 @ 15:34:
Zie je, het bewijs dat linux zuigt :+ ;)

Hoe teken je je triangles precies, zijn dat tri of quad lists? Indexed of niet indexed?
windowshippie!!11!!!!zes!!1211

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
    glBegin(GL_TRIANGLES);
        for(int i=0; i<faces.size(); i++) {
        // teken alle faces
            for(int j=0; j<3; j++) {
            // elk face kent 3 normals/vertices

                glNormal3f(faces[i].normals[j]->x, faces[i].normals[j]->y, faces[i].normals[j]->z);

                if(faces[i].texcoords[j]) glTexCoord2f(faces[i].texcoords[j]->x, faces[i].texcoords[j]->y);

                glVertex3f(faces[i].vertex[j]->x, faces[i].vertex[j]->y, faces[i].vertex[j]->z);
            }
        }
    glEnd();

het zijn tri's en tijdens het inlezen zijn ze indexed, maar ook deze worden correct ingelezen.

oprecht vertrouwen wordt nooit geschaad


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

Wat maakt die grijstinten, zijn dat de normalen die gebruikt worden bij de belichting of zijn het de texcoords? Probeer elke triangle anders eens een individuele kleur te geven, en kijk dan of windows overeen komt met linux.

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
.oisyn schreef op zondag 09 juli 2006 @ 16:27:
Wat maakt die grijstinten, zijn dat de normalen die gebruikt worden bij de belichting of zijn het de texcoords? Probeer elke triangle anders eens een individuele kleur te geven, en kijk dan of windows overeen komt met linux.
Die tinten zijn van de belichting, hoewel het om de een of andere manier nu niet lukt om een screengrab van de linux variant te produceren, lijkt het erop dat alles overeenkomt, behalve dan dus dat enkele triangles verkeerd worden geplaatst.
windows variant: Afbeeldingslocatie: http://www2.hku.nl/~arjan0/plaatjes/vertexcolor.jpg

heel vaag probleem dit :?

hier nog de code:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
    glBegin(GL_TRIANGLES);
        float teller = 0;
        for(int i=0; i<faces.size(); i++) {
            glColor4f(1 - teller/faces.size(), teller/faces.size(), 0, 1);
            teller++;
            for(int j=0; j<3; j++) {
                glNormal3f(faces[i].normals[j]->x,      faces[i].normals[j]->y,     faces[i].normals[j]->z);
                //if(faces[i].texcoords[j]) glTexCoord2f(faces[i].texcoords[j]->x,  faces[i].texcoords[j]->y);
                glVertex3f(faces[i].vertex[j]->x,       faces[i].vertex[j]->y,      faces[i].vertex[j]->z);
            }
        }
    glEnd();

Het rechter gele vlak zit in linux bv. haaks op de kijkrichting, waarbij de punt in de diepte linksonder ligt ipv rechtsonder in de diepte...

[edit]
Ok ik heb het waarschijnlijk ontdekt.
Er worden wat waardes anders gekopieerd, hetgeen achterlijk is aangezien er EXACT dezelfde code voor wordt gebruikt... :?
hier de output van diff:
code:
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
0, 0, 1                                                       | 0, 0, 1
0, 0, 1                                                       | 0, 0, 1
0, 0, 1                                                       | 0, 0, 1
0, 0, 1                                                       | 0, 0, 1
0, 0, 1                                                       | 0, 0, 1
0, 0, 1                                                       | 0, 0, 1
0, 0, -1                                                      | 0, 0, -1
0, 0, -1                                                      | 0, 0, -1
0, 0, -1                                                      | 0, 0, -1
0, 0, -1                                                      | 0, 0, -1
0, 0, -1                                                      | 0, 0, -1
0, 0, -1                                                      | 0, 0, -1
-1, 0, 0                                                      | -1, 0, 0
-1, 0, 0                                                      | -1, 0, 0
-1, 0, 0                                                      | -1, 0, 0
-1, 0, 0                                                      | -1, 0, 0
-1, 0, 0                                                      | -1, 0, 0
-1, 0, 0                                                      | -1, 0, 0
0, 1, 0                                                       | -1, 0, 0
0, 1, 0                                                       | 0, 1, 0
0, 1, 0                                                       | 0, 1, 0
0, 1, 0                                                       | 0, 1, 0
0, 1, 0                                                       | 0, 1, 0
0, 1, 0                                                       | 0, 1, 0
1, 0, 0                                                       | 0, 1, 0
1, 0, 0                                                       | 1, 0, 0
1, 0, 0                                                       | 1, 0, 0
1, 0, 0                                                       | 1, 0, 0
1, 0, 0                                                       | 1, 0, 0
1, 0, 0                                                       | 1, 0, 0
vertices:                                                     | vertices:
-1, -1, -1                                                    | -1, -1, -1
-1, 1, -1                                                     | -1, 1, -1
1, -1, -1                                                     | 1, -1, -1
1, 1, -1                                                      | 1, 1, -1
1, -1, -1                                                     | 1, -1, -1
-1, 1, -1                                                     | -1, 1, -1
1, 1, 1                                                       | 1, 1, 1
-1, 1, 1                                                      | -1, 1, 1
1, -1, 1                                                      | -1, 1, 1
-1, -1, 1                                                     | 1, 1, -1
1, -1, 1                                                      | -1, 1, 1
-1, 1, 1                                                      | -1, 1, 1
1, -1, -1                                                     | 1, -1, -1
1, 1, -1                                                      | 1, 1, -1
1, -1, 1                                                      | -1, 1, 1
1, 1, 1                                                       | 1, 1, 1
1, -1, 1                                                      | -1, 1, 1
1, 1, -1                                                      | 1, 1, -1
-1, -1, -1                                                    | -1, -1, -1
1, -1, -1                                                     | 1, -1, -1
-1, -1, 1                                                     | 1, 1, -1
1, -1, 1                                                      | -1, 1, 1
-1, -1, 1                                                     | 1, 1, -1
1, -1, -1                                                     | 1, -1, -1
-1, 1, -1                                                     | -1, 1, -1
-1, -1, -1                                                    | -1, -1, -1
-1, 1, 1                                                      | -1, 1, 1
-1, -1, 1                                                     | 1, 1, -1
-1, 1, 1                                                      | -1, 1, 1
-1, -1, -1                                                      -1, -1, -1
bij de normals gaat het prima, maar bij de vertex coordinaten gaat het hier en daar mis, wtf.

[ Voor 101% gewijzigd door Arjan op 09-07-2006 17:22 ]

oprecht vertrouwen wordt nooit geschaad


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

De normals komen overigens ook niet overeen, of is dat een copypaste fout? Kijk bijvoorbeeld eens naar regel 19, links (0, 1, 0), rechts (-1, 0, 0). Zelfde verhaal op regel 25, alsof die ene (-1, 0, 0) van regel 19 teveel is en alles opschuift.

Wat me verder opvalt aan de fouten bij de vertices is dat als het fout gaat, of x en y omgedraaid worden, of de vertex in z'n geheel genegeerd wordt (is er eigenlijk een fatsoenlijke Nederlandse vertaling van "to negate", in de wiskundige betekenis van het woord?).

Hoe lees je de vertices?

[ Voor 5% gewijzigd door .oisyn op 09-07-2006 19:39 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
.oisyn schreef op zondag 09 juli 2006 @ 19:38:
De normals komen overigens ook niet overeen, of is dat een copypaste fout? Kijk bijvoorbeeld eens naar regel 19, links (0, 1, 0), rechts (-1, 0, 0). Zelfde verhaal op regel 25, alsof die ene (-1, 0, 0) van regel 19 teveel is en alles opschuift.
die had ik over het hoofd gezien ja
Wat me verder opvalt aan de fouten bij de vertices is dat als het fout gaat, of x en y omgedraaid worden, of de vertex in z'n geheel genegeerd wordt (is er eigenlijk een fatsoenlijke Nederlandse vertaling van "to negate", in de wiskundige betekenis van het woord?).

Hoe lees je de vertices?
hehe, dat is een draak^2 :P (hij kan ongetwijfeld veel mooier)
code:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
    std::vector<float> tempVertex, tempNormal, tempTexCoords;

    std::string temp, woord;

    int parseType = 0;

    bool nextLine = false;

    std::vector<std::string> keywords;

    keywords.push_back("Coordinate");

    keywords.push_back("Normal");

    keywords.push_back("TextureCoordinate");

    keywords.push_back("coordIndex");

    keywords.push_back("texCoordIndex");

    keywords.push_back("normalIndex");

    keywords.push_back("diffuseColor");

    keywords.push_back("transparency");

    keywords.push_back("url");

    std::vector<std::string> data;

    std::ifstream wrl;

    wrl.open(url.c_str());

    if(!wrl) return 1;
    
    std::vector<point3f> vertex;        //x,z,y,x,z,y...

    std::vector<point3f> texCoords;     //x,z,y,x,z,y...

    std::vector<point3f> normal;        //x,z,y,x,z,y...

    std::vector<int> coordsIndex;       //0,1,2,0,1,2...

    std::vector<int> texCoordsIndex;    //0,1,2,0,1,2...

    std::vector<int> normalIndex;       //0,1,2,0,1,2...
    

    while(getline(wrl, temp)) {

        for(int i=0; i<temp.length(); i++) {

            if(temp[i] == ',') temp.erase(i, 1);

            if(temp[i] == ']') {

                if(temp[i-1] != ' ') {

                    temp.insert(i, " ");

                    i++;

                }

            }



        }

        if(temp[temp.size()-1] == ' ') {    //trailing space

            temp.erase(temp.size()-1, 1);

        }

        std::stringstream tempstream(temp);

        int checkDelim;

        while(!tempstream.eof()) {

            nextLine = false;

            tempstream >> woord;

            if(parseType > 0) {

                if(woord == "]") {

                    parseType = 0;

                } else {

                    switch(parseType) {

                    case 1:

                        tempVertex.push_back( atof(woord.c_str()) );

                        break;

                    case 2:

                        tempNormal.push_back( atof(woord.c_str()) );

                        break;

                    case 3:

                        tempTexCoords.push_back( atof(woord.c_str()) );

                        break;

                    case 4:

                        checkDelim = atoi(woord.c_str());

                        if(checkDelim != -1) coordsIndex.push_back( checkDelim );

                        break;

                    case 5:

                        checkDelim = atoi(woord.c_str());

                        if(checkDelim != -1) texCoordsIndex.push_back( checkDelim );

                        break;

                    case 6:

                        checkDelim = atoi(woord.c_str());

                        if(checkDelim != -1) normalIndex.push_back( checkDelim );

                        break;

                    case 7:

                        color[0] = atof(woord.c_str());

                        tempstream >> woord;

                        color[1] = atof(woord.c_str());

                        tempstream >> woord;

                        color[2] = atof(woord.c_str());

                        parseType = 0;

                        break;

                    case 8:

                        color[3] = 1 - atof(woord.c_str());

                        parseType = 0;

                        break;

                    case 9:

                        for(int i=0; i<woord.length(); i++) {

                            if(woord[i] == '"') woord.erase(i, 1);

                        }

                        loadedURL = woord;

                        parseType = 0;

                        break;

                    default:

                        break;

                    }

                }

            }

            int j = 0;

            for(int i=0; i<keywords.size(); i++) {

                if(woord == keywords[i]) {

                    parseType = i + 1;

                    if(parseType < 7) nextLine = true;

                    break;

                }

            }

            if(nextLine) break;

        }

        data.push_back(temp);

    }

    wrl.close();



    for(int a=0; a<tempVertex.size(); a++) {

        tempVertex[a] /= 512;

    }

    for(int a=0; a<tempVertex.size(); a+=3) {

        vertex.push_back( point3f(tempVertex[a], tempVertex[a+2], tempVertex[a+1]) );
        //std::cout << vertex[a] << std::endl;

    }

    for(int a=0; a<tempNormal.size(); a+=3) {

        normal.push_back( point3f(tempNormal[a], tempNormal[a+2], tempNormal[a+1]) );
        //std::cout << normal[a] << std::endl;

    }

    for(int a=0; a<tempTexCoords.size(); a+=2) {

        texCoords.push_back( point3f(tempTexCoords[a], tempTexCoords[a+1], 0.0f) );
        //std::cout << texCoords[a] << std::endl;

    }

    for(int i=0; i<coordsIndex.size(); i+=3) {

        face temp = face();



        temp.vertexIndex[0] = coordsIndex[i];

        temp.vertexIndex[1] = coordsIndex[i+1];

        temp.vertexIndex[2] = coordsIndex[i+2];



        temp.normalIndex[0] = normalIndex[i];

        temp.normalIndex[1] = normalIndex[i+1];

        temp.normalIndex[2] = normalIndex[i+2];



        if(texCoordsIndex.size() > i) {

            temp.texIndex[0] = texCoordsIndex[i];

            temp.texIndex[1] = texCoordsIndex[i+1];

            temp.texIndex[2] = texCoordsIndex[i+2];

        }



        for(int j=0; j<3; j++) {

            temp.normals[j] = normal[normalIndex[i+j]];

            temp.vertex[j] = vertex[coordsIndex[i+j]];

            temp.texcoords[j] = texCoords[texCoordsIndex[i+j]];

        }

        faces.push_back(temp);

    }



    if(vertex.size() > 2) {

        for(int a=0; a<faces.size(); a++) {

            for(int b=0; b<3; b++) {

                faces[a].edges[b].vertex[0] = &faces[a].vertex[b];

                faces[a].edges[b].vertex[1] = &faces[a].vertex[(b+1)%3];

            }

            faces[a].planeEquation = calculatePlane(a);

        }
        

        for(int a=0; a<faces.size(); a++) {

            for(int b=0; b<faces.size(); b++) {

                if(a!=b) {

                    for(int c=0; c<3; c++) {

                        for(int d=0; d<3; d++) {

                            if(faces[a].edges[c].vertex[0] == faces[b].edges[d].vertex[0]) {

                                if(faces[a].edges[c].vertex[1] == faces[b].edges[d].vertex[1]) {

                                    faces[a].edges[c].neighbour = &faces[b];

                                }

                            }

                            if(faces[a].edges[c].vertex[0] == faces[b].edges[d].vertex[1]) {

                                if(faces[a].edges[c].vertex[1] == faces[b].edges[d].vertex[0]) {

                                    faces[a].edges[c].neighbour = &faces[b];

                                }

                            }

                            if(!faces[a].edges[c].neighbour) faces[a].edges[c].neighbour = &faces[a];

                        }

                    }

                }

            }

        }



        minX = vertex[0].x;

        maxX = vertex[0].x;

        minY = vertex[0].y;

        maxY = vertex[0].y;

        minZ = vertex[0].z;

        maxZ = vertex[0].z;



        for(int a=0; a<vertex.size(); a++) {

            minX = vertex[a].x < minX ? vertex[a].x : minX;

            maxX = vertex[a].x > maxX ? vertex[a].x : maxX;



            minY = vertex[a].y < minY ? vertex[a].y : minY;

            maxY = vertex[a].y > maxY ? vertex[a].y : maxY;



            minZ = vertex[a].z < minZ ? vertex[a].z : minZ;

            maxZ = vertex[a].z > maxZ ? vertex[a].z : maxZ;

        }

    }



    width = maxX - minX;

    height = maxY - minY;

    depth = maxZ - minZ;



    return 0;
met de while loop, loop ik lijn voor lijn door de .WRL bestanden(die gebruik ik voor de modellen).
Ik denk dat ik deze code helemaal opnieuw ga maken, want dit is chaos,maar toch errrg raar dat ie t wel doet onder windows en niet onder linux...

oprecht vertrouwen wordt nooit geschaad


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

Is boost::spirit niets voor jou? ;)

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
Dat scoort een 10 op de NCPP schaal ben ik bang :P
maar ik begrijp dat het wel de moeite is om me dit eigen te maken?

offtopic:
Nieuwe Concepten Per Pixel

oprecht vertrouwen wordt nooit geschaad


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
C++:
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// haal data op van schijf //
    std::ifstream wrl;
    wrl.open(url.c_str());
    if(!wrl) return;
    std::string temp, data;
    data.clear();
    while(getline(wrl, temp)) {
        // negeer comments //
        if(temp[0] != '#') {
            // zorg ervoor dat de brackets altijd omgeven zijn door spaties //
            for(int i=0; i<temp.size(); i++) temp[i] = temp[i] == ',' ? ' ' : temp[i];
            if(temp.size() > 2) temp.insert(temp.size()-2, " ");
            data += " " + temp;
        }
    }
    wrl.close();
    // einde //

    std::stringstream woordstream(data);
    std::string woord;

    while(!woordstream.eof()) {
        woordstream >> woord;

        if(woord == "Material") {
            while(!woordstream.eof()) {
                woordstream >> woord;
                if(woord == "diffuseColor") {
                    for(int i=0; i<3; i++) {
                        woordstream >> woord;
                        model.diffuseColor[i] = strtof(woord.c_str(), NULL);
                    }
                } else if(woord == "ambientIntensity") {
                    woordstream >> woord;
                    model.ambientIntensity = strtof(woord.c_str(), NULL);
                } else if(woord == "specularColor") {
                    model.specularColor[3] = 1.0f;
                    for(int i=0; i<3; i++) {
                        woordstream >> woord;
                        model.specularColor[i] = strtof(woord.c_str(), NULL);
                    }
                } else if(woord == "shininess") {
                    woordstream >> woord;
                    model.shininess = strtof(woord.c_str(), NULL);
                } else if(woord == "transparency") {
                    woordstream >> woord;
                    model.diffuseColor[3] = 1 - strtof(woord.c_str(), NULL);
                    break;
                } else {
                    //break;
                }
            }
        } else if(woord == "ccw") {
            woordstream >> woord;
            model.ccw = woord == "TRUE" ? true : false;
        } else if(woord == "coord") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                //std::cout << "\n|" << woord << "|\n";
                if(woord[0] != ',') model.coord.push_back(strtof(woord.c_str(), NULL));
                woordstream >> woord;
            }
        } else if(woord == "normal") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                if(woord[0] != ',') model.normal.push_back(strtof(woord.c_str(), NULL));
                woordstream >> woord;
            }
        } else if(woord == "texCoord") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                if(woord[0] != ',') model.texCoord.push_back(strtof(woord.c_str(), NULL));
                woordstream >> woord;
            }
        } else if(woord == "coordIndex") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                if(woord[0] != ',' && woord[0] != '-') model.coordIndex.push_back(atoi(woord.c_str()));
                woordstream >> woord;
            }
        } else if(woord == "normalIndex") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                if(woord[0] != ',' && woord[0] != '-') model.normalIndex.push_back(atoi(woord.c_str()));
                woordstream >> woord;
            }
        } else if(woord == "texCoordIndex") {
            while(woord != "[") woordstream >> woord;
            woordstream >> woord;
            while(woord != "]") {
                if(woord[0] != ',' && woord[0] != '-') model.texCoordIndex.push_back(atoi(woord.c_str()));
                woordstream >> woord;
            }
        }
    }

Ik heb het geheel al terug weten te brengen tot een stuk duidelijkere code :)
Het probleem ligt bij regel 12.
ik scheidt alle karakters van elkaar dmv spaties. Daardoor kan ik ze vervolgens per woord uitlezen met de stringstream en de >> operator.
Echter, soms zit het ']' karakter vast aan een float, dus moet ik ze van elkaar scheiden. Logisch leek mij om daarvoor de volgende code te gebruiken:
C++:
1
if(temp.size() > 1) temp.insert(temp.size()-1, " ");

Als het gelezen woord langer is dan 1 karakter, wil ik een spatie plaatsen voor het laatste karakter, oftewel insert(laatste_karakter, " ")
Nu werkt dit onder windows prima, maar onder linux moet ik niet size() - 1, maar size() - 2 gebruiken en de reden daarvoor ontgaat me een beetje :/

oprecht vertrouwen wordt nooit geschaad


  • SPee
  • Registratie: Oktober 2001
  • Laatst online: 13-02 11:29
Waarschijnlijk omdat Linux en Windows anders met de regeleinden werken.
Bij windows: /r/n
Bij linux: /n
Dat scheelt in jouw geval die extra karakter.

Althans volgens mijn theorie ;)

let the past be the past.


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

Dat zou echter betekenen dat het andersom zou zijn: onder linux -1, en onder windows -2. Bovendien gaat het sowieso niet op omdat de stream standaard wordt geopend als tekst waarbij \r\n combinaties terug worden gezet naar \n tekens.

Hoe zien de strings op de verschillende platforms er eigenlijk uit?

[ Voor 22% gewijzigd door .oisyn op 11-07-2006 14:50 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
dit is de string zoals die wordt gemaakt voor windows met size()-1
C++:
1
   DEF Box01 Transform  { translation 0 0  0 children  [ Shape  { appearance Appearance  { material Material  { diffuseColor 0.5882 0.5882 0.588 2 ambientIntensity 1. 0 specularColor 0 0  0 shininess 0.14 5 transparency  0 } texture ImageTexture  { url "test.bmp " } } geometry DEF Box01-FACES IndexedFaceSet  { ccw TRU E solid TRU E coord DEF Box01-COORD Coordinate { point  [ -512 -512 512  512 -512 512  -512 -512 -512  512 -512 -512  -512 512 512    512 512 512  -512 512 -512  512 512 -512 ] } normal Normal { vector  [ 1 0 0  -1 0 0  0 1 0  0 0 1  0 -1 0  ]  } normalPerVertex TRU E texCoord DEF Box01-TEXCOORD TextureCoordinate { point  [ 0 0  1 0  0 1  1 1  0 0  1 0  0 1  1 1  0 0  1 0  0 1  1 1 ] } coordIndex  [ 2  0  3  -1  1  3  0  -1  5  4  7  -1  6  7  4  -1  3  1  7  -1    5  7  1  -1  2  3  6  -1  7  6  3  -1  0  2  4  -1  6  4  2  -1 ] texCoordIndex  [ 11  9  10  -1  8  10  9  -1  9  8  11  -1  10  11  8  -1  1  0  3  -1    2  3  0  -1  5  4  7  -1  6  7  4  -1  1  0  3  -1  2  3  0  -1 ] normalIndex  [ 2  2  2  -1  2  2  2  -1  4  4  4  -1  4  4  4  -1  1  1  1    -1  1  1  1  -1  3  3  3  -1  3  3  3  -1  0  0  0  -1  0  0    0  -1   ] } } ] }

dit is dus de data string nadat de wrl file gesloten wordt.

er lijkt toch waarheid in de /r/n uitleg te zitten, kijkend naar de output van dezelfde code onder linux:
C++:
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
 
 
 DEF Box01 Transform { 
 translation 0 0 0 
 children [ 
 Shape { 
 appearance Appearance { 
 material Material { 
 diffuseColor 0.5882 0.5882 0.5882 
 ambientIntensity 1.0 
 specularColor 0 0 0 
 shininess 0.145 
 transparency 0 
 } 
 texture ImageTexture { 
 url "test.bmp" 
 } 
 } 
 geometry DEF Box01-FACES IndexedFaceSet { 
 ccw TRUE 
 solid TRUE 
 coord DEF Box01-COORD Coordinate { point [ 
 -512 -512 512  512 -512 512  -512 -512 -512  512 -512 -512  -512 512 512   
 512 512 512  -512 512 -512  512 512 -512] 
 } 
 normal Normal { vector [ 
 1 0 0  -1 0 0  0 1 0  0 0 1  0 -1 0  ] } 
 normalPerVertex TRUE 
 texCoord DEF Box01-TEXCOORD TextureCoordinate { point [ 
 0 0  1 0  0 1  1 1  0 0  1 0  0 1  1 1  0 0  1 0  0 1  1 1] 
 } 
 coordIndex [ 
 2  0  3  -1  1  3  0  -1  5  4  7  -1  6  7  4  -1  3  1  7  -1   
 5  7  1  -1  2  3  6  -1  7  6  3  -1  0  2  4  -1  6  4  2  -1] 
 texCoordIndex [ 
 11  9  10  -1  8  10  9  -1  9  8  11  -1  10  11  8  -1  1  0  3  -1   
 2  3  0  -1  5  4  7  -1  6  7  4  -1  1  0  3  -1  2  3  0  -1] 
 normalIndex [ 
 2  2  2  -1  2  2  2  -1  4  4  4  -1  4  4  4  -1  1  1  1   
 -1  1  1  1  -1  3  3  3  -1  3  3  3  -1  0  0  0  -1  0  0   
 0  -1  ] 
 } 
 } 
 ] 
 } 

regel 12 maar vast gewijzigd naar het zinnigere:
C++:
1
2
3
            int endchar = temp.find(']');

            if(endchar != std::string::npos) temp.insert(endchar, " ");
waardoor er nog steeds newlines in de code zitten, maar de ']' karakters tenminste gescheiden worden door een spatie.
[edit]
C++:
1
2
endchar = temp.find('\r');
if(endchar != std::string::npos) temp[endchar] = ' ';
Zo, nu zijn we ook van de endlines af :)

[ Voor 48% gewijzigd door Arjan op 11-07-2006 15:28 ]

oprecht vertrouwen wordt nooit geschaad


  • .oisyn
  • Registratie: September 2000
  • Laatst online: 13-02 18:54

.oisyn

Moderator Devschuur®

Demotivational Speaker

Ah, gebruik je soms dezelfde file, dus met de \r\n newlines van windows, in linux? Want in linux worden die \r's er natuurlijk niet uitgefilterd.

De oplossing kan veel simpeler, gewoon "\r\n" als 3e parameter aan getline meegeven.

[ Voor 25% gewijzigd door .oisyn op 11-07-2006 15:28 ]

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


  • Arjan
  • Registratie: Juni 2001
  • Niet online

Arjan

copyright is wrong

Topicstarter
.oisyn schreef op dinsdag 11 juli 2006 @ 15:27:
Ah, gebruik je soms dezelfde file, dus met de \r\n newlines van windows, in linux? Want in linux worden die \r's er natuurlijk niet uitgefilterd.

De oplossing kan veel simpeler, gewoon "\r\n" als 3e parameter aan getline meegeven.
ah :)
ja, ik gebruik idd dezelfde file, ik had er alleen niet bij stil gestaan dat die /r's er niet uit werden gefilterd, probleem iig opgelost! thanks!

oprecht vertrouwen wordt nooit geschaad

Pagina: 1