static int l_physics_getShapeFriction(lua_State* state) { l_physics_Shape* shape = (l_physics_Shape*)lua_touserdata(state, 1); lua_pushnumber(state, cpShapeGetFriction(shape->shape)); return 1; }
void Slice::ClipPoly(cpSpace *space, cpShape *shape, cpVect n, cpFloat dist) { cpBody *body = cpShapeGetBody(shape); int count = cpPolyShapeGetCount(shape); int clippedCount = 0; cpVect *clipped = (cpVect *)alloca((count + 1)*sizeof(cpVect)); for(int i=0, j=count-1; i<count; j=i, i++){ cpVect a = cpBodyLocalToWorld(body, cpPolyShapeGetVert(shape, j)); cpFloat a_dist = cpvdot(a, n) - dist; if(a_dist < 0.0){ clipped[clippedCount] = a; clippedCount++; } cpVect b = cpBodyLocalToWorld(body, cpPolyShapeGetVert(shape, i)); cpFloat b_dist = cpvdot(b, n) - dist; if(a_dist*b_dist < 0.0f){ cpFloat t = cpfabs(a_dist)/(cpfabs(a_dist) + cpfabs(b_dist)); clipped[clippedCount] = cpvlerp(a, b, t); clippedCount++; } } cpVect centroid = cpCentroidForPoly(clippedCount, clipped); cpFloat mass = cpAreaForPoly(clippedCount, clipped, 0.0f)*DENSITY; cpFloat moment = cpMomentForPoly(mass, clippedCount, clipped, cpvneg(centroid), 0.0f); cpBody *new_body = cpSpaceAddBody(space, cpBodyNew(mass, moment)); cpBodySetPosition(new_body, centroid); cpBodySetVelocity(new_body, cpBodyGetVelocityAtWorldPoint(body, centroid)); cpBodySetAngularVelocity(new_body, cpBodyGetAngularVelocity(body)); cpTransform transform = cpTransformTranslate(cpvneg(centroid)); cpShape *new_shape = cpSpaceAddShape(space, cpPolyShapeNew(new_body, clippedCount, clipped, transform, 0.0)); // Copy whatever properties you have set on the original shape that are important cpShapeSetFriction(new_shape, cpShapeGetFriction(shape)); }
float CCPhysicsShape::getFriction(void) { return cpShapeGetFriction(m_shape); }
void RigidBody2D::CopyShapeData(cpShape* from, cpShape* to) { cpShapeSetElasticity(to, cpShapeGetElasticity(from)); cpShapeSetFriction(to, cpShapeGetFriction(from)); cpShapeSetSurfaceVelocity(to, cpShapeGetSurfaceVelocity(from)); }
float Nz::RigidBody2D::GetFriction(std::size_t shapeIndex) const { assert(shapeIndex < m_shapes.size()); return float(cpShapeGetFriction(m_shapes[shapeIndex])); }
GLMFloat worldShape_friction(WorldShape_t *aEntity) { return cpShapeGetFriction(aEntity->cpShape); }
cpFloat shape::friction( void ) { return cpShapeGetFriction( this->m_shape ); }