bonjour,

j'ai actuellement un problème quant à l'utilisation des vectors dans mon programme.
en effet j'écris actuellement un programme qui génère un terrain 3d avec gestion des ombres à partir d'un maillage numérique du terrain.
j'ai trouvé que le problème se situait dans ce bout de code, qui est l'algo de calcul d'ombre :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
void VC3( vector< double > & coord ) 
{
  string line;
  ifstream myfile ("test2.txt");
 
 
  if (myfile.is_open())
  {
 
     coord.reserve(1200);
    while ( getline (myfile,line))
      {
 
      stringstream ss(line);  
 
	double nombre1;
    double nombre2;
	double nombre3;
	char   sep;
 
 
	while(ss >> nombre1 >> sep >> nombre2 >> sep >> nombre3)
	    {
		coord.push_back(nombre3);
	    }
 
      }
 
    myfile.close();
  }
 
  else cout << "Unable to open file"; 
 
 
}
 
// Deuxième parie : algorithme d'ombrage
 
 
void Color( vector< double > &lightcolor ) 
 {
    vector< double > heightmap;
    VC3( heightmap ); //fonction qui remplit le vector heightmap
 
	double s;
	s = heightmap.size();
    int size;
	size = sqrt(s);
	lightcolor.resize(s);
 
	// calcule lightDir selon la position du soleil, heure par heure, pendant l'année
 
 
 
	float direct = 0;
    int j = 180;
	int t = 20;
	double pi = 3.141592654;
    float Io = 0;
 
 
 
		Io = 1367*(1+ 0.033*cos(j*2*pi/365.25));
 
 
 
 
 
 
	// on obtient les 3 composantes de la lumière :
			float lightDir[3];
			lightDir[0] = 0.9;
			lightDir[1] = -0.4;
			lightDir[2] =  0.6;
 
	 // Masque de l'horizon
 
 
 
 
	 // create flag buffer to indicate where we've been
        float *flagMap = new float[s];
        for(int i = 0; i < s; i++) 
            flagMap[i] = 0;
 
        int *X, *Y;
        int iX, iY;
        int dirX, dirY;
		int index;	
 
         // calculate absolute values for light direction
        float lightDirXMagnitude = lightDir[0];
        float lightDirZMagnitude = lightDir[2];
        if(lightDirXMagnitude < 0) lightDirXMagnitude *= -1;
        if(lightDirZMagnitude < 0) lightDirZMagnitude *= -1;
 
        // decide which loop will come first, the y loop or x loop
        // based on direction of light, makes calculations faster
        if(lightDirXMagnitude > lightDirZMagnitude)
        {
                Y = &iX;
                X = &iY;
 
                if(lightDir[0] < 0)
                {
                        iY = size-1;
                        dirY = -1;
                }
                else
                {
                        iY = 0;
                        dirY = 1;
                }
 
                if(lightDir[2] < 0)
                {
                        iX = size-1;
                        dirX = -1;
                }
                else
                {
                        iX = 0;
                        dirX = 1;
                }
        }
        else
        {
                Y = &iY;
                X = &iX;
 
                if(lightDir[0] < 0)
                {
                        iX = size-1;
                        dirX = -1;
                }
                else
                {
                        iX = 0;
                        dirX = 1;
                }
 
                if(lightDir[2] < 0)
                {
                        iY = size-1;
                        dirY = -1;
                }
                else
                {
                        iY = 0;
                        dirY = 1;
                }
        }
 
 
       // outer loop
       while(1)
       {
           // inner loop
           while(1)
           {
              		float px, py, height, distance;
			int index;	              
			   px = *X;
               py = *Y;
 
               index = (*Y)* size  + (*X);
			   vector<double>::iterator it = lightcolor.begin()+index;
 
               // travel along ray
               while(1)
               {
                   px -= lightDir[0];
                   py -= lightDir[2];
 
                  // check if we've reached the boundary
                  if(px < 0 || px >= size-1 || py < 0 || py >= size-1)
                  {  
                      flagMap[index] = -1;
					  *it =255;
					  direct += 1300;
					  break;
                  }
 
                  (...lignes sans rapport...)
 
                 // get height at current point while traveling along light ray
                 height = heightmap[index] - lightDir[1]*distance;
 
                   static float val;
                 val = interpolatedHeight;
                 if(0 < interpolatedFlagMap) val = interpolatedFlagMap + interpolatedHeight;
            if(height < val)
 
                 {
                     flagMap[index] = val - height ;
  					  *it =0;
				   break;
                 }
 
 
		else
              {
                flagMap[index] = -1.0;
				// calcul de la composante directe sur un plan incliné : 
                *it =255;
				break;
              }   
 
             }
 
             // update inner loop variable
             if(dirY < 0)
             {
                 iY--;
                 if(iY < 0) break;
             }
             else
             {
                 iY++;
                 if(iY >= size) break;
             }
         }
 
         // reset inner loop starting point
         if(dirY < 0) iY = size - 1;
         else iY = 0;
 
         // update outer loop variable
         if(dirX < 0)
         {
             iX--;
             if(iX < 0) break;
         }
         else
         {
             iX++;
             if(iX >= size) break;
         }
     }
 
 
     delete [] flagMap;
 
	 cout << "tâche 4 terminée"<< ' ';
 
 
 }
le problème se situe au niveau de l'utilisation que je fais du vector "lightdir", mais je ne vois pas ou...
si vous pouviez trouver des pistes...merci!

ps: j'ai enlevé pas mal de lignes donc il ne compilera pas tel quel