コード例 #1
0
MachineSystem::MachineSystem(int width, int height, int hPegs, int vPegs, cpVect position)
: parts(hPegs*vPegs),
  attachments((hPegs*vPegs), std::vector<Attachment *>(hPegs*vPegs, NULL)),
  space(cpSpaceNew()),
  nMachines(0),
  nAttachments(0)
{
    cpSpaceSetIterations(space, 20);
    gridSpacing = cpv((float)width/(hPegs + 1), (float)height/(vPegs + 1));
    size = cpv(hPegs, vPegs);
    body = cpBodyNewStatic();
    cpBodySetPos(body, position);
    
    cpShape *wallShape = cpSegmentShapeNew(body, cpv(-width/2, height/2), cpv(width/2, height/2), .5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(-width/2, -height/2), cpv(+width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(-width/2, +height/2), cpv(-width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(+width/2, +height/2), cpv(+width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    inputMachinePosition = cpv(-1,-1);
    outputMachinePosition = cpv(-1,-1);
    
}
コード例 #2
0
ファイル: LevelGrid.cpp プロジェクト: ofx/dr
void LevelGrid::InitializeLevelPhysics(void)
{
    // Fetch the physics space
    cpSpace *space = this->m_Engine->GetWorld()->GetSpace();

    // Add the physics body
    this->m_Body = cpBodyNewStatic();
        
    // Add the physics shapes
    for (int i = 0 ; i < this->m_NumY - 1 ; ++i)
    {
        hgeVector *vec  = this->m_LeftLevelVertices[i];
        hgeVector *nvec = this->m_LeftLevelVertices[i + 1];

        cpShape *shape = cpSegmentShapeNew(this->m_Body, cpv(vec->x, vec->y), cpv(nvec->x, nvec->y), 0.0f);
        shape->e = 1.0; shape->u = 1.0;
        shape->collision_type = COLLISION_TYPE_LEVEL;
        cpSpaceAddStaticShape(space, shape);
        cpBodyActivateStatic(this->m_Body, shape);
        this->m_Shapes.push_back(shape);
    }
    for (int i = 0 ; i < this->m_NumY - 1 ; ++i)
    {
        hgeVector *vec  = this->m_RightLevelVertices[i];
        hgeVector *nvec = this->m_RightLevelVertices[i + 1];
        
        cpShape *shape = cpSegmentShapeNew(this->m_Body, cpv(vec->x, vec->y), cpv(nvec->x, nvec->y), 0.0f);
        shape->e = 1.0; shape->u = 1.0;
        shape->collision_type = COLLISION_TYPE_LEVEL;
        cpSpaceAddStaticShape(space, shape);
        cpBodyActivateStatic(this->m_Body, shape);
        this->m_Shapes.push_back(shape);
    }

    // Create the activator physics shapes
    for (int i = 0 ; i < this->m_NumActivators ; ++i)
    {
        Activator *activator = this->m_Activators[i];

        // Create the cpVects
        cpVect *verts = (cpVect*) malloc(sizeof(cpVect) * 4);
        verts[3].x = activator->Vertices[0].x; verts[3].y = activator->Vertices[0].y;
        verts[2].x = activator->Vertices[1].x; verts[2].y = activator->Vertices[1].y;
        verts[1].x = activator->Vertices[2].x; verts[1].y = activator->Vertices[2].y;
        verts[0].x = activator->Vertices[3].x; verts[0].y = activator->Vertices[3].y;

        // Create and add the poly shape
        cpShape *shape = cpPolyShapeNew(this->m_Body, 4, verts, cpvzero);
        shape->e = 1.0; shape->u = 1.0;
        shape->sensor         = true;
        shape->collision_type = COLLISION_TYPE_ACTIVATOR;
        shape->data           = activator;
        cpSpaceAddStaticShape(space, shape);
        cpBodyActivateStatic(this->m_Body, shape);
        this->m_Shapes.push_back(shape);

        free(verts);
    }
}
コード例 #3
0
ファイル: Tank.c プロジェクト: 0w/moai-dev
static cpSpace *
init(void)
{
	staticBody = cpBodyNew(INFINITY, INFINITY);
	
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	cpSpaceResizeActiveHash(space, 30.0f, 1000);
	space->iterations = 10;
	
	cpShape *shape;
		
	// Create segments around the edge of the screen.
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	
	for(int i=0; i<50; i++){
		cpBody *body = add_box(10.0, 1.0);
		
		cpConstraint *pivot = cpSpaceAddConstraint(space, cpPivotJointNew2(staticBody, body, cpvzero, cpvzero));
		pivot->biasCoef = 0.0f; // disable joint correction
		pivot->maxForce = 1000.0f; // emulate linear friction
		
		cpConstraint *gear = cpSpaceAddConstraint(space, cpGearJointNew(staticBody, body, 0.0f, 1.0f));
		gear->biasCoef = 0.0f; // disable joint correction
		gear->maxForce = 5000.0f; // emulate angular friction
	}
	
	// We joint the tank to the control body and control the tank indirectly by modifying the control body.
	tankControlBody = cpBodyNew(INFINITY, INFINITY);
	tankBody = add_box(15.0, 10.0);
	
	cpConstraint *pivot = cpSpaceAddConstraint(space, cpPivotJointNew2(tankControlBody, tankBody, cpvzero, cpvzero));
	pivot->biasCoef = 0.0f; // disable joint correction
	pivot->maxForce = 10000.0f; // emulate linear friction
	
	cpConstraint *gear = cpSpaceAddConstraint(space, cpGearJointNew(tankControlBody, tankBody, 0.0f, 1.0f));
	gear->biasCoef = 1.0f; // limit angular correction rate
	gear->maxBias = 1.0f; // limit angular correction rate
	gear->maxForce = 500000.0f; // emulate angular friction
		
	return space;
}
コード例 #4
0
ファイル: Simple.c プロジェクト: 18702515007xjy/cocos2d
// Init is called by the demo code to set up the demo.
static cpSpace *
init(void)
{
	// Create an infinite mass body to attach ground segments and other static geometry to.
	// We won't be adding this body to the space, because we don't want it to be simulated at all.
	// Adding bodies to the space simulates them. (fall under the influence of gravity, etc)
	// We want the static body to stay right where it is at all times.
	staticBody = cpBodyNew(INFINITY, INFINITY);
	
	// Create a space, a space is a simulation world. It simulates the motions of rigid bodies,
	// handles collisions between them, and simulates the joints between them.
	space = cpSpaceNew();
	
	// Lets set some parameters of the space:
	// More iterations make the simulation more accurate but slower
	space->iterations = 10;
	// These parameters tune the efficiency of the collision detection.
	// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpSpace
	cpSpaceResizeStaticHash(space, 30.0f, 1000);
	cpSpaceResizeActiveHash(space, 30.0f, 1000);
	// Give it some gravity
	space->gravity = cpv(0, -100);
	
	// Create A ground segment along the bottom of the screen
	cpShape *ground = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f);
	// Set some parameters of the shape.
	// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpShape
	ground->e = 1.0f; ground->u = 1.0f;
	ground->layers = NOT_GRABABLE_MASK; // Used by the Demo mouse grabbing code
	// Add the shape to the space as a static shape
	// If a shape never changes position, add it as static so Chipmunk knows it only needs to
	// calculate collision information for it once when it is added.
	// Do not change the postion of a static shape after adding it.
	cpSpaceAddStaticShape(space, ground);
	
	// Add a moving circle object.
	cpFloat radius = 15.0f;
	cpFloat mass = 10.0f;
	// This time we need to give a mass and moment of inertia when creating the circle.
	cpBody *ballBody = cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, radius, cpvzero));
	// Set some parameters of the body:
	// For more info: http://code.google.com/p/chipmunk-physics/wiki/cpBody
	ballBody->p = cpv(0, -240 + radius+5);
	// Add the body to the space so it will be simulated and move around.
	cpSpaceAddBody(space, ballBody);
	
	
	// Add a circle shape for the ball.
	// Shapes are always defined relative to the center of gravity of the body they are attached to.
	// When the body moves or rotates, the shape will move with it.
	// Additionally, all of the cpSpaceAdd*() functions return the thing they added so you can create and add in one go.
	cpShape *ballShape = cpSpaceAddShape(space, cpCircleShapeNew(ballBody, radius, cpvzero));
	ballShape->e = 0.0f; ballShape->u = 0.9f;
	
	return space;
}
コード例 #5
0
void Coin::attachMe(cpSpace* space)
{
#if STATIC_OBJECT == 1
	cpSpaceAddStaticShape(space, coinShape);
	cpSpaceAddBody(space, coinShape->body);
#else
	cpSpaceAddShape(space, coinShape);
#endif

}
コード例 #6
0
ファイル: UnsafeOps.c プロジェクト: JulianSpillane/moai-dev
static cpSpace *
init(void)
{
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	space->iterations = 5;
	space->gravity = cpv(0, -100);
	
	cpSpaceResizeStaticHash(space, 40.0f, 999);
	cpSpaceResizeActiveHash(space, 30.0f, 2999);
	
	cpBody *body, *staticBody = &space->staticBody;
	cpShape *shape;
	
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	
	for(int i=0; i<NUM_CIRCLES; i++){
		body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForCircle(1.0f, 0.0f, circleRadius, cpvzero)));
		body->p = cpvmult(cpv(frand()*2.0f - 1.0f, frand()*2.0f - 1.0f), circleRadius*5.0f);
		
		circles[i] = shape = cpSpaceAddShape(space, cpCircleShapeNew(body, circleRadius, cpvzero));
		shape->e = 0.0f; shape->u = 1.0f;
	}
	
	strcat(messageString,
		"chipmunk_unsafe.h Contains functions for changing shapes, but they can cause severe stability problems if used incorrectly.\n"
		"Shape changes occur as instantaneous changes to position without an accompanying velocity change. USE WITH CAUTION!");
	return space;
}
コード例 #7
0
ファイル: Bounce.c プロジェクト: rickystone/TwilightGolf
static cpSpace *
init(void)
{
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	cpSpaceResizeActiveHash(space, 30.0f, 1000);
	space->iterations = 10;

	cpShape *shape;

	// Create segments around the edge of the screen.
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(NULL, cpv(-320,-240), cpv(-320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(NULL, cpv(320,-240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(NULL, cpv(-320,-240), cpv(320,-240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(NULL, cpv(-320,240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	
	for(int i=0; i<10; i++)
		add_box();
	
	cpBody *body = cpSpaceAddBody(space, cpBodyNew(100.0f, 10000.0f));

	shape = cpSpaceAddShape(space, cpSegmentShapeNew(body, cpv(-75,0), cpv(75,0), 5.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	
	cpSpaceAddConstraint(space, cpPivotJointNew2(body, NULL, cpvzero, cpvzero));
	
	return space;
}
コード例 #8
0
ファイル: gui.c プロジェクト: outgame/CrayonPhysics
int initialize_window(Gui *gui){
  //making the window
  gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(gui->window), "Crayon Physics A++");
  gtk_window_set_default_size(GTK_WINDOW(gui->window), WINDOW_WIDTH, WINDOW_HEIGHT);
  gtk_window_set_position(GTK_WINDOW(gui->window), GTK_WIN_POS_CENTER);
  
  //making the grid to go in the window
  GtkWidget *grid;
  grid = gtk_grid_new();
  gtk_container_add(GTK_CONTAINER(gui->window), grid);
  
  //make the menu
  if (!initialize_menu(grid, gui)){
    return -1;
  }
  
  //initializing the draw area
  gui->draw_area = gtk_drawing_area_new();
  initialize_draw_area(grid, gui->draw_area);
  
  //initialize the text entry box
  gui->entry = gtk_entry_new();
  initialize_text_entry(grid, gui);

  //initialize the text view
  gui->text_view = gtk_text_view_new();
  initialize_text_view(grid, gui);

  //shapes and bodies for testing
  gtk_widget_show_all(gui->window);
  cpShape *ground = cpSpaceAddStaticShape(gui->space, cpSegmentShapeNew(gui->space->staticBody, cpv(0, 1), cpv(10, 1), CRAYON_RADIUS * 2));
  cpShapeSetFriction(ground, 1.0);
  cpSpaceAddStaticShape(gui->space, cpSegmentShapeNew(gui->space->staticBody, cpv(3, -100), cpv(3, 100), CRAYON_RADIUS * 2));
  //add events and connect signals
  gtk_widget_add_events(gui->draw_area, GDK_BUTTON_PRESS_MASK);
  connect_signals(gui);
  
  return 1;
}
コード例 #9
0
void PhysicsWorld::addShape(PhysicsShape* shape)
{
    for (auto it = shape->_info->shapes.begin(); it != shape->_info->shapes.end(); it++)
    {
        if (cpBodyIsStatic(shape->getBody()->_info->body))
        {
            cpSpaceAddStaticShape(_info->space, *it);
        }else
        {
            cpSpaceAddShape(_info->space, *it);
        }
    }
}
コード例 #10
0
ファイル: cpSpace.c プロジェクト: rickystone/TwilightGolf
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
//	cpAssert(shape->body, "Cannot add a shape with a NULL body.");
	if(!shape->body) return cpSpaceAddStaticShape(space, shape);

	cpAssert(!cpHashSetFind(space->activeShapes->handleSet, shape->hashid, shape),
		"Cannot add the same shape more than once.");
	cpAssertSpaceUnlocked(space);
	
	cpSpaceHashInsert(space->activeShapes, shape, shape->hashid, shape->bb);
	return shape;
}
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
	cpBody *body = shape->body;
	if(!body || body == &space->staticBody) return cpSpaceAddStaticShape(space, shape);
	
	cpAssert(!cpHashSetFind(space->activeShapes->handleSet, shape->hashid, shape),
		"Cannot add the same shape more than once.");
	cpAssertSpaceUnlocked(space);
	
	cpBodyActivate(body);
	cpBodyAddShape(body, shape);
	addShapeRaw(shape, space->activeShapes);
		
	return shape;
}
コード例 #12
0
void ChipmunkTestLayer::initPhysics()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION    
    // init chipmunk
    //cpInitChipmunk();

    _space = cpSpaceNew();

    //_space->gravity = cpv(0, -100);
    _space->gravity = cpv(0, 0);

    //
    // rogue shapes
    // We have to free them manually
    //
    // bottom
    _walls[0] = cpSegmentShapeNew( _space->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y), 0.0f);

    // top
    _walls[1] = cpSegmentShapeNew( _space->staticBody, 
        cpv(VisibleRect::leftTop().x, VisibleRect::leftTop().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    // left
    _walls[2] = cpSegmentShapeNew( _space->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::leftTop().x,VisibleRect::leftTop().y), 0.0f);

    // right
    _walls[3] = cpSegmentShapeNew( _space->staticBody, 
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    for( int i=0;i<4;i++) {
        _walls[i]->e = 1.0f;
        _walls[i]->u = 1.0f;
        cpSpaceAddStaticShape(_space, _walls[i] );
    }

    // Physics debug layer
    _debugLayer = PhysicsDebugNode::create(_space);
    this->addChild(_debugLayer, Z_PHYSICS_DEBUG);
#endif
}
コード例 #13
0
void HelloWorld::initPhysic() {
#if CC_ENABLE_CHIPMUNK_INTEGRATION

    //启动重力加速度,系统会定时调用didAccelerate
    setAccelerometerEnabled(true);

    m_pSpace = cpSpaceNew();

    m_pSpace->gravity = cpv(0, -100);

    //
    // rogue shapes
    // We have to free them manually
    //
    // bottom
    m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y), 0.0f);

    // top
    m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, 
        cpv(VisibleRect::leftTop().x, VisibleRect::leftTop().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    // left
    m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody,
        cpv(VisibleRect::leftBottom().x,VisibleRect::leftBottom().y),
        cpv(VisibleRect::leftTop().x,VisibleRect::leftTop().y), 0.0f);

    // right
    m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, 
        cpv(VisibleRect::rightBottom().x, VisibleRect::rightBottom().y),
        cpv(VisibleRect::rightTop().x, VisibleRect::rightTop().y), 0.0f);

    for( int i=0;i<4;i++) {
        m_pWalls[i]->e = 1.0f;
        m_pWalls[i]->u = 1.0f;
        cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] );
    }

    // Physics debug layer
    m_pDebugLayer = CCPhysicsDebugNode::create(m_pSpace);
    this->addChild(m_pDebugLayer, Z_PHYSICS_DEBUG);
#endif
}
コード例 #14
0
ファイル: cpSpace.c プロジェクト: AntonioModer/Cheetah
//MARK: Body, Shape, and Joint Management
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
	cpBody *body = shape->body;
	if(cpBodyIsStatic(body)) return cpSpaceAddStaticShape(space, shape);
	
	cpAssertHard(!shape->space, "This shape is already added to a space and cannot be added to another.");
	cpAssertSpaceUnlocked(space);
	
	cpBodyActivate(body);
	cpBodyAddShape(body, shape);
	
	cpShapeUpdate(shape, body->p, body->rot);
	cpSpatialIndexInsert(space->activeShapes, shape, shape->hashid);
	shape->space = space;
		
	return shape;
}
コード例 #15
0
ファイル: GameScene.cpp プロジェクト: NatWeiss/RGP
void GameScene::createPhysicsBox(int x1, int y1, int x2, int y2, float elasticity, float friction, int collisionType)
{
	cpShape* shape = nullptr;
	int start = shapes.size();

	// create box as four segments
	shapes.push_back(cpSegmentShapeNew(space->staticBody, cpv(x1, y1), cpv(x1, y2), 0.0f));
	shapes.push_back(cpSegmentShapeNew(space->staticBody, cpv(x1, y2), cpv(x2, y2), 0.0f));
	shapes.push_back(cpSegmentShapeNew(space->staticBody, cpv(x2, y2), cpv(x2, y1), 0.0f));
	shapes.push_back(cpSegmentShapeNew(space->staticBody, cpv(x2, y1), cpv(x1, y1), 0.0f));
	for (int i = 0; i < 4; i++)
	{
		shapes[start + i]->e = elasticity;
		shapes[start + i]->u = friction;
		shapes[start + i]->collision_type = collisionType;
		cpSpaceAddStaticShape(space, shapes[start + i]);
	}
}
コード例 #16
0
ファイル: cpSpace.c プロジェクト: harad/Last-Escape
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
	cpBody *body = shape->body;
	if(!body || cpBodyIsStatic(body)) return cpSpaceAddStaticShape(space, shape);
	
	cpAssert(!cpHashSetFind(space->activeShapes->handleSet, shape->hashid, shape),
		"Cannot add the same shape more than once.");
	cpAssertSpaceUnlocked(space);
	
	cpBodyActivate(body);
	cpBodyAddShape(body, shape);
	
	cpShapeCacheBB(shape);
	cpSpaceHashInsert(space->activeShapes, shape, shape->hashid, shape->bb);
		
	return shape;
}
コード例 #17
0
ファイル: cpSpace.c プロジェクト: 0x0c/cocos2d-x
//MARK: Body, Shape, and Joint Management
cpShape *
cpSpaceAddShape(cpSpace *space, cpShape *shape)
{
	cpBody *body = shape->body;
	if(cpBodyIsStatic(body)) return cpSpaceAddStaticShape(space, shape);
	
	cpAssertHard(shape->space != space, "You have already added this shape to this space. You must not add it a second time.");
	cpAssertHard(!shape->space, "You have already added this shape to another space. You cannot add it to a second.");
	cpAssertSpaceUnlocked(space);
	
	cpBodyActivate(body);
	cpBodyAddShape(body, shape);
	
	cpShapeUpdate(shape, body->p, body->rot);
	cpSpatialIndexInsert(space->activeShapes, shape, shape->hashid);
	shape->space = space;
		
	return shape;
}
コード例 #18
0
// NOTE - don't use a GEAR attachment to attach to the wall - the peg does not rotate, so the body will not rotate
void MachineSystem::addPart(MachinePart *newPart, Attachment *attachment, cpVect gridPosition)
{
    int machineNumber = machinePositionToNumber(gridPosition);
    
    MachinePart *alreadyAttached = parts[machineNumber];
    if (!alreadyAttached) {
        cpVect pegPosition = gridPositionToWorld(gridPosition);
        cpBody *pegBody = cpBodyNewStatic();
        cpBodySetPos(pegBody, pegPosition);
        cpShape *pegShape = cpCircleShapeNew(pegBody, 5.0, cpv(0,0));
        cpShapeSetLayers(pegShape, PEG_LAYER);
        cpSpaceAddStaticShape(space, pegShape);
        
        parts[machineNumber] = newPart;
        nMachines++;
        newPart->setOriginalPosition(pegPosition);
        newPart->attachToBody(attachment, pegBody);
        attachments[machineNumber][machineNumber] = attachment;
    }
}
コード例 #19
0
ファイル: bomb.cpp プロジェクト: robmerrell/neon_destruction
void Bomb::definePhysics(cpSpace *space) {
  // body
  if (simulation_type == "DYNAMIC")
    body = cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, 15.0f, cpvzero));
  else
    body = cpBodyNew(INFINITY, INFINITY);
    
  body->p = cpv(x, y);
  if (simulation_type == "DYNAMIC") cpSpaceAddBody(space, body);

  // ball shape
  bombShape = cpCircleShapeNew(body, 15.0f, cpvzero);
  bombShape->e = elasticity;
  bombShape->u = 0.2;
  bombShape->data = this;
  bombShape->collision_type = BOMB_COLLISION;
  
  if (simulation_type == "DYNAMIC")
    cpSpaceAddShape(space, bombShape);
  else
    cpSpaceAddStaticShape(space, bombShape);
}
コード例 #20
0
void EndlessWorld::extendFlat()
{
	//flat
	cpVect verts[] = {
		cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, -2000),
		cpv(koniec - dodatek - G_odlegloscmiedzyBramkami, 0),
		cpv(koniec, 0),
		cpv(koniec, -2000),
	};
	cpSpaceRemoveStaticShape(gravitySpace, floor);
	floor = cpPolyShapeNew(floorBody, 4, verts, cpvzero);
	floor->e = 0;//elastycznosc;
	floor->u = 0.1f;//friction
	floor->collision_type = COLLISIONTYPEFLOOR;
	cpShapeSetLayers(floor, CPFLOORCOLIDER);
	cpSpaceAddStaticShape(gravitySpace, floor);
	flatsprite->setTextureRect(Rect(verts[0].x, verts[1].y, abs(verts[3].x), flatsprite->getTexture()->getContentSize().height));
	bottomSpr->setPositionX(koniec - dodatek - G_odlegloscmiedzyBramkami);
	//chkpts
	if (isEndless())
	{
		for (int i = koniec - dodatek; i <= koniec; i += G_odlegloscmiedzyBramkami)
		{
			auto chkpt = Chcekpoint::create(this, &orderedOpponents, R_SPRITE_checkpoint);
			chkpt->setPosition(i, floor->bb.t);
			modifyGate(chkpt);
			rotationLayer->addChild(chkpt);
		}
	}
	//POWERUPS
	for (int j = koniec - dodatek + G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar); j <= koniec; j += G_powerUpOdleglos + random(0,G_powerUpOdlegloscVar))
	{
		int wysokosc = 2.5f * Sprite::createWithSpriteFrameName(R_Box[1])->getContentSize().height;
		PowerUp *pwrup = PowerUp::create(&orderedOpponents);
		pwrup->setPosition(Vec2(j, floor->bb.t + wysokosc));
		rotationLayer->addChild(pwrup);
	}
}
コード例 #21
0
ファイル: Query.cpp プロジェクト: charlesa101/cocos2d-x
static cpSpace *
init(void)
{
	staticBody = cpBodyNew(INFINITY, INFINITY);
	
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	space->elasticIterations = 0;
	space->iterations = 5;
	
	cpSpaceResizeStaticHash(space, 40.0f, 999);
	cpSpaceResizeActiveHash(space, 30.0f, 2999);
	
	cpShape *shape;
	
	// add a non-collidable segment as a quick and dirty way to draw the query line
	shape = cpSegmentShapeNew(staticBody, cpvzero, cpv(100.0f, 0.0f), 4.0f);
	cpSpaceAddStaticShape(space, shape);
	shape->layers = 0;
	querySeg = shape;
	
	{ // add a fat segment
		cpFloat mass = 1.0f;
		cpFloat length = 100.0f;
		cpVect a = cpv(-length/2.0f, 0.0f), b = cpv(length/2.0f, 0.0f);
		
		cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForSegment(mass, a, b)));
		body->p = cpv(0.0f, 100.0f);
		
		cpSpaceAddShape(space, cpSegmentShapeNew(body, a, b, 20.0f));
	}
	
	{ // add a static segment
		cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(0, 300), cpv(300, 0), 0.0f));
	}
	
	{ // add a pentagon
		cpFloat mass = 1.0f;
		const int NUM_VERTS = 5;
		
		cpVect verts[NUM_VERTS];
		for(int i=0; i<NUM_VERTS; i++){
			cpFloat angle = -2*(cpFloat)M_PI*i/((cpFloat) NUM_VERTS);
			verts[i] = cpv(30*cpfcos(angle), 30*cpfsin(angle));
		}
		
		cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForPoly(mass, NUM_VERTS, verts, cpvzero)));
		body->p = cpv(50.0f, 50.0f);
		
		cpSpaceAddShape(space, cpPolyShapeNew(body, NUM_VERTS, verts, cpvzero));
	}
	
	{ // add a circle
		cpFloat mass = 1.0f;
		cpFloat r = 20.0f;
		
		cpBody *body = cpSpaceAddBody(space, cpBodyNew(mass, cpMomentForCircle(mass, 0.0f, r, cpvzero)));
		body->p = cpv(100.0f, 100.0f);
		
		cpSpaceAddShape(space, cpCircleShapeNew(body, r, cpvzero));
	}
	
	return space;
}
コード例 #22
0
ファイル: world.cpp プロジェクト: damir00/zac
void World::addStaticLine(cpVect start,cpVect end) {
	cpShape* s=cpSegmentShapeNew(static_body,start,end,0.1);
	cpSpaceAddStaticShape(space,s);
}
コード例 #23
0
 CDynamics2DBoxEntity::CDynamics2DBoxEntity(CDynamics2DEngine& c_engine,
                                            CBoxEntity& c_entity) :
    CDynamics2DEntity(c_engine, c_entity.GetEmbodiedEntity()),
    m_cBoxEntity(c_entity),
    m_fMass(c_entity.GetMass()),
    m_ptShape(NULL),
    m_ptBody(NULL) {
    /* Get the size of the entity */
    CVector3 cHalfSize = c_entity.GetSize() * 0.5f;
    m_fHalfHeight = cHalfSize.GetZ();
    /* Create a polygonal object in the physics space */
    /* Start defining the vertices
       NOTE: points must be defined in a clockwise winding
    */
    cpVect tVertices[] = {
       cpv(-cHalfSize.GetX(), -cHalfSize.GetY()),
       cpv(-cHalfSize.GetX(),  cHalfSize.GetY()),
       cpv( cHalfSize.GetX(),  cHalfSize.GetY()),
       cpv( cHalfSize.GetX(), -cHalfSize.GetY())
    };
    const CVector3& cPosition = GetEmbodiedEntity().GetPosition();
    CRadians cXAngle, cYAngle, cZAngle;
    GetEmbodiedEntity().GetOrientation().ToEulerAngles(cZAngle, cYAngle, cXAngle);
    if(c_entity.GetEmbodiedEntity().IsMovable()) {
       /* The box is movable */
       /* Create the body */
       m_ptBody =
          cpSpaceAddBody(m_cEngine.GetPhysicsSpace(),
                         cpBodyNew(m_fMass,
                                   cpMomentForPoly(m_fMass,
                                                   4,
                                                   tVertices,
                                                   cpvzero)));
       m_ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
       cpBodySetAngle(m_ptBody, cZAngle.GetValue());
       /* Create the geometry */
       m_ptShape =
          cpSpaceAddShape(m_cEngine.GetPhysicsSpace(),
                          cpPolyShapeNew(m_ptBody,
                                         4,
                                         tVertices,
                                         cpvzero));
       /* This object is grippable */
       m_ptShape->collision_type = CDynamics2DEngine::SHAPE_GRIPPABLE;
       m_ptShape->data = reinterpret_cast<void*>(&c_entity);
       /* No elasticity */
       m_ptShape->e = 0.0;
       /* Lots contact friction to help pushing */
       m_ptShape->u = 0.7;
       /* Friction with ground */
       m_ptLinearFriction =
          cpSpaceAddConstraint(m_cEngine.GetPhysicsSpace(),
                               cpPivotJointNew2(m_cEngine.GetGroundBody(),
                                                m_ptBody,
                                                cpvzero,
                                                cpvzero));
       m_ptLinearFriction->maxBias = 0.0f; // disable joint correction
       m_ptLinearFriction->maxForce = 1.49f; // emulate linear friction (this is just slightly smaller than FOOTBOT_MAX_FORCE)
       m_ptAngularFriction =
          cpSpaceAddConstraint(m_cEngine.GetPhysicsSpace(),
                               cpGearJointNew(m_cEngine.GetGroundBody(),
                                              m_ptBody,
                                              0.0f,
                                              1.0f));
       m_ptAngularFriction->maxBias = 0.0f; // disable joint correction
       m_ptAngularFriction->maxForce = 1.49f; // emulate angular friction (this is just slightly smaller than FOOTBOT_MAX_TORQUE)
    }
    else {
       /* The box is not movable */
       /* Manually rotate the vertices */
       cpVect tRot = cpvforangle(cZAngle.GetValue());
       tVertices[0] = cpvrotate(tVertices[0], tRot);
       tVertices[1] = cpvrotate(tVertices[1], tRot);
       tVertices[2] = cpvrotate(tVertices[2], tRot);
       tVertices[3] = cpvrotate(tVertices[3], tRot);
       /* Create the geometry */
       m_ptShape =
          cpSpaceAddStaticShape(m_cEngine.GetPhysicsSpace(),
                                cpPolyShapeNew(m_cEngine.GetGroundBody(),
                                               4,
                                               tVertices,
                                               cpv(cPosition.GetX(), cPosition.GetY())));
       /* This object is normal */
       m_ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
       m_ptShape->data = reinterpret_cast<void*>(&c_entity);
       /* No elasticity */
       m_ptShape->e = 0.0;
       /* Little contact friction to help sliding away */
       m_ptShape->u = 0.1;
    }
 }
コード例 #24
0
void bmx_cpspace_addstaticshape(cpSpace * space, cpShape * shape) {
	cpSpaceAddStaticShape(space, shape);
}
コード例 #25
0
ファイル: Player.c プロジェクト: 18702515007xjy/cocos2d
static cpSpace *
init(void)
{
	staticBody = cpBodyNew(INFINITY, INFINITY);
	
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	space->iterations = 10;
	space->gravity = cpv(0, -1500);
	
	cpBody *body;
	cpShape *shape;
	
	// Create segments around the edge of the screen.
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;
	
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-320,240), cpv(320,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;
	
	// add some other segments to play with
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-220,-200), cpv(-220,240), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(0,-240), cpv(320,-200), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(200,-240), cpv(320,-100), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, cpv(-220,-80), cpv(200,-80), 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	shape->collision_type = 2;
	
	// Set up the player
	cpFloat radius = 15.0f;
	body = cpSpaceAddBody(space, cpBodyNew(10.0f, INFINITY));
	body->p = cpv(0, -220);
	body->velocity_func = playerUpdateVelocity;

	shape = cpSpaceAddShape(space, cpCircleShapeNew(body, radius, cpvzero));
	shape->e = 0.0f; shape->u = 2.0f;
	shape->collision_type = 1;
	
	playerInstance.u = shape->u;
	playerInstance.shape = shape;
	playerInstance.groundShapes = cpArrayNew(0);
	shape->data = &playerInstance;
	
	cpSpaceAddCollisionHandler(space, 1, 2, begin, preSolve, NULL, separate, NULL);
	
	return space;
}
コード例 #26
0
ファイル: Space.cpp プロジェクト: Marwes/CppChipmunk
cp::Shape* Space::addStaticShape(cp::Shape *shape)
{
		cpShape*  temp = cpSpaceAddStaticShape(space,shape ? shape->get() : 0);
		return static_cast<cp::Shape* >(temp ? temp->data : 0);
}
コード例 #27
0
ファイル: wall.c プロジェクト: tjhsstgeek/MultiBT
void wall_add(struct wall *w, struct game *g) {
	cpSpaceAddStaticShape(g->cp, &w->shape);
}
コード例 #28
0
CDynamics2DCylinderEntity::CDynamics2DCylinderEntity(CDynamics2DEngine& c_engine,
        CCylinderEntity& c_entity) :
    CDynamics2DEntity(c_engine, c_entity.GetEmbodiedEntity()),
    m_cCylinderEntity(c_entity),
    m_fMass(c_entity.GetMass()),
    m_ptShape(NULL),
    m_ptBody(NULL) {
    /* Get the radius of the entity */
    Real fRadius = c_entity.GetRadius();
    m_fHalfHeight = c_entity.GetHeight() * 0.5f;
    /* Create a circle object in the physics space */
    const CVector3& cPosition = GetEmbodiedEntity().GetPosition();
    if(c_entity.IsMovable()) {
        /* The cylinder is movable */
        /* Create the body */
        m_ptBody = cpSpaceAddBody(m_cEngine.GetPhysicsSpace(),
                                  cpBodyNew(m_fMass,
                                            cpMomentForCircle(m_fMass,
                                                    0,
                                                    fRadius + fRadius,
                                                    cpvzero)));
        m_ptBody->p = cpv(cPosition.GetX(), cPosition.GetY());
        CRadians cXAngle, cYAngle, cZAngle;
        GetEmbodiedEntity().GetOrientation().ToEulerAngles(cZAngle, cYAngle, cXAngle);
        cpBodySetAngle(m_ptBody, cZAngle.GetValue());
        /* Create the geometry */
        m_ptShape = cpSpaceAddShape(m_cEngine.GetPhysicsSpace(),
                                    cpCircleShapeNew(m_ptBody, fRadius, cpvzero));
        /* This object is grippable */
        m_ptShape->collision_type = CDynamics2DEngine::SHAPE_GRIPPABLE;
        m_ptShape->data = reinterpret_cast<void*>(&c_entity);
        /* No elasticity */
        m_ptShape->e = 0.0;
        /* Lots surface contact friction to help pushing */
        m_ptShape->u = 0.7;
        /* Friction with ground */
        m_ptLinearFriction =
            cpSpaceAddConstraint(m_cEngine.GetPhysicsSpace(),
                                 cpPivotJointNew2(m_cEngine.GetGroundBody(),
                                         m_ptBody,
                                         cpvzero,
                                         cpvzero));
        m_ptLinearFriction->biasCoef = 0.0f; // disable joint correction
        m_ptLinearFriction->maxForce = 1.0f; // emulate linear friction
        m_ptAngularFriction =
            cpSpaceAddConstraint(m_cEngine.GetPhysicsSpace(),
                                 cpGearJointNew(m_cEngine.GetGroundBody(),
                                                m_ptBody,
                                                0.0f,
                                                1.0f));
        m_ptAngularFriction->biasCoef = 0.0f; // disable joint correction
        m_ptAngularFriction->maxForce = 5.0f; // emulate angular friction
    }
    else {
        /* The cylinder is not movable */
        /* Create the geometry */
        m_ptShape = cpSpaceAddStaticShape(m_cEngine.GetPhysicsSpace(),
                                          cpCircleShapeNew(m_cEngine.GetGroundBody(),
                                                  fRadius,
                                                  cpv(cPosition.GetX(), cPosition.GetY())));
        /* This object is normal */
        m_ptShape->collision_type = CDynamics2DEngine::SHAPE_NORMAL;
        m_ptShape->data = reinterpret_cast<void*>(&c_entity);
        /* No elasticity */
        m_ptShape->e = 0.0;
        /* Little contact friction to help sliding away */
        m_ptShape->u = 0.1;
    }
}
コード例 #29
0
MachineSystem::MachineSystem(MachineSystem &original, cpVect position)
: space(cpSpaceNew()),
 size(original.size),
gridSpacing(original.gridSpacing),
inputMachinePosition(original.inputMachinePosition),
outputMachinePosition(original.outputMachinePosition),
nMachines(0),
nAttachments(0),
destroyAttachments(original.destroyAttachments)
{
    cpFloat width = (original.size.x +1)*original.gridSpacing.x;
    cpFloat height = (original.size.y +1)*original.gridSpacing.y;
   
    body = cpBodyNewStatic();
    cpBodySetPos(body, position);
    
    cpShape *wallShape = cpSegmentShapeNew(body, cpv(-width/2, height/2), cpv(width/2, height/2), .5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(-width/2, -height/2), cpv(+width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(-width/2, +height/2), cpv(-width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    wallShape = cpSegmentShapeNew(body, cpv(+width/2, +height/2), cpv(+width/2, -height/2), 0.5);
    cpShapeSetLayers(wallShape, WALL_LAYER);
    cpSpaceAddStaticShape(space, wallShape);
    
    // do the copy of the attachment and machines manually, because we need to add and attach machines
    int nPegs = size.x*size.y;

    parts.resize(nPegs, NULL);
    
    attachments.resize(nPegs);
    
    for (int i=0; i<nPegs; i++)
        attachments[i].resize(nPegs, NULL);
    
    for (int x = 0; x < size.x; x++ ) {
        for (int y = 0; y < size.y; y++) {
            cpVect gridPos = cpv(x,y);
            int machineNum = machinePositionToNumber(gridPos);
            MachinePart *machineToCopy = original.parts[machineNum];
            if (machineToCopy) {
                MachinePart *newPart = new MachinePart(*machineToCopy, space);
                Attachment *wallAttachment = Attachment::copyAttachment(original.attachments[machineNum][machineNum]);
                addPart(newPart, wallAttachment, gridPos);
            }
        }
    }
    
    for (int i=0; i<nPegs; i++) {
        for (int j=0; j<i; j++) {
            Attachment *attachmentToCopy = original.attachments[i][j];
            if (attachmentToCopy) {
                Attachment *attachmentCopy = Attachment::copyAttachment(attachmentToCopy);
                cpVect machine1Pos = machineNumberToPosition(i);
                cpVect machine2Pos = machineNumberToPosition(j);
                
                attachMachines(machine1Pos, machine2Pos, attachmentCopy);
                attachmentCopy->innovationNumber = attachmentToCopy->innovationNumber;
            }
        }
    }
}
コード例 #30
0
ファイル: Tumble.c プロジェクト: 18702515007xjy/cocos2d
static cpSpace *
init(void)
{
	staticBody = cpBodyNew(INFINITY, INFINITY);
	
	cpResetShapeIdCounter();
	
	space = cpSpaceNew();
	cpSpaceResizeActiveHash(space, 40.0f, 999);
	cpSpaceResizeStaticHash(space, 40.0f, 99);
	space->gravity = cpv(0, -600);
	
	cpBody *body;
	cpShape *shape;
	
	// Vertexes for the bricks
	int num = 4;
	cpVect verts[] = {
		cpv(-30,-15),
		cpv(-30, 15),
		cpv( 30, 15),
		cpv( 30,-15),
	};
	
	// Set up the static box.
	cpVect a = cpv(-200, -200);
	cpVect b = cpv(-200,  200);
	cpVect c = cpv( 200,  200);
	cpVect d = cpv( 200, -200);
	
	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, a, b, 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, b, c, 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, c, d, 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;

	shape = cpSpaceAddStaticShape(space, cpSegmentShapeNew(staticBody, d, a, 0.0f));
	shape->e = 1.0f; shape->u = 1.0f;
	shape->layers = NOT_GRABABLE_MASK;
	
	// Give the box a little spin.
	// Because staticBody is never added to the space, we will need to
	// update it ourselves. (see above).
	// NOTE: Normally you would want to add the segments as normal and not static shapes.
	// I'm just doing it to demonstrate the cpSpaceRehashStatic() function.
	staticBody->w = 0.4f;
	
	// Add the bricks.
	for(int i=0; i<3; i++){
		for(int j=0; j<7; j++){
			body = cpSpaceAddBody(space, cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero)));
			body->p = cpv(i*60 - 150, j*30 - 150);
			
			shape = cpSpaceAddShape(space, cpPolyShapeNew(body, num, verts, cpvzero));
			shape->e = 0.0f; shape->u = 0.7f;
		}
	}
	
	return space;
}