Exemple #1
0
ConvexObject::ConvexObject(std::vector<cpVect> points, float mass)
  : PhysicalObject(points, mass)
{
     cpRecenterPoly(points.size(), points.data());
     shape = cpPolyShapeNew(body, points.size(), points.data(), cpv(0, 0));
     shape->data = static_cast<PhysicalObject *>(this);

     shapes.push_back(shape);
}
void PhysicsShape::recenterPoints(Vec2* points, int count, const Vec2& center)
{
    cpVect* cpvs = new cpVect[count];
    cpRecenterPoly(count, PhysicsHelper::points2cpvs(points, cpvs, count));
    PhysicsHelper::cpvs2points(cpvs, points, count);
    delete[] cpvs;
    
    if (center != Vec2::ZERO)
    {
        for (int i = 0; i < count; ++i)
        {
            points[i] += center;
        }
    }
}
Exemple #3
0
__declspec( dllexport ) void recenterpolygon( const void * _in, int in_size, void * _out, int out_sz )
{
	int i;
	int size = PEEKINT(INPUT_MEMBLOCK,0);
	cpVect *vertices = (cpVect*)malloc(size*sizeof(cpVect));
	for (i = 0;i != size;i++)
	{
		vertices[i] = PEEKVECT(INPUT_MEMBLOCK,4+i*8);
	}
	cpRecenterPoly(size,vertices);
	for (i = 0;i != size;i++)
	{
		POKEVECT(OUTPUT_MEMBLOCK,i*8,vertices[i]);
	}
	free(vertices);
}
Exemple #4
0
static VALUE
rb_cpRecenterPoly(VALUE self,  VALUE arr) {
  Check_Type(arr, T_ARRAY);
  long numVerts   = RARRAY_LEN(arr);
  VALUE *ary_ptr = RARRAY_PTR(arr);
  cpVect verts[numVerts];

  for(long i = 0; i < numVerts; i++)
    verts[i] = *VGET(ary_ptr[i]);

  cpRecenterPoly(numVerts, verts);

  for(long i = 0; i < numVerts; i++)
    ary_ptr[i] = VNEW(verts[i]);
  return arr;
}
Exemple #5
0
Point* PhysicsShape::recenterPoints(Point* points, int count, Point center)
{
    cpVect* cpvs = new cpVect[count];
    cpRecenterPoly(count, PhysicsHelper::points2cpvs(points, cpvs, count));
    PhysicsHelper::cpvs2points(cpvs, points, count);
    delete[] cpvs;
    
    if (center != Point::ZERO)
    {
        for (int i = 0; i < count; ++i)
        {
            points[i] += center;
        }
    }
    
    return points;
}