+ /* Insert a new sprite */
+ if (pointSpriteCount >= MAX_POINT_SPRITES) {
+ printf("PROBLEM");
+ return;
+ }
+ pointSprites[pointSpriteCount++] = PACK_POINT_SPRITE(mx, my, mc);
+
+ srand(seed);
+
+ thunder(x0, y0, mx, my, c0, mc, rand(), randomness >> 1, depth-1);
+ thunder(mx, my, x1, y1, mc, c1, rand(), randomness >> 1, depth - 1);
+}
+
+MyVertex randomVertex() {
+ MyVertex ret;
+ float l;
+
+ ret.x = rand() % 200 - 100; if (ret.x == 0) ret.x = 1;
+ ret.y = rand() % 200 - 100; if (ret.y == 0) ret.y = 1;
+ ret.z = rand() % 200 - 100; if (ret.z == 0) ret.z = 1;
+
+ // Normalize
+ l = sqrt(ret.x * ret.x + ret.y * ret.y + ret.z * ret.z);
+ ret.x /= l;
+ ret.y /= l;
+ ret.z /= l;
+
+ return ret;
+}
+
+void initMesh() {
+ int i;
+
+ srand(MESH_RANDOM_SEED);
+
+ for (i = 0; i < VERTEX_COUNT; i++) {
+ vertexBuffer[i] = randomVertex();
+ }
+}
+
+void animateMesh() {
+ int i = 0;
+ MyVertex bx, by, bz;
+ float yRot;
+
+ yRot = ROTATION_SPEED * time_msec / 1000.0f;
+
+ /* Create rotated basis */
+ bx.x = cos(yRot);
+ bx.y = 0.0f;
+ bx.z = sin(yRot);
+
+ by.x = 0.0f;
+ by.y = 1.0f;
+ by.z = 0.0f;
+
+ bz.x = cos(yRot + M_PI/2.0f);
+ bz.y = 0.0f;
+ bz.z = sin(yRot + M_PI/2.0f);
+
+ for (i = 0; i < VERTEX_COUNT; i++) {
+ MyVertex v1, v2;
+ v1 = vertexBuffer[i];
+
+
+ v1.y *= sin(time_msec / 1000.0f + v1.x + v1.z);
+
+ /* O re panaia mou */
+ v2.x = v1.x * bx.x + v1.y * by.x + v1.z * bz.x;
+ v2.y = v1.x * bx.y + v1.y * by.y + v1.z * bz.y;
+ v2.z = v1.x * bx.z + v1.y * by.z + v1.z * bz.z;
+
+ v2.z += CAMERA_DISTANCE;
+
+ vertexBufferAnimated[i] = v2;
+ }
+}
+
+void projectMesh() {
+ int i = 0;
+
+ for (i = 0; i < VERTEX_COUNT; i++) {
+
+ if (vertexBufferAnimated[i].z <= NEAR_PLANE) {
+ vertexBufferProjected[i].x = vertexBufferProjected[i].y = 1000.0f;
+ vertexBufferProjected[i].z = -1.0f;
+ continue;
+ }
+
+ vertexBufferProjected[i].x = vertexBufferAnimated[i].x * PERSPECTIVE_NEUTRAL_DEPTH / vertexBufferAnimated[i].z;
+ vertexBufferProjected[i].y = vertexBufferAnimated[i].y * PERSPECTIVE_NEUTRAL_DEPTH / vertexBufferAnimated[i].z;
+ }
+}
+
+void renderMeshToPointSprites(int seed) {
+ int vertex, j;
+ int sx, sy;
+ unsigned char color;
+ unsigned char *dst;
+ unsigned char fogAtOrigin;
+
+ fogAtOrigin = fog(CAMERA_DISTANCE);
+
+ pointSpriteCount = 0;