void GLUI_Rotation::iaction_draw_active_area_persp( void ) { /********** arcball *******/ copy_float_array_to_ball(); setup_texture(); setup_lights(); glEnable(GL_CULL_FACE ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); mat4 tmp_rot = *ball->rot_ptr; glMultMatrixf( (float*) &tmp_rot[0][0] ); /*** Draw the checkered box ***/ /*glDisable( GL_TEXTURE_2D ); */ draw_ball(1.35); // 1.96 ); glPopMatrix(); glBindTexture(GL_TEXTURE_2D,0); /* unhook our checkerboard texture */ glDisable( GL_TEXTURE_2D ); glDisable( GL_LIGHTING ); glDisable( GL_CULL_FACE ); }
void GLUI_Rotation::iaction_draw_active_area_persp( void ) { if ( NOT can_draw() ) return; copy_float_array_to_ball(); setup_texture(); setup_lights(); glEnable(GL_CULL_FACE ); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); mat4 tmp_rot = *ball->rot_ptr; glMultMatrixf( (float*) &tmp_rot[0][0] ); /*** Draw the checkered box ***/ /*glDisable( GL_TEXTURE_2D ); */ draw_ball( 1.96 ); glPopMatrix(); glDisable( GL_TEXTURE_2D ); glDisable( GL_LIGHTING ); glDisable( GL_CULL_FACE ); }
static gint GeomDrawWireFrame(gdouble scaleBall) { int i; int j; gboolean* Ok = NULL; GList* list = NULL; if(Ncenters>0) Ok = g_malloc(Ncenters*sizeof(gboolean)); for(i = 0;i<Ncenters;i++) Ok[i] = FALSE; for(list=BondsOrb;list!=NULL;list=list->next) { BondType* data=(BondType*)list->data; i = data->n1; j = data->n2; if(!ShowHAtomOrb && (strcmp("H",GeomOrb[i].Symb)==0 || strcmp("H",GeomOrb[j].Symb)==0)) continue; if(data->bondType == GABEDIT_BONDTYPE_HYDROGEN) draw_wireframe(i,j,1); else draw_wireframe(i,j, 2); Ok[i] = TRUE; Ok[j] = TRUE; } for(i = 0;i<Ncenters;i++) { if(!ShowHAtomOrb && strcmp("H",GeomOrb[i].Symb)==0) continue; if(!Ok[i]) draw_ball(i,0.2*scaleBall); } if(Ok) g_free(Ok); glLineWidth(1); return TRUE; }
static void draw_stuff(t_game *game) { draw_board(game); draw_blocks(game); draw_ball(game); draw_score(game->score, 1.8f, -1.6f); draw_score(game->life, 0.2f, -1.6f); }
void redraw() { erase(); draw_borders(); draw_ball(); draw_users(); draw_info(); refresh(); }
static GLuint make_ball(void) { GLuint list; list = glGenLists(1); glNewList(list, GL_COMPILE); draw_ball(); glEndList(); return list; }
static void game_draw(GContext *ctx) { /* Per-frame game rendering here. */ // draw player1 last to overlap player 2 draw_ball(sg_bounds, ctx, &ball); draw_paddle(sg_bounds, ctx, &player2); draw_paddle(sg_bounds, ctx, &player1); // debug draw_debug_arc(sg_bounds, ctx, ball_traj(&ball)); }
ENTRYPOINT void draw_boing (ModeInfo *mi) { boing_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); mi->polygon_count = 0; glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (! bp->button_down_p) tick_physics (mi); glPushMatrix (); gltrackball_rotate (bp->trackball); glLightfv (GL_LIGHT0, GL_POSITION, bp->lightpos); glDisable (GL_CULL_FACE); glDisable (GL_DEPTH_TEST); glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); draw_box (mi); draw_shadow (mi); glEnable (GL_CULL_FACE); glEnable (GL_DEPTH_TEST); draw_ball (mi); if (scanlines_p) draw_scanlines (mi); glPopMatrix (); if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
static int move_tagged_balls (HDC hdc) { int x, y; for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ if (!field [x][y].tag) continue; field [x][y].frame = (field [x][y].frame + 1) % nstones; draw_ball (hdc, x, y); } return 1; }
static void ipobble_DrawScene() { char s[24]; draw_podzilla(podzilla_bmp_var); me_draw(current_angle); draw_ball(new_ball_x, new_ball_y, new_ball_type, new_ball_type); draw_ball(current_ball_x, current_ball_y, current_ball_type, current_ball_type); if(ball_firing){ /* first 'white' the ball */ GrSetGCForeground(ipobble_gc, WHITE); draw_ball(ball_x,ball_y,ball_type, -1); /* now test if bumping */ if((ball_x + (float)BALL_WIDTH) >= (float)BRD_MAXX || (ball_x - 2) <= (float)BRD_MINX) ball_vx=-ball_vx; ball_x+=ball_vx; ball_y+=ball_vy; /* now test if attaching */ /* if yes set flag to test new 4s... */ GrSetGCForeground(ipobble_gc, BLACK); draw_ball(ball_x,ball_y,ball_type, ball_type); if(test_collision()==1){ boards_ball_draw(0); test_connection(level_connection); } } else { fire_counter--; if(fire_counter * DELTA_TIME % 100 == 0) { sprintf(s, "time: %.3d", fire_counter * DELTA_TIME / 100); GrText(ipobble_wid,ipobble_gc, screen_info.cols - 50, screen_info.rows - HEADER_TOPLINE - 15, s, -1, GR_TFASCII); } if(fire_counter <= 0) do_fire(); } }
static void multi_draw_frame() { glPushMatrix(); glTranslated(-3.2f, 0.0f, -7.0f); glScalef(3.0f, 3.0f, 1.0f); glRotatef(30.0, 1.0, 0.0, 0.0); draw_field(); draw_ball(ball); draw_racket(first_player); draw_racket(second_player); glPopMatrix(); glPushMatrix(); glTranslated(3.2f, 0.0f, -7.0f); glRotatef(180.0f, 0.0f, 1.0f, 0.0f); glScalef(3.0f, 3.0f, 1.0f); glRotatef(-30.0, 1.0, 0.0, 0.0); draw_field(); draw_ball(ball); draw_racket(first_player); draw_racket(second_player); glPopMatrix(); }
static void do_fire() { fire_counter = fire_counter_start; ball_firing = 1; ball_vx = (float)sin((float)(current_angle + 180.0) / 180.0 * 3.1415); ball_vy = (float)cos((float)(current_angle + 180.0) / 180.0 * 3.1415); ball_x = current_ball_x; ball_y = current_ball_y; GrSetGCForeground(ipobble_gc, WHITE); draw_ball(new_ball_x, new_ball_y, new_ball_type,-1); draw_ball(current_ball_x, current_ball_y, current_ball_type,-1); ball_type = current_ball_type; new_ball_x = 0; new_ball_y = me_posy - 1; current_ball_type = new_ball_type; counter++; if(counter % 30 == 0) level++; new_ball_type = new_ball(level); GrSetGCForeground(ipobble_gc, BLACK); draw_ball(new_ball_x, new_ball_y, new_ball_type, new_ball_type); draw_ball(current_ball_x, current_ball_y, current_ball_type, current_ball_type); }
static void untag_all () { int x, y; for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ field [x][y].tag = 0; if (sync_stones){ field [x][y].frame = 0; draw_ball (x, y); } } }
static int move_tagged_balls (void *data) { int x, y; for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ if (!field [x][y].tag) continue; field [x][y].frame = (field [x][y].frame + 1) % nstones; draw_ball (x, y); } gdk_flush (); return 1; }
static void boards_ball_draw(int ibmp) { int i, j; int ioff, istep; for(i = 0; i < BROWS; i++) { ioff = brd_oy + i * B_LINE_HEIGHT; istep = BALL_WIDTH * (i % 2) / 2; for(j = 0; j < BCOLS; j++){ if(board[i * BCOLS + j] >= 0) draw_ball(brd_ox + j * BALL_WIDTH + istep,ioff, board[i * BCOLS + j], board[i * BCOLS +j]); } } GrSetGCForeground(ipobble_gc, WHITE); }
static void paint (GdkRectangle *area) { int x1, y1, x2, y2, x, y; x1 = area->x / STONE_SIZE; y1 = area->y / STONE_SIZE; x2 = (area->x + area->width) / STONE_SIZE; y2 = (area->y + area->height) / STONE_SIZE; for (x = x1; x <= x2; x++){ for (y = y1; y <= y2; y++){ draw_ball (x, y); } } }
static void untag_all (HWND hwnd) { int x, y; HDC hdc = GetClientDC (hwnd); for (x = 0; x < STONE_COLS; x++) for (y = 0; y < STONE_LINES; y++){ field [x][y].tag = 0; if (sync_stones && field [x][y].frame != 0) { field [x][y].frame = 0; draw_ball (hdc, x, y); } } ReleaseDC (hdc); }
END_TEST START_TEST(test_draw_ball) { char stu[2048]; char *mod = "...*...\n.*****.\n.*****.\n*******\n.*****.\n.*****.\n...*...\n"; int size = 3; freopen("mockoutput", "w", stdout); draw_ball(size); read_stdout(stu, 2048); char infostr[100] = ""; if (mycompare(stu, mod, infostr)) { fail("[Task 1.6] Called draw_ball(%d). Your output:\n%s\nReference output:\n%s\nReason: %s\n", size, stu, mod, infostr); } }
/* Redraw the ball in its current position, including copying it to the output * window. */ void redraw_ball(nbstate *state) { /* Erase the ball area to the background: */ draw_background(state, (int)state->ball.x, (int)state->ball.y, state->ball.s->w, state->ball.s->h); /* Redraw any powers we may have erased: */ redraw_powers(state, (int)state->ball.x, (int)state->ball.y, state->ball.s->w, state->ball.s->h); /* Redraw the ball: */ draw_ball(state); /* Copy it to the output window: */ draw_canvas(state, state->ball.lx, state->ball.ly, state->ball.s->w, state->ball.s->h); }
static void paint (HWND hwnd, HDC hdc) { RECT rc; int x1, y1, x2, y2, x, y; GetClientRect (hdc, &rc); x1 = rc.left / STONE_SIZE; y1 = rc.top / STONE_SIZE; x2 = rc.right / STONE_SIZE; y2 = rc.bottom / STONE_SIZE; for (x = 0; x < STONE_COLS; x++){ for (y = 0; y < STONE_LINES; y++){ draw_ball (hdc, x, y); } } }
void next_frame(int f) { if (f == 0) { for (int r = 0; r < NUM_ROWS; r++) { for (int c = 0; c < NUM_COLUMNS; c++) { set_rgb(pixels, pixel_index(r, c), (r+c)%2, (r+c)%2, 0); } } } float x = f; //sin(f/100.0)*50 + 60; float y = f; //sin(f/100.0)*50 + 60; draw_ball(x, y, 0.5, 240, 120, 0); for (int s = 0; s < NUM_SEGS; s++) { put_pixels(s, pixels + s*SEG_PIXELS*3, SEG_PIXELS); } erase_ball(x, y, 3); }
/* Move the ball to from the position specified by state->ball.lx and * state->ball.ly to state->ball.x and state->ball.y, and update the relevant * area of the output window. */ void move_ball(nbstate *state) { int x, w, y, h; /* Check that the ball really has moved: */ if(state->ball.lx == state->ball.x && state->ball.ly == state->ball.y) return; /* Calculate the position and dimensions of the rectangle which * encloses both the old ball and the new ball so we know what area * to copy to the output window later. FIXME: this is quite inefficient * when doing stuff like parking the ball, where the old ball position * could be at the other side of the screen to the place we want to * move it to. It is however OK in the common case of only moving the * ball a few pixels at a time. */ if(state->ball.x < state->ball.lx) { x = (int)state->ball.x; w = state->ball.lx - x + state->ball.s->w; } else { x = state->ball.lx; w = (int)state->ball.x - x + state->ball.s->w; } if(state->ball.y < state->ball.ly) { y = (int)state->ball.y; h = state->ball.ly - y + state->ball.s->h; } else { y = state->ball.ly; h = (int)state->ball.y - y + state->ball.s->h; } /* Draw the background where the old ball image is to erase it: */ draw_background(state, state->ball.lx, state->ball.ly, state->ball.s->w, state->ball.s->h); /* Redraw any powers that are under that position: */ redraw_powers(state, state->ball.lx, state->ball.ly, state->ball.s->w, state->ball.s->h); /* Draw the ball in the new position and update ball.lx and ball.ly: */ draw_ball(state); /* Draw the modified area of the canvas to the output window: */ draw_canvas(state, x, y, w, h); }
void VisObj::draw_selection() { float r = view_ctrl.get_eye_dist(); r *= 0.003; glDisable(GL_LIGHTING); for(auto vid : mani.vertices()) { Vec3d p = mani.pos(vid); if(vertex_selection[vid]) glColor3f(1,1,0); else glColor3f(0, 0, 0.3); glPushMatrix(); glTranslated(p[0], p[1], p[2]); glScalef(r, r, r); draw_ball(); glPopMatrix(); } glEnable(GL_LIGHTING); }
void draw_level(t_level *level) { t_list_node *cursor; t_brick *cur_brick; cursor = level->brick_list; while (cursor) { cur_brick = (t_brick *)cursor->value; if (cur_brick->val > 0) draw_brick(cur_brick); cursor = cursor->next; } update_ball(level->ball, level->brick_list); draw_ball(level->ball); update_pad(level->pad, level->ball); draw_pad(level->pad); draw_level_border(); draw_lives(level->lives); draw_score(level->score); }
void display(void) { static float angle = 0.0 ; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); gluLookAt (camera[0], camera[1], camera[2], (GLdouble) ball_position.x, 0.0, (GLdouble) ball_position.y, 0.0, 0.0, 1.0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glColorMask(1,1,1,1); glEnable(GL_LIGHTING); glEnable(GL_BLEND); draw_dirt(); glPushMatrix(); glTranslatef ( 2.0 , 0.0 , 0 ); draw_cannon(); glPopMatrix(); glPushMatrix(); glTranslatef ( ball_position.x , 0.0 , ball_position.y ); if ( ball_position.y > 1.0 ) { angle++; glRotatef (angle, 0.0f, 0.0f, 1.0f); } draw_ball() ; glPopMatrix(); glutSwapBuffers(); }
void draw_scene(void) { /* clear the screen and the depth buffer */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* reset modelview matrix */ glLoadIdentity(); /* draw the border */ draw_border(); /* draw the paddle */ draw_paddle(); draw_ball(); if(BALL_NUMBER == 2) draw_ball_2(); /* since this is double buffered, swap the * buffers to display what just got drawn */ glutSwapBuffers(); }
static gint GeomDrawBallStick(gdouble scaleBall, gdouble scaleStick) { gint i; gint j; GList* list = NULL; for(i = 0;i<Ncenters;i++) { if(!ShowHAtomOrb && strcmp("H",GeomOrb[i].Symb)==0) continue; draw_ball(i,scaleBall); } for(list=BondsOrb;list!=NULL;list=list->next) { BondType* data=(BondType*)list->data; i = data->n1; j = data->n2; if(!ShowHAtomOrb && (strcmp("H",GeomOrb[i].Symb)==0 || strcmp("H",GeomOrb[j].Symb)==0)) continue; if(data->bondType == GABEDIT_BONDTYPE_HYDROGEN) draw_hbond(i,j,1.0/10.0*scaleStick); else draw_bond(i,j,1.0/3.0*scaleStick, data->bondType); } return TRUE; }
void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); init_material(Ka, Kd, Ks, 100 * Kp, Red, Green, Blue); glTranslatef(xpos / 500.0, ypos / 500.0, zpos / 500.0); glRotatef(xangle, 1.0, 0.0, 0.0); glRotatef(yangle, 0.0, 1.0, 0.0); glRotatef(zangle, 0.0, 0.0, 1.0); draw_ball(Px, Py, Pz, Radius); init_material(Ka, Kd, Ks, 100 * Kp, bred, bgreen, bblue); draw_bat(Bx, By, Bz, Bradius, 10); draw_stick(); glFlush(); glutSwapBuffers(); }
void main_app_loop() { if (current_screen == SCREEN_GAMEPLAY) { time_now_ms = pulse_get_millis(); if (time_now_ms - time_last_box_drawn_ms >= game_speed) { score++; move_surfaces(); int this_height = ball_y; ceiling = false; if (jump_ticks > 0) { clear_ball(ball_x, ball_y); if (ball_y-15 >=2) { ball_y = ball_y - 2; jump_ticks--; } else { jump_ticks--; ceiling = true; } } else if (ball_y < SCREEN_HEIGHT-112) { if ((ball_y+1 < SCREEN_HEIGHT-112) || ((surface_start_x[6]-4 > 20) || (surface_length_x[6]+surface_start_x[6] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-96) { if ((ball_y+1 < SCREEN_HEIGHT-96) || ((surface_start_x[5]-4 > 20) || (surface_length_x[5]+surface_start_x[5] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-80) { if ((ball_y+1 < SCREEN_HEIGHT-80) || ((surface_start_x[4]-4 > 20) || (surface_length_x[4]+surface_start_x[4] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-64) { if ((ball_y+1 < SCREEN_HEIGHT-64) || ((surface_start_x[3]-4 > 20) || (surface_length_x[3]+surface_start_x[3] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-48) { if ((ball_y+1 < SCREEN_HEIGHT-48) || ((surface_start_x[2]-4 > 20) || (surface_length_x[2]+surface_start_x[2] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-32) { if ((ball_y+1 < SCREEN_HEIGHT-32) || ((surface_start_x[1]-4 > 20) || (surface_length_x[1]+surface_start_x[1] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else if (ball_y < SCREEN_HEIGHT-16) { if ((ball_y+1 < SCREEN_HEIGHT-16) || ((surface_start_x[0]-4 > 20) || (surface_length_x[0]+surface_start_x[0] < 20))) { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } } else { clear_ball(ball_x, ball_y); ball_y = ball_y + 2; } draw_ball(ball_x, ball_y, green); if ((this_height == ball_y) && (!ceiling)) { jumps_available = 2; } if (ball_y >= SCREEN_HEIGHT-1) { game_over(); } time_last_box_drawn_ms = time_now_ms; } else if (current_screen == SCREEN_CLOCK) { pulse_get_time_date(¤t_time); } } }
void handle_packet(struct packet *p){ switch(p->type){ case PKT_ANNOUNCE: if(mode == MODE_CLIENT){ if(!started){ gameid = p->gameid; struct packet join; memset((void*)&join, 0, sizeof(join)); join.gameid = gameid; join.type = PKT_JOIN; memcpy(join.c.join.nick, GLOBAL(nickname), 16); join.seq = p->seq+1; nrf_snd_pkt_crc(sizeof(join), (uint8_t *)&join); player_joined = 1; } } break; case PKT_JOIN: if(mode == MODE_SERVER){ if(!started){ if(!player_joined){ started = 1; lcdClear(); lcdPrintln("Player joined"); lcdPrintln((char *)&p->c.join.nick); lcdRefresh(); struct packet ack; memset((void*)&ack, 0, sizeof(ack)); ack.gameid = gameid; ack.type = PKT_ACK; //memcpy(ack.c.ack.nick, GLOBAL(nickname), 16); ack.seq = p->seq+1; nrf_snd_pkt_crc(sizeof(ack), (uint8_t *)&ack); player_joined = 1; delayms(1000); init(); struct packet state; memset((void*)&state, 0, sizeof(state)); state.gameid = gameid; state.type = PKT_GAMESTATE; state.c.state.score1 = player1.score; state.c.state.score2 = player2.score; state.c.state.pad1 = player1.paddle_pos; state.c.state.pad2 = player2.paddle_pos; state.c.state.ball_x = ball1.x; state.c.state.ball_y = ball1.y; state.seq = p->seq+2; nrf_snd_pkt_crc(sizeof(state), (uint8_t *)&state); } } } break; case PKT_ACK: if(mode == MODE_CLIENT){ if(!started){ started = 1; lcdClear(); lcdPrintln("Joined!"); //lcdPrintln((char *)&p->c.announce.nick); init(); lcdRefresh(); } } break; case PKT_GAMESTATE: if(mode == MODE_CLIENT){ if(started){ player1.score = p->c.state.score1; player2.score = p->c.state.score2; player1.paddle_pos = p->c.state.pad1; player2.paddle_pos = p->c.state.pad2; ball1.x = p->c.state.ball_x; ball1.y = p->c.state.ball_y; if(!check_end()){ lcdClear(); print_score(); draw_paddles(); just_draw_ball(); lcdDisplay(); struct packet move; memset((void*)&move, 0, sizeof(move)); move.gameid = gameid; move.type = PKT_MOVEMENT; move.c.movement.dir = next_move; move.seq = p->seq+1; delayms(50); nrf_snd_pkt_crc(sizeof(move), (uint8_t *)&move); latest_packet = move; next_move = DIR_STAY; receive = 1; } } } break; case PKT_MOVEMENT: if(mode == MODE_SERVER){ if(started){ if(next_move != DIR_LEFT) // Only let valid keys through move_player(&player1, next_move); if(p->c.movement.dir != DIR_RIGHT) // Only let valid keys through move_player(&player2, p->c.movement.dir); check_collision_players(); draw_ball(); lcdClear(); print_score(); //check_collision_player(&player1); //check_collision_player(&player2); draw_paddles(); just_draw_ball(); lcdDisplay(); struct packet state; memset((void*)&state, 0, sizeof(state)); state.gameid = gameid; state.type = PKT_GAMESTATE; state.c.state.score1 = player1.score; state.c.state.score2 = player2.score; state.c.state.pad1 = player1.paddle_pos; state.c.state.pad2 = player2.paddle_pos; state.c.state.ball_x = ball1.x; state.c.state.ball_y = ball1.y; state.seq = p->seq+1; delayms(50); nrf_snd_pkt_crc(sizeof(state), (uint8_t *)&state); latest_packet = state; next_move = DIR_STAY; receive = 1; check_end(); } } break; case PKT_EXIT: if(started){ if(mode == MODE_CLIENT) player2.score = MAX_POINTS; else player1.score = MAX_POINTS; check_end(); } break; } }