Sky Color Not Interpolating

closed account (N36fSL3A)
I wrote a sky class for my game, and based on the time, it's supposed to interpolate the color between 5 base colors based on the time.

It starts at noon, however it isn't interpolating at all, just staying at a constant color. Here's the important section of the 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
#ifndef _SKY_H_
#define _SKY_H_

class CF::Sky
{
	public:

		Sky(GLfloat* sr, GLfloat* m, GLfloat* n, GLfloat* ss, GLfloat* nt, GameTime* g) /*...*/

		void Update()
		{
			// If a fourth of a second passed passed
			/*if(nowTime >= prevTime + 1000/4)
			{
				time->second++;
				time->Update(); // Update timer

				//iPerc += 1000/4;
				iPerc += 0.02f;

				prevTime = nowTime; // Previous time
			}*/time->second++;
				time->Update(); // Update timer

				//iPerc += 1000/4;
				iPerc += 0.02f;

				prevTime = nowTime; // Previous time

			nowTime = SDL_GetTicks(); // Now time
		}

		void Render()
		{
			GLfloat color[3] = {0, 0, 0};

			// Sky colors...
			if(selectedSky == 0)
				Interpolate(sunRColor, morningColor, color, iPerc);
			else if(selectedSky == 1)
				Interpolate(morningColor, noonColor, color, iPerc);
			else if(selectedSky == 2)
				Interpolate(morningColor, sunSColor, color, iPerc);
			else if(selectedSky == 3)
				Interpolate(morningColor, nightColor, color, iPerc);

			// Set clear color to interpolated value
			glClearColor(color[0], color[1], color[2], color[3]);

			/*Code for fog...*/
		}

		~Sky() /*...*/

	private:
		// Game Time
		GameTime* time;

		// Arrays
		GLfloat* sunRColor;
		GLfloat* morningColor;
		GLfloat* noonColor;
		GLfloat* sunSColor;
		GLfloat* nightColor;

		Uint32 prevTime;
		Uint32 nowTime;

		float iPerc;

		bool constructor;

		Uint8 selectedSky;

		/**FUNCTIONS**/
		void Interpolate(GLfloat* beg, GLfloat* end, GLfloat* ret, float percnt)
		{
			// Interpolate formula:
			// Vc = Vi + interpolatePercentage * (Vf – Vi)
			//
			// Vc = calculated value
			// Vi = intial value
			// Vf = end value

			GLfloat tmpA[3] = {beg[0], beg[1], beg[2]};
			GLfloat begn[3] = {beg[0], beg[1], beg[2]};

			for(unsigned int i = 0; i < 3; i++) // Interpolate the colors
				ret[i] = tmpA[i] + (percnt *(end[i] - tmpA[i]));
		}
};

#endif//_SKY_H_ 
This is just a guess and may not be the issue, but your initial value and end value are the same so ret[i] = tmpA[i] + (percnt *(end[i] - tmpA[i])); is the same as ret[i] = tmpA[i];
Misread the code.
Last edited on
closed account (N36fSL3A)
Never mind, I figured out the problem. I forgot to add code that adds 1 to the selected sky color when it hits 100% interpolation. Thanks for your help however.
Topic archived. No new replies allowed.