Beispiel #1
0
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);
    }
}
Beispiel #2
0
void
cpSpaceRemoveStaticShape(cpSpace *space, cpShape *shape)
{
	cpAssertHard(cpSpaceContainsShape(space, shape), "Cannot remove a static or sleeping shape that was not added to the space. (Removed twice maybe?)");
	cpAssertSpaceUnlocked(space);
	
	cpBody *body = shape->body;
	if(cpBodyIsStatic(body)) cpBodyActivateStatic(body, shape);
	cpBodyRemoveShape(body, shape);
	cpSpaceFilterArbiters(space, body, shape);
	cpSpatialIndexRemove(space->staticShapes, shape, shape->hashid);
	shape->space = NULL;
}
Beispiel #3
0
void
cpSpaceRemoveShape(cpSpace *space, cpShape *shape)
{
	cpBody *body = shape->body;
	cpAssertHard(cpSpaceContainsShape(space, shape), "Cannot remove a shape that was not added to the space. (Removed twice maybe?)");
	cpAssertSpaceUnlocked(space);
	
	cpBool isStatic = (cpBodyGetType(body) == CP_BODY_TYPE_STATIC);
	if(isStatic){
		cpBodyActivateStatic(body, shape);
	} else {
		cpBodyActivate(body);
	}

	cpBodyRemoveShape(body, shape);
	cpSpaceFilterArbiters(space, body, shape);
	cpSpatialIndexRemove(isStatic ? space->staticShapes : space->dynamicShapes, shape, shape->hashid);
	shape->space = NULL;
	shape->hashid = 0;
}
Beispiel #4
0
void cBody::ActivateStatic( cBody *body, cShape * filter ) {
	cpBodyActivateStatic( mBody, filter->Shape() );
}
Beispiel #5
0
 void Body::activateStatic(std::shared_ptr<Shape> filter) { cpBodyActivateStatic(_body, *filter);
 };
Beispiel #6
0
void Body::activateStatic(cp::Shape *filter)
{
		cpBodyActivateStatic(body,filter ? filter->get() : 0);
}