void *layout_new (void) { tp_layout *ret = (tp_layout*) malloc (sizeof(tp_layout)); ret->k = 1.0; ret->K1 = 0.06; ret->K2 = 0.024; ret->force = 1.0; //viewZone = 5.0; calculated by the quality level ret->theta = 0.7; ret->quality = 0; ret->nodesPerCell = 10; ret->maxTreeDepth = 100; ret->stabilizationLimit = 0.9; tp_rect universe = tp_Rect (-100, -100, 200, 200); ret->box = box_new (ret->nodesPerCell, ret->maxTreeDepth, universe); ret->nodes = dict_new (10000); layout_reset_energies (ret); layout_set_quality (ret, ret->quality); pthread_mutex_init (&mutex, NULL); return ret; }
void *rLCD(void *patcher, short x, short y, short w, short s) { ResType theType; Lcd *p; FontInfo info; p = (Lcd *)newobject(lcd_class); if (s < 1) s = 1; box_new((Box *)p, patcher, F_DRAWFIRSTIN | F_GROWBOTH, x, y, x+w,y+s); p->lcd_box.b_firstin = (void *)p; /* it's not really an inlet */ p->lcd_row = 0; p->lcd_col = 0; p->lcd_region = 0L; /* DDZ moved to prevent dispose of bad region handle (LCD_font calls LCD_resize) */ LCD_font(p,0L,0L); /* DDZ changed to add 0,0 as arguments (needed) 12/14/92 */ p->lcd_shiftClick = false; p->file_outlet=outlet_new(p,0L); p->lcd_outlet = outlet_new(p,0L); p->lcd_palette = myPalette; p->lcd_pIndex = numPaletteColors-1; p->lcd_penMode = patCopy; p->screen = 0L; p->reson_sampleRate = 20000.0; p->reson_spectScale = -100.0; p->reson_trimRatio = 1.0; p->local=1; // sde want to draw mouseclicks by default p->lcd_debug = false; p->lcd_oldRect = p->lcd_box.b_rect; /* DDZ, the statement above needs to be done in case the window is not visible, because otherwise, oldRect can be set to some huge size and erase the entire patcher window */ // sde picthandle = (PicHandle)newhandle(4L);// create a dummy so we have something to dispose pictgood=0; { GrafPort *gp; gp = patcher_setport(p->lcd_box.b_patcher); if (gp) { LCD_resize(p); SetPort(gp); } } box_ready((Box *)p); return (p); }
/**************************************************** * panel creation * ****************************************************/ static void make_round_corners(panel *p) { GtkWidget *b1, *b2, *img; GtkWidget *(*box_new) (gboolean, gint); void (*box_pack)(GtkBox *, GtkWidget *, gboolean, gboolean, guint); gchar *s1, *s2; #define IMGPREFIX PREFIX "/share/fbpanel/images/" ENTER; if (p->edge == EDGE_TOP) { s1 = IMGPREFIX "top-left.xpm"; s2 = IMGPREFIX "top-right.xpm"; } else if (p->edge == EDGE_BOTTOM) { s1 = IMGPREFIX "bottom-left.xpm"; s2 = IMGPREFIX "bottom-right.xpm"; } else if (p->edge == EDGE_LEFT) { s1 = IMGPREFIX "top-left.xpm"; s2 = IMGPREFIX "bottom-left.xpm"; } else if (p->edge == EDGE_RIGHT) { s1 = IMGPREFIX "top-right.xpm"; s2 = IMGPREFIX "bottom-right.xpm"; } else RET(); box_new = (p->orientation == ORIENT_HORIZ) ? gtk_vbox_new : gtk_hbox_new; b1 = box_new(0, FALSE); gtk_widget_show(b1); b2 = box_new(0, FALSE); gtk_widget_show(b2); box_pack = (p->edge == EDGE_TOP || p->edge == EDGE_LEFT) ? gtk_box_pack_start : gtk_box_pack_end; img = gtk_image_new_from_file(s1); gtk_widget_show(img); box_pack(GTK_BOX(b1), img, FALSE, FALSE, 0); img = gtk_image_new_from_file(s2); gtk_widget_show(img); box_pack(GTK_BOX(b2), img, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(p->lbox), b1, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(p->lbox), b2, FALSE, FALSE, 0); RET(); }
static void register_ship_gfx(void){ particle_t *p; p = particle_new(box_new(vec_new(0,0),24,32),-0.5); p->draw = particle_draw_square; p->action = trail_action; p->param[0] = 100; particle_set_color(p,1,0.1,0,0.1); particle_set_alt_color(p,1,0,0,0.2); factory_register(p,P_SHIP_TRAIL); p = particle_new(box_new(vec_new(0,0),4,4),8); p->draw = particle_draw_square; p->action = boost_action; p->param[0] = 100; particle_set_color(p,1,0.1,0,0.1); particle_set_alt_color(p,1,0,0,0.2); factory_register(p,P_SHIP_BOOST); }
static void register_ship(void){ particle_t*p; model_t *mod; material_t *mat; mod = model_load("data/ship.obj"); mat = material_new(); material_set_diffuse(mat,1,0,0,1.0); material_set_spec(mat,1,0.5,0.2,1.0); material_set_edge(mat,0.5,0,0,0.1); material_set_shininess(mat,50); material_enable(mat, DRAW_FACE | DRAW_EDGE); model_set_material(mod,1,mat); mat = material_new(); material_set_diffuse(mat,0.8,0.8,0.8,1); material_set_spec(mat,0.8,0.8,0.8,1); material_set_shininess(mat,50); material_set_edge(mat,0,0,0,0.1); material_enable(mat, DRAW_FACE | DRAW_EDGE); model_set_material(mod,0,mat); mat = material_new(); material_set_diffuse(mat,0,0,0,1); material_set_edge(mat,1,1,1,0.1); material_enable(mat, DRAW_FACE | DRAW_EDGE ); model_set_material(mod,2,mat); p = particle_new(box_new(vec_new(0,0),40,32),0); p->draw = ship_draw; p->move = particle_simple_move; p->action = ship_action; p->collide = ship_collide; p->vector[MISSILE] = vec_new(100,0); p->model[0] = mod; particle_set_color(p,1,0.3,0,0.1); particle_set_alt_color(p,1,0.5,0,0.5); particle_set_collides(p,1); particle_set_camera(p,1); particle_set_solid(p,1); particle_set_group(p,P_SHIP); particle_toggle_collide_group(p,P_SHIP); particle_toggle_collide_group(p,P_MISSILE); particle_set_nprop(p,SHIP_HSPEED,nprop_new(0,SHIP_ACCEL)); particle_set_nprop(p,SHIP_VSPEED,nprop_new(0,SHIP_ACCEL)); factory_register(p,P_SHIP); }
static void register_ship_missile(void){ particle_t *p; model_t *mod; material_t *mat; mod = model_load("data/missile.obj"); mat = material_new(); material_set_diffuse(mat,1,0,0,1.0); material_set_emit(mat,0.2,0.1,0,1.0); material_set_spec(mat,1,0.5,0.2,1.0); material_set_edge(mat,0.5,0,0,0.1); material_set_shininess(mat,50); material_enable(mat, DRAW_FACE | DRAW_EDGE); model_set_material(mod,0,mat); mat = material_new(); material_set_diffuse(mat,0.416,0.525,0.345,1); material_set_spec(mat,0.025,0.149,0,1); material_set_shininess(mat,50); material_set_edge(mat,0,0,0,0.1); material_enable(mat, DRAW_FACE | DRAW_EDGE); model_set_material(mod,1,mat); p = particle_new(box_new(vec_new(0,0),10,10),-1); particle_set_color(p,0,0.5,1,0.1); particle_set_alt_color(p,0.1,0.6,1,0.1); p->draw = missile_draw; p->move = particle_simple_move; p->collide = missile_collide; p->die = missile_die; p->action = missile_action; particle_set_group(p,P_MISSILE); particle_toggle_collide_group(p,P_SHIP); particle_toggle_collide_group(p,P_MISSILE); p->model[0] = mod; particle_set_collides(p,1); p->a = vec_new(0,0); particle_set_solid(p,0); factory_register(p,P_MISSILE); }
void do_physics(world_t *w){ int i = 0; particle_t *p = NULL; int j = 0; particle_t *q = NULL; box_t b = box_new(vec_new(0,0),10,10); vec_t d = vec_new(0,0); while((p = world_next_moving(w,&i))){ j = 0; p->move(p); if(particle_collides(p)){ while((q = world_next_solid(w,b,&j))){ if( q != p && particle_collide_with(q,p) && !vec_zero(d = box_oriented_collision(p->box,q->box)) ){ /*printf("collide\n");*/ /*d = box_oriented_collision(p->box,q->box);*/ if(d.x != 0.0){ p->v.x = - p->v.x * 0.5 ; }else{ p->v.x *= 0.3; } if(d.y != 0.0){ p->v.y = - p->v.y * 0.5 ; }else{ p->v.x *= 0.3; } if(p->collide){ p->collide(p,q); } p->box.pos = vec_add(p->box.pos,d); } } } } /*TODO collisions and damage*/ }
//GUI calls this method to try to add a new shape drawn by user cpShape *core_add_new_shape ( cpSpace *space, const int type, const double p1x, const double p1y, const double p2x, const double p2y, Color *color, const double orientation, const double friction, const double elasticity, const double density, const int index ) { //if the new shape is a circle, store the values in a circle struct, make the circle shape, and destroy the struct if ( type == CIRCLE_TYPE ) { Circle *circ = circle_new(); //set radius if ( abs ( p1x - p2x ) > abs ( p1y - p2y ) ){ circ->radius = abs ( p2y - p1y ) / 2; } else { circ->radius = abs ( p2x - p1x ) / 2; } //set centerx if ( p1x > p2x ) { circ->x = p1x - circ->radius; } else { circ->x = p1x + circ->radius; } //set centery if ( p1y > p2y ) { circ->y = p1y - circ->radius; } else { circ->y = p1y + circ->radius; } circ->color->r = color->r; circ->color->g = color->g; circ->color->b = color->b; circ->orientation = orientation; circ->friction = friction; circ->elasticity = elasticity; circ->density = density; cpShape * circ_shape = core_add_circle_shape ( space, circ, index ); circle_destroy ( circ ); return circ_shape; } //if the new shape is a box, store the values in a box struct, make the box shape, and destroy the struct if ( type == BOX_TYPE ) { Box *box = box_new(); box->x = p1x + ( p2x - p1x ) / 2; box->y = p1y + ( p2y - p1y) / 2; box->width = abs ( p2x - p1x ); box->height = abs ( p2y - p1y ); box->color->r = color->r; box->color->g = color->g; box->color->b = color->b; box->orientation = orientation; box->friction = friction; box->elasticity = elasticity; box->density = density; if ( box->width < .001 || box->height < .001 ){ box_destroy ( box ); return NULL; } cpShape *box_shape = core_add_box_shape ( space, box, index ); box_destroy ( box ); return box_shape; } return NULL; }
// core_load_level // reads contents of file, adds corresponding cpShapes to cpSpace // returns EXIT_SUCCESS if level loaded successfully // returns EXIT_FAILURE if level loaded unsuccessfully (bad syntax) static int core_load_level_parse ( cpSpace *space, FILE * fp ) { int max_line_size = 40; // maximum length of line that we want to read in // array to hold contents of each line char line [max_line_size]; char * line_place = line; // holds address of start of line fgets ( line, max_line_size, fp ); // check to see that first line has correct content if( strncmp ( line, "gravity ", 8 ) != 0 ) return EXIT_FAILURE; line_place = &line[8]; // advance line to next chars to be read double gravity = atof ( line_place ); // saves gravity input into a double core_set_gravity ( space, gravity ); // set gravity // check that next line is blank fgets ( line, max_line_size, fp ); int exit = 1; // keeps track of whether to continue reading lines while ( exit == 1 ) { if ( fgets ( line, max_line_size, fp ) == 0 ) return EXIT_SUCCESS; // get next line. If EOF, return if ( strncmp ( line, "box STATIC", 10 ) == 0 ) { // static box information to follow Box * box = box_new(); if ( parse_box ( fp, &(box->x), &(box->y), &(box->width), &(box->height), &(box->angle), (box->color), &(box->friction), &(box->elasticity), &(box->density)) == EXIT_FAILURE ) { fprintf ( stderr, "Parsing error in box STATIC\n" ); box_destroy ( box ); return EXIT_FAILURE; }; // add static box to space and destroy temporary box data core_add_static_box_shape ( space, box ); box_destroy ( box ); } else if ( strncmp ( line, "box NONSTATIC", 13 ) == 0 ) { Box * box = box_new(); if( parse_box ( fp, &(box->x), &(box->y), &(box->width), &(box->height), &(box->angle), (box->color), &(box->friction), &(box->elasticity), &(box->density) ) == EXIT_FAILURE ) { fprintf ( stderr, "Parsing error in box NONSTATIC\n" ); box_destroy ( box ); return EXIT_FAILURE; }; // need to add mass, inertia since body moves core_add_box_shape ( space, box, 0 ); box_destroy ( box ); } else if ( strncmp ( line, "ball NONSTATIC", 14 ) == 0 ) { Circle * circ = circle_new (); if ( parse_ball ( fp, &(circ->x), &(circ->y), &(circ->radius), &(circ->angle), circ->color, &(circ->friction), &(circ->elasticity), &(circ->density)) == EXIT_FAILURE ) { fprintf ( stderr, "Parsing error in ball NONSTATIC\n" ); circle_destroy ( circ ); return EXIT_FAILURE; } // need to add mass, inertia since body moves core_add_circle_shape ( space, circ, 0 ); circle_destroy ( circ ); } else if ( strncmp ( line, "ball STATIC", 11) == 0 ) { Circle * circ = circle_new(); if ( parse_ball ( fp, &(circ->x), &(circ->y), &(circ->radius), &(circ->angle), circ->color, &(circ->friction), &(circ->elasticity), &(circ->density) ) == EXIT_FAILURE ) { fprintf ( stderr, "Parsing error in ball STATIC\n" ); circle_destroy ( circ ); return EXIT_FAILURE; } core_add_static_circle_shape ( space, circ ); circle_destroy ( circ ); } else // invalid input return EXIT_FAILURE; if ( fgets ( line, max_line_size, fp ) == NULL ) exit = 0; // get next line. If EOF, get out } cpSpaceEachBody ( space, &core_update_body, (void *) NULL ); return EXIT_SUCCESS; }
// make a homebase void core_make_homebase ( cpSpace *space, const double x, const double y, const int start_index, const int planet_num){ Box *defense[4]; double r = (double)rand()/(double)RAND_MAX; double g = (double)rand()/(double)RAND_MAX; double b = (double)rand()/(double)RAND_MAX; for( int i = 0; i < 4; i++){ defense[i] = box_new(); defense[i]->color->r = r; defense[i]->color->g = g; defense[i]->color->b = b; defense[i]->orientation = 0; defense[i]->friction = 0; defense[i]->elasticity = 1; defense[i]->density = 20; defense[i]->width = SIDE_WIDTH; defense[i]->height = SIDE_HEIGHT; } defense[0]->x = x-SIDE_HEIGHT/2; defense[0]->y = y-SIDE_OFFSET; defense[1]->x = x-SIDE_OFFSET; defense[1]->y = y+SIDE_HEIGHT/2; defense[2]->x = x+SIDE_HEIGHT/2; defense[2]->y = y+SIDE_OFFSET; defense[3]->x = x+SIDE_OFFSET; defense[3]->y = y-SIDE_HEIGHT/2; cpShape *side; BodyInfo *sidebi; for(int i = 0; i< 4; i++){ side = core_add_box_shape (space, defense[i], start_index+i); cpBodySetAngle(side->body, PI*i/2); sidebi = (BodyInfo *) (side->body->data); sidebi->space_shape_type = -1; // make it so sides don't timeout } for(int i = 0; i< 4; i++){ box_destroy (defense[i]); } Circle *planet; planet = circle_new(); planet->color->r = r; planet->color->g = g; planet->color->b = b; planet->orientation = 0; planet->friction = 0; planet->elasticity = 1; planet->density = 200; planet->radius = CORE_RADIUS; planet->x = x; planet->y = y; cpShape *core = core_add_circle_shape (space, planet, start_index+4); cpShapeSetCollisionType ( core, GOAL_COLLISION_TYPE ); //pjw midnite DrawShapeInfo *info = (DrawShapeInfo *)cpShapeGetUserData(core); info->originx = x; info->originy = y; BodyInfo *bi = (BodyInfo *)core->body->data; bi->originx = x; bi->originy = y; bi->space_shape_type = planet_num; info->space_shape_type = planet_num; circle_destroy (planet); }