void moveGenerator(){ int i; int j; for(j=0;j<100;j++){ for(i=0;i<GENERATOR_MAX;i++){ FixedPoint angle = FloatToFix((float)(rand()) / RAND_MAX); FixedPoint speed = ((float)(rand()) / RAND_MAX)*4; if(makeBullet(Gen[i].pt.x, Gen[i].pt.y, (FixedPoint)INT_cos(angle)*speed, (FixedPoint)INT_sin(angle)*speed) < 0){ return; } /* if(makeBullet(Gen[i].pt.x, Gen[i].pt.y, (FixedPoint)INT_cos(Gen[i].angle), (FixedPoint)INT_sin(Gen[i].angle)) < 0){ return; } Gen[i].angle++; Gen[i].angle %= ANGLE_MAX; */ GLint vertex[8]; GLint x = FixToInt(Gen[i].pt.x); GLint y = FixToInt(Gen[i].pt.y); glEnableClientState( GL_VERTEX_ARRAY ); glVertexPointer( 2, GL_INT, 0, vertex ); vertex[0] = x-3; vertex[1] = y-3; vertex[2] = x-3; vertex[3] = y+3; vertex[4] = x+3; vertex[5] = y+3; vertex[6] = x+3; vertex[7] = y-3; glColor4fv(GEN_COLOR); glDrawArrays( GL_QUADS, 0, 4 ); } } }
int main(int argc, char **argv) { int num_degrees, angle; FILE *headerfile, *tablefile; double radians; fix result; char tempbuf[512], *dir; int viewer_distance, maxx; if (argc != 2) usage(); dir = argv[1]; num_degrees = NUMDEGREES; maxx = MAXX; viewer_distance = VIEWER_DISTANCE; /* First spew the header file */ sprintf(tempbuf, "%s\\%s", dir, header_file); headerfile = fopen(tempbuf, "wt"); if (headerfile == NULL) file_error(); fprintf(headerfile, "/*\n"); fprintf(headerfile, " * %s: Header file for trig tables.\n", header_file); fprintf(headerfile, " * This file was automatically generated by %s.\n", progname); fprintf(headerfile, " */\n\n"); fprintf(headerfile, "#ifndef _TRIG_H\n"); fprintf(headerfile, "#define _TRIG_H\n\n"); fprintf(headerfile, "#define NUMDEGREES %d\n", num_degrees); fprintf(headerfile, "#define LOG_NUMDEGREES %d\n", discrete_log(num_degrees)); fprintf(headerfile, "#define COS(x) (cos_table[x & (NUMDEGREES - 1)])\n"); fprintf(headerfile, "#define SIN(x) (sin_table[x & (NUMDEGREES - 1)])\n"); // fprintf(headerfile, "#define TAN(x) (tan_table[x & (NUMDEGREES - 1)])\n"); // fprintf(headerfile, "#define COT(x) (cot_table[x & (NUMDEGREES - 1)])\n"); fprintf(headerfile, "\n"); fprintf(headerfile, "extern long cos_table[NUMDEGREES];\n"); fprintf(headerfile, "extern long sin_table[NUMDEGREES];\n"); // fprintf(headerfile, "extern long tan_table[NUMDEGREES];\n"); // fprintf(headerfile, "extern long cot_table[NUMDEGREES];\n"); // fprintf(headerfile, "extern long atan_table[%d];\n", maxx); fprintf(headerfile, "\n#endif /* ifndef _TRIG_H */\n"); fclose(headerfile); /* Now write out the tables themselves */ sprintf(tempbuf, "%s\\%s", dir, table_file); tablefile = fopen(tempbuf, "wt"); if (tablefile == NULL) file_error(); fprintf(tablefile, "/*\n"); fprintf(tablefile, " * %s: Trig tables.\n", table_file); fprintf(tablefile, " * This file was automatically generated by %s.\n", progname); fprintf(tablefile, " */\n"); fprintf(tablefile, "#include \"client.h\"\n\n"); /* cosine table */ fprintf(tablefile, "long cos_table[%d] = {\n", num_degrees); for (angle = 0; angle < num_degrees; angle++) { radians = (double) angle * PITWICE / num_degrees; result = FloatToFix(cos(radians)); fprintf(tablefile, "0x%8.8x, ", result); if (angle % 4 == 3) fprintf(tablefile, "\n"); } fprintf(tablefile, "\n};\n\n"); /* sine table */ fprintf(tablefile, "long sin_table[%d] = {\n", num_degrees); for (angle = 0; angle < num_degrees; angle++) { radians = (double) angle * PITWICE / num_degrees; result = FloatToFix(sin(radians)); fprintf(tablefile, "0x%8.8x, ", result); if (angle % 4 == 3) fprintf(tablefile, "\n"); } fprintf(tablefile, "\n};\n\n"); // Tangent and cotangent tables no longer needed 9/95 ARK // Arctangent table no longer needed 12/95 ARK #if 0 /* tangent table */ fprintf(tablefile, "long tan_table[%d] = {\n", num_degrees); for (angle = 0; angle < num_degrees; angle++) { radians = (double) angle * PITWICE / num_degrees; /* Watch out for pi/2 and -pi/2 */ if (angle == num_degrees / 4) result = BIGFIXINT; else if (angle == num_degrees / 4 * 3) result = -BIGFIXINT; else result = FloatToFix(tan(radians)); if (result > BIGFIXINT) result = BIGFIXINT; if (result < -BIGFIXINT) result = -BIGFIXINT; fprintf(tablefile, "0x%8.8x, ", result); if (angle % 4 == 3) fprintf(tablefile, "\n"); } fprintf(tablefile, "\n};\n\n"); /* cotangent table */ fprintf(tablefile, "long cot_table[%d] = {\n", num_degrees); for (angle = 0; angle < num_degrees; angle++) { radians = (double) angle * PITWICE / num_degrees; /* Watch out for 0 and pi */ if (angle == 0) result = BIGFIXINT; else if (angle == num_degrees / 2) result = BIGFIXINT; else result = FloatToFix(1.0 / tan(radians)); if (result > BIGFIXINT) result = BIGFIXINT; if (result < -BIGFIXINT) result = -BIGFIXINT; fprintf(tablefile, "0x%8.8x, ", result); if (angle % 4 == 3) fprintf(tablefile, "\n"); } fprintf(tablefile, "\n};\n\n"); /* Arctangent table */ fprintf(tablefile, "long atan_table[%d] = {\n", maxx); for (i = 0; i < maxx; i++) { radians = atan(((double)(i - maxx / 2)) / viewer_distance); /* Convert radians to pseudodegrees */ result = (long) ((radians * num_degrees) / PITWICE); if (result < 0) result += num_degrees; fprintf(tablefile, "%4d, ", result); if (i % 8 == 7) fprintf(tablefile, "\n"); } fprintf(tablefile, "\n};\n\n"); fclose(tablefile); #endif return 0; }