static void game_draw_balls(struct s_rend *rend, const struct s_vary *vary, const float *bill_M, float t) { float c[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; float ball_M[16]; float pend_M[16]; m_basis(ball_M, vary->uv[0].e[0], vary->uv[0].e[1], vary->uv[0].e[2]); m_basis(pend_M, vary->uv[0].E[0], vary->uv[0].E[1], vary->uv[0].E[2]); glPushMatrix(); { glTranslatef(vary->uv[0].p[0], vary->uv[0].p[1] + BALL_FUDGE, vary->uv[0].p[2]); glScalef(vary->uv[0].r, vary->uv[0].r, vary->uv[0].r); glColor4f(c[0], c[1], c[2], c[3]); ball_draw(rend, ball_M, pend_M, bill_M, t); } glPopMatrix(); }
void game_tick(Game *game) { int ch = 0, move_result = BALL_MOVED; long elapsed = elapsed_since(&game->start_time); static long last_event = 0; if ((elapsed - last_event) >= (BALL_DELAY * MICROSECONDS_PER_SECOND)) { move_result = ball_move(game->ball, game->field, game->player); if (move_result == BALL_SCORE) { game->player->score += 1; } else if (move_result == BALL_MISS) { game->player->score = 0; ball_reset(game->ball, game->field); } last_event = elapsed; } if ((ch = getch()) != ERR) { if (ch == MOVE_UP) { player_move(game->field, game->player, -1); } if (ch == MOVE_DOWN) { player_move(game->field, game->player, 1); } } // field_refresh(game->field); field_redraw(game->field); wclear(game->field->game); field_draw_score(game->field, game->player); wrefresh(game->field->score); player_draw(game->player, game->field); ball_draw(game->ball, game->field); wrefresh(game->field->game); }
void display() { const int win_width = glutGet(GLUT_WINDOW_WIDTH); const int win_height = glutGet(GLUT_WINDOW_HEIGHT); const float win_aspect = (float)win_width / (float)win_height; glViewport(0, 0, win_width, win_height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(win_aspect > RATIO) { glOrtho(-win_aspect, win_aspect, -1., 1., -1., 1.); } else { glOrtho(-RATIO, RATIO, -RATIO/win_aspect, RATIO/win_aspect, -1., 1.); } glMatrixMode(GL_MODELVIEW); glClearColor(0., 0., 1., 1.); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glColor3f(1,1,1); glVertex2f(-RATIO, -1); glVertex2f(RATIO, -1); glVertex2f(RATIO, 1); glVertex2f(-RATIO, 1); glEnd(); draw_bricks(); paddle_draw(); ball_draw(); glutSwapBuffers(); // GLUT doesn't offer cross plattform timing // assume 60Hz refresh rate T_last_frame = 1./60.; }
static void game_draw_balls(const struct s_file *fp) { float c[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; float M[16]; m_basis(M, fp->uv[0].e[0], fp->uv[0].e[1], fp->uv[0].e[2]); glPushMatrix(); { glTranslatef(fp->uv[0].p[0], fp->uv[0].p[1] + BALL_FUDGE, fp->uv[0].p[2]); glMultMatrixf(M); glScalef(fp->uv[0].r, fp->uv[0].r, fp->uv[0].r); glColor4fv(c); ball_draw(); } glPopMatrix(); }
void test_perm(int N, int NN, unsigned int M) { int j; unsigned long i; double sum2 = 0; Array<long> count(0,NN-1); // count number of times each ball is drawn Array<int> last(0,NN-1); // details of last draw long consec = 0; // count number of consecutive balls last = 0; count = 0; // set the arrays to zero cout << endl; cout << "Size of urn = " << NN << "; "; cout << "no. of balls = " << N << "; "; cout << "no. of trials = " << M << endl; cout << BaseTest::Header << endl; if (N > NN) { Throw(Runtime_error("N > NN")); } long double S0 = 0.0; // sum of ball numbers long double S1 = 0.0; // sum of ball * draw double centre = (NN+1) / 2.0; // average ball number double avj = (N+1)/2.0; // average draw number Array2<int> table1(0,NN-1,0,N-1); // times ball i occurs at draw j Array2<int> table2(0,NN-1,0,NN-1); // times ball i and ball j both occur table1 = 0; table2 = 0; // clear the tables long turnings = 0; // number of turning points RandomPermutation RP; // reset the Urn Array<int> Draw(0,N-1); // for the draw for (i=1; i<=M; i++) // iterate over total number of trials { int last_ball = -1; RP.Next(NN,N,Draw.base(),1); // do the draw Array<int> check(0,NN-1); check = 0; // for checking no repeats for (j = 1; j <= N; j++) // N balls in draw { int x = Draw(j-1); if (x<1 || x>NN) Throw(Runtime_error("Invalid number")); check(x-1)++; count(x-1)++; sum2 += last(x-1); if (x == last_ball+1 || x == last_ball-1) consec++; last_ball = x; double xc = x - centre; S0 += xc; S1 += xc * (j-avj); table1(x-1,j-1)++; } for (j=0; j<NN; j++) { if (check(j) > 1) Throw(Runtime_error("Repeated number")); last(j) = check(j); if (check(j)) // increment table of pairs { for (int k = j+1; k<NN; k++) if (check(k)) table2(j,k)++; } } // count number of turnings for (j = 2; j < N; j++) { long last = Draw(j-2); long current = Draw(j-1); long next = Draw(j); if ( (last < current && next < current) || (last > current && next > current) ) turnings++; } } // do the tests double sum1 = 0.0; double d = M * (N / (double)NN); for (j=0; j<NN; j++) { sum1 += square(count(j) - d); } if (N < NN) { sum1 /= d; double sd = (NN - N) * sqrt( 2 * (M - 1) / (M * ((double)(NN - 1))) ); NormalTestTwoSided freq_test("Ball freq.", sum1, NN - N, square(sd)); freq_test.DoTest(); NormalTestTwoSided repeats_test("Repeats", sum2, (M - 1) * (N * N / (double)NN), square((double)(N * (NN - N)) / (double)NN) * (M - 1) / (NN - 1) ); repeats_test.DoTest(); double V0 = ((double)N * (NN+1.0) * (NN-N))/12.0; NormalTestTwoSided average_test("Average", S0, 0, M * V0); average_test.DoTest(); } if (N > 1) { double V1 = (double)N * (N*N - 1) * NN * (NN + 1) / 144.0; NormalTestTwoSided ball_times_draw("Ball * draw", S1, 0, M * V1); ball_times_draw.DoTest(); double e = 2 * M * (N - 1) / (double)NN; // expected # of consecutive balls NormalTestTwoSided consec_test("Consec balls", consec, e, e); consec_test.DoTest(); } if (N > 1) { // balls vs draws double CS = 0; double ev = (double)M / NN; for (int i = 0; i < NN; i++) for (int j = 0; j < N; j++) CS += square(table1(i,j)-ev); CS /= ev; ev = N * (NN - 1); double v = 2.0 * N * (M - 1) * (N - (2 - NN) * NN) / M / (NN - 1); NormalTestTwoSided ball_draw("Ball vs draw", CS, ev, v); ball_draw.DoTest(); } if (N>1 && N < NN) { // pairs of balls double CS = 0; double ev = (double)M*N*(N-1)/ NN / (NN-1); for (int i = 0; i < NN; i++) for (int j = i+1; j < NN; j++) CS += square(table2(i,j)-ev); CS /= ev; ev = (NN-N)*(NN+N-1)/2.0; double v = (double)(M-1)*square(NN-N)*(-3+6*N-3.0*N*N+2*NN-6.0*N*NN+ 2.0*N*N*NN+NN*NN)/(M*(NN-2)*(NN-3)); NormalTestTwoSided pairs_test("Pairs table", CS, ev, v); pairs_test.DoTest(); } if (N > 2) { double V2 = (16.0 * N - 29.0) / 90.0; NormalTestTwoSided runs_test("Runs test", turnings, (double)M * (N-2) / 1.5, M * V2); runs_test.DoTest(); } }
static void game_draw_balls(struct s_rend *rend, const struct s_vary *fp, const float *bill_M, float t) { static const GLfloat color[5][4] = { { 1.0f, 1.0f, 1.0f, 0.7f }, { 1.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f, 1.0f }, }; int ui; sol_color_mtrl(rend, 1); for (ui = curr_party(); ui > 0; ui--) { if (ui == ball) { float ball_M[16]; float pend_M[16]; m_basis(ball_M, fp->uv[ui].e[0], fp->uv[ui].e[1], fp->uv[ui].e[2]); m_basis(pend_M, fp->uv[ui].E[0], fp->uv[ui].E[1], fp->uv[ui].E[2]); glPushMatrix(); { glTranslatef(fp->uv[ui].p[0], fp->uv[ui].p[1] + BALL_FUDGE, fp->uv[ui].p[2]); glScalef(fp->uv[ui].r, fp->uv[ui].r, fp->uv[ui].r); glColor4f(color[ui][0], color[ui][1], color[ui][2], color[ui][3]); ball_draw(rend, ball_M, pend_M, bill_M, t); } glPopMatrix(); } else { glPushMatrix(); { glTranslatef(fp->uv[ui].p[0], fp->uv[ui].p[1] - fp->uv[ui].r + BALL_FUDGE, fp->uv[ui].p[2]); glScalef(fp->uv[ui].r, fp->uv[ui].r, fp->uv[ui].r); glColor4f(color[ui][0], color[ui][1], color[ui][2], 0.5f); mark_draw(rend); } glPopMatrix(); } } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); sol_color_mtrl(rend, 0); }
static void game_draw_balls(const struct s_file *fp, const float *bill_M, float t) { static const GLfloat color[5][4] = { { 1.0f, 1.0f, 1.0f, 0.7f }, { 1.0f, 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, { 1.0f, 1.0f, 0.0f, 1.0f }, }; int ui; for (ui = curr_party(); ui > 0; ui--) { if (ui == ball) { float ball_M[16]; float pend_M[16]; m_basis(ball_M, fp->uv[ui].e[0], fp->uv[ui].e[1], fp->uv[ui].e[2]); m_basis(pend_M, fp->uv[ui].E[0], fp->uv[ui].E[1], fp->uv[ui].E[2]); glPushMatrix(); { glTranslatef(fp->uv[ui].p[0], fp->uv[ui].p[1] + BALL_FUDGE, fp->uv[ui].p[2]); glScalef(fp->uv[ui].r, fp->uv[ui].r, fp->uv[ui].r); glEnable(GL_COLOR_MATERIAL); glColor4fv(color[ui]); ball_draw(ball_M, pend_M, bill_M, t); glDisable(GL_COLOR_MATERIAL); } glPopMatrix(); } else { glPushMatrix(); { glTranslatef(fp->uv[ui].p[0], fp->uv[ui].p[1] - fp->uv[ui].r + BALL_FUDGE, fp->uv[ui].p[2]); glScalef(fp->uv[ui].r, fp->uv[ui].r, fp->uv[ui].r); glColor4f(color[ui][0], color[ui][1], color[ui][2], 0.5f); mark_draw(); } glPopMatrix(); } } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); }