| 4660 | #define random2(i) (((i * i) & 65535) >> 2) |
| 4661 | |
| 4662 | static void C_Noise( |
| 4663 | long u_init, |
| 4664 | long v_init, |
| 4665 | long du, |
| 4666 | long dv, |
| 4667 | long ddu, |
| 4668 | long ddv, |
| 4669 | unsigned char *screen_buffer, |
| 4670 | unsigned int count) |
| 4671 | { |
| 4672 | unsigned char color; |
| 4673 | unsigned char bx0, bx1, by0, by1; |
| 4674 | unsigned char rx0, ry0; |
| 4675 | |
| 4676 | // Original Perlin's noise program used an array g[512][2]. |
| 4677 | // This program replaces the array with real-time calculations. |
| 4678 | // The results are stored into variables of the form g_b##_#. |
| 4679 | |
| 4680 | short g_b00_0; // Used to replace array g[b00][0] |
| 4681 | short g_b00_1; // Used to replace array g[b00][1] |
| 4682 | short g_b01_0; // replaces array g[b01][0] |
| 4683 | short g_b01_1; // replaces array g[b01][1] |
| 4684 | short g_b10_0; // replaces array g[b10][0] |
| 4685 | short g_b10_1; // replaces array g[b10][1] |
| 4686 | short g_b11_0; // replaces array g[b11][0] |
| 4687 | short g_b11_1; // replaces array g[b11][1] |
| 4688 | |
| 4689 | // Used to replace array: b00 = p[p[bx0] + by0]; |
| 4690 | short b00; |
| 4691 | short b01; |
| 4692 | short b10; |
| 4693 | short b11; |
| 4694 | |
| 4695 | unsigned short i; |
| 4696 | unsigned short u_16bit, v_16bit; |
| 4697 | signed short rx1, ry1; |
| 4698 | signed short sx, sy; |
| 4699 | signed long color_p0, color_p1, color_p2, color_p3; |
| 4700 | signed long color_y0, color_y1; |
| 4701 | |
| 4702 | // Inner loop for the scan line. "count" pixels will be drawn. |
| 4703 | for (i = 0; i < count; i++) { |
| 4704 | // Convert the u and v parameters from 10.22 to 8.8 format. |
| 4705 | u_16bit = (short)(u_init >> 14); |
| 4706 | v_16bit = (short)(v_init >> 14); |
| 4707 | |
| 4708 | // Imagine having a square of the type |
| 4709 | // p0---p1 Where p0 = (bx0, by0) +----> U |
| 4710 | // |(u,v)| p1 = (bx1, by0) | |
| 4711 | // | | p2 = (bx0, by1) | Coordinate System |
| 4712 | // p2---p3 p3 = (bx1, by1) V |
| 4713 | // The u, v point in 2D texture space is bounded by this rectangle. |
| 4714 | |
| 4715 | // Goal: determine the color of the points p0, p1, p2, p3. |
| 4716 | // Then the color of the point (u, v) will be found by linear interpolation. |
| 4717 | |
| 4718 | // First step: Get the 2D coordinates of the points p0, p1, p2, p3. |
| 4719 | |