Exemplo n.º 1
0
static void post_step_body_replace_shapes(cpSpace *space, cpBody *body, void *data) {
	
	Body_data *pa = cpBodyGetUserData(body);
    
    int length = pa->x_values->len;

	cpBodyEachShape(body, (cpBodyShapeIteratorFunc) free_shape, NULL);

	cpSpaceReindexShapesForBody(space, body);
	//fprintf(stderr, "0Made it this far.\n");
	for (int index = 1; index < length; index++) {
		cpFloat x = g_array_index(pa->x_values, cpFloat, index);
        cpFloat y = g_array_index(pa->y_values, cpFloat, index);
		
		cpShape *seg = cpSegmentShapeNew(body, cpv(x,y), cpv(g_array_index(pa->x_values, cpFloat, index - 1), g_array_index(pa->y_values, cpFloat, index - 1)), CRAYON_RADIUS);
		//fprintf(stderr, "1Made it this far.\n");
		cpShapeSetFriction(seg, CRAYON_FRICTION);
		//fprintf(stderr, "2Made it this far.\n");
		//cpShapeSetElasticity(cpShape *shape, cpFloat value)?
		cpSpaceAddShape(space, seg);
		//fprintf(stderr, "3Made it this far.\n");
	}

	cpSpaceReindexShapesForBody(space, body);
}
Exemplo n.º 2
0
void render_objects()
{
	int i;
	for(i=0; i<1; i++) {
		cpBodyEachShape(tire[i], draw_shape, NULL);
	}
}
Exemplo n.º 3
0
ETERM *space_remove_body(ETERM *fromp, ETERM *argp) {

    // get the args
    ETERM *space_refp = erl_element(1, argp);
    ETERM *idp = erl_element(2, argp);

    erlmunk_space *s;
    int space_id = ERL_REF_NUMBER(space_refp);
    HASH_FIND_INT(erlmunk_spaces, &space_id, s);

    int body_id = ERL_INT_VALUE(idp);
    erlmunk_body *b = NULL;
    HASH_FIND_INT(s->bodies, &body_id, b);
    if (b == NULL)
        return NULL;

    // DEBUGF(("removing body #%d\n", body_id));

    // remove the user data associated with the body
    erlmunk_body_data *data = cpBodyGetUserData(b->body);
    if (data->term != NULL)
        erl_free_compound(data->term);
    free(data);

    cpBodyEachShape(b->body, shapeRemove, NULL);
    cpSpaceRemoveBody(s->space, b->body);

    space_remove_body_hash(s, b);

    cpBodyDestroy(b->body);
    cpBodyFree(b->body);

    return NULL;
}
Exemplo n.º 4
0
// poststep functions to add and remove bodies 
void postStepRemoveBody ( cpSpace *space, cpBody *body, void *unused ) {
    
    cpBodyEachShape ( body, (cpBodyShapeIteratorFunc)core_destroy_out_shapes, space );
    
    cpSpaceRemoveBody ( space, body );
    core_destroy_body ( body, NULL );
}
Exemplo n.º 5
0
void
classdef_circularBody_finalize(JSContext* cx, JSObject* sp) {
  cpBody* body = (cpBody*)JS_GetPrivate(cx, sp);
  printf("About to try and delete a cpBody and, its cpConstraints and its cpShapes...\n");
  cpBodyEachShape(body, &removeShapeFromBodyIterator, 0);
  cpBodyEachConstraint(body, &removeConstraintFromBodyIterator, 0);
  cpBodyFree(body);
}
Exemplo n.º 6
0
void free_body_full(cpBody *body) {
    cpBodyEachShape(body, (cpBodyShapeIteratorFunc) free_shape, NULL);
    
    point_array_free( (Body_data *) cpBodyGetUserData(body) );
	cpSpace *space = cpBodyGetSpace(body);
	cpSpaceRemoveBody(space, body);
	cpBodyDestroy(body);
    cpBodyFree(body);
}
Exemplo n.º 7
0
void initialize_player(struct obj *self)
{
        Mix_Chunk *sound = load_sound("electric_1.wav");
        CHECK_EXTRA_STRUCT(self,sizeof(struct player_extra), struct player_extra, .keystate = SDL_GetKeyboardState(NULL), .gunSound = sound);


    cpBodyEachShape(self->body, shape_set_collision_type, CT_PLAYER);

    printf("old volume: %d", sound, -1);
    self->room->viewport.focus = self->body;
    self->room->viewport.focusLast = cpBodyGetPosition(self->body);
}
Exemplo n.º 8
0
void Renderer::createDebugTumbler(cpBody* body, const sf::Vector2u& tumblerSize,
                                  std::vector<SpritePiece>* pieces) {
  mTargetSize = tumblerSize;
  initTargets();

  cpBodyEachShape(body, [](cpBody* body, cpShape* shape, void* data) {
    auto type = reinterpret_cast<ShapeType*>(cpShapeGetUserData(shape));
    if (*type != ShapeType::Segment) return;

    reinterpret_cast<Renderer*>(data)->drawBar(shape);
  }, this);

  createPieces(pieces);
}
Exemplo n.º 9
0
void free_body_full(cpBody *body) {
    cpBodyEachShape(body, (cpBodyShapeIteratorFunc) free_shape, NULL);
    
    point_array_free( (Point_array *) cpBodyGetUserData(body) );
    cpBodyFree(body);
}
Exemplo n.º 10
0
void cBody::EachShape( ShapeIteratorFunc Func, void * data ) {
	cShapeIterator it( this, data, Func );
	cpBodyEachShape( mBody, &BodyShapeIteratorFunc, (void*)&it );
}
Exemplo n.º 11
0
void BlockRemove(Block *block)
{
	cpBodyEachShape(block->Body, RemoveShape, space.Space);
	cpSpaceRemoveBody(space.Space, block->Body);
}
Exemplo n.º 12
0
__declspec( dllexport ) void deletevar( const void * _in, int in_size, void * _out, int out_sz )
{
	cpBody *body;
	int i;
	int index;
	Variable *var;
	Variable *mainVar = vhRemoveVariable(&mVariableHandler,PEEKINT(INPUT_MEMBLOCK,0));
	
	if (mainVar->mType == VarTypeBody)
	{
		body = (cpBody*)mainVar->mPtr;
		resetVariableList();
		cpBodyEachShape(body,listShape,0);
		index = 0;
		for (i = 0;i != mVariableListIterator;i++)
		{
			var = mVariableList[i];
			
			POKEINT(OUTPUT_MEMBLOCK,index,var->mCBPtr);index += 4;
			
			cpSpaceRemoveShape(&mSpace,(cpShape*)var->mPtr);
			cpShapeFree((cpShape*)var->mPtr);
			//MessageBoxA(NULL,"ShapeRemoved2","Error",MB_OK);

			vhRemoveVariable(&mVariableHandler,var->mLocalHandle);
			varFree(var);
		}

		resetVariableList();
		cpBodyEachConstraint(body,listConstraint,0);
		for (i = 0;i != mVariableListIterator;i++)
		{
			var = mVariableList[i];
			POKEINT(OUTPUT_MEMBLOCK,index,var->mCBPtr);index+=4;
			//MessageBoxA(NULL,"Constraint removed2","Error",MB_OK);
			cpSpaceRemoveConstraint(&mSpace,(cpConstraint*)var->mPtr);
			cpConstraintFree((cpConstraint*)var->mPtr);
			vhRemoveVariable(&mVariableHandler,var->mLocalHandle);
			varFree(var);
		}
		POKEINT(OUTPUT_MEMBLOCK,index,0);//End point
		//MessageBoxA(NULL,"BodyRemoved","Error",MB_OK);
		cpSpaceRemoveBody(&mSpace,body);
		cpBodyFree(body);
		varFree(mainVar);
	}
	else if (mainVar->mType == VarTypeShape)
	{
		cpSpaceRemoveShape(&mSpace,(cpShape*)mainVar->mPtr);
		cpShapeFree((cpShape*)mainVar->mPtr);
		//MessageBoxA(NULL,"ShapeRemoved","Error",MB_OK);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else if (mainVar->mType == VarTypeConstraint)
	{
		cpSpaceRemoveConstraint(&mSpace,(cpConstraint*)mainVar->mPtr);
		cpConstraintFree((cpConstraint*)mainVar->mPtr);
		varFree(mainVar);

		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else if (mainVar->mType == VarTypeDataArray)
	{
		daFree((DataArray*)mainVar->mPtr);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else
	{
		//Failure...
		MessageBoxA(NULL,"Unknown cpChipmunk error 11","Error",MB_OK);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
		
	}
	
}
Exemplo n.º 13
0
// updates x and y coordinates of each shape attahced to a body
static void core_update_body ( cpBody * body, void *data ) {
    
    cpVect pos = cpBodyGetPos ( body );
    cpBodyEachShape ( body, &core_update_shape, (void *) &pos );
    
}
Exemplo n.º 14
0
void Body::eachShape(BodyShapeIteratorFunc func)
{
		cpBodyEachShape(body,*BodyEachShape,&func);
}
Exemplo n.º 15
0
void Body::eachShape(cpBodyShapeIteratorFunc func,void *data)
{
		cpBodyEachShape(body,func,data);
}