37 #if defined(_X86) && !defined(_WIN64)
38 inline int f2i(
float flt)
51 inline int f2i(
float flt)
61 static bool refractInit =
false;
63 static const int WAVE_SIZE = 256;
64 static const DWORD WAVE_MASK = 0xff;
69 : size(0), depth(0), scaleTex(1), avgHeight(0),
70 nVertices(0), surface(0), waves(0)
96 for (UINT u = 0; u < 256; u++) {
97 float fCos0 = (float) u / (
float) 256.0f;
98 float f0 = acosf(fCos0);
99 float fSin0 = sinf(f0);
101 float fSin1 = fSin0 / 1.333f;
102 float f1 = asinf(fSin1);
103 float fCos1 = cosf(f1);
105 refract[u].
refract = fSin0 / fSin1 * fCos1 - fCos0;
107 refract[u].
diffuse = ((((0xff - u)*(0xff - u)*(0xff - u)) << 8) & 0xff000000);
109 RefractionTable[u] = RefractionTable[256];
125 waves =
new(__FILE__,__LINE__)
float[WAVE_SIZE*4];
127 double f = 1.0 / (double) WAVE_SIZE;
128 for (
int i = 0; i < WAVE_SIZE; i++) {
129 double s0 = sin(2*
PI*i*f);
130 double s1 = sin(4*
PI*i*f);
131 double s2 = sin(6*
PI*i*f);
132 double s3 = sin(8*
PI*i*f);
134 waves[0*WAVE_SIZE + i] = (float) (1.8 * s0*s0 - 0.9);
135 waves[1*WAVE_SIZE + i] = (float) (1.6 * s1*s1 - 0.8);
136 waves[2*WAVE_SIZE + i] = (float) (0.4 * s2);
137 waves[3*WAVE_SIZE + i] = (float) (0.8 * s3*s3 - 0.4);
140 for (
int i = 0; i < 4; i++) {
157 UINT STEP = WAVE_SIZE / (SIZE-1);
159 UINT AREA = SIZE * SIZE;
162 for (i = 0; i < 4; i++) {
169 for (y = 0; y < SIZE; y++) {
170 for (x = 0; x < SIZE; x++) {
172 h +=
waves[ ((n[0] + x*STEP
173 - y*STEP2) & WAVE_MASK) + 0*WAVE_SIZE ];
174 h +=
waves[ ((n[1] + x*STEP2
175 + y*STEP) & WAVE_MASK) + 1*WAVE_SIZE ];
176 h +=
waves[ ((n[2] + x*STEP) & WAVE_MASK) + 2*WAVE_SIZE ];
177 h +=
waves[ ((n[3] + y*STEP) & WAVE_MASK) + 3*WAVE_SIZE ];
192 for (y = 0; y < SIZE; y++) {
197 for (x = 0; x < SIZE; x++) {
213 uXN = (uXN + 1) % SIZE;
218 uYN = (uYN + SIZE) % AREA;
222 for (i = 0; i < 4; i++) {
237 UINT AREA = SIZE * SIZE;
244 float* pTu = vset->
tu;
245 float* pTv = vset->
tv;
247 float fInc = 1.0f / (float) (SIZE-1);
251 for (y = 0; y < SIZE; y++) {
252 for (x = 0; x < SIZE; x++) {