void PhysicsShapeEdgeSegment::updateScale()
{
    cpFloat factorX = _newScaleX / _scaleX;
    cpFloat factorY = _newScaleY / _scaleY;

    cpShape* shape = _cpShapes.front();
    cpVect a = cpSegmentShapeGetA(shape);
    a.x *= factorX;
    a.y *= factorY;
    cpVect b = cpSegmentShapeGetB(shape);
    b.x *= factorX;
    b.y *= factorY;
    cpSegmentShapeSetEndpoints(shape, a, b);

    PhysicsShape::updateScale();
}
void PhysicsShapeEdgeChain::updateScale()
{
    cpFloat factorX = _newScaleX / _scaleX;
    cpFloat factorY = _newScaleY / _scaleY;

    for (auto shape : _cpShapes)
    {
        cpVect a = cpSegmentShapeGetA(shape);
        a.x *= factorX;
        a.y *= factorY;
        cpVect b = cpSegmentShapeGetB(shape);
        b.x *= factorX;
        b.y *= factorY;
        cpSegmentShapeSetEndpoints(shape, a, b);
    }
    
    PhysicsShape::updateScale();
}
void PhysicsShapeEdgePolygon::updateScale()
{
    cpFloat factorX = PhysicsHelper::float2cpfloat(_newScaleX / _scaleX);
    cpFloat factorY = PhysicsHelper::float2cpfloat(_newScaleY / _scaleY);

    for (auto shape : _cpShapes)
    {
        cpVect a = cpSegmentShapeGetA(shape);
        a.x *= factorX;
        a.y *= factorY;
        cpVect b = cpSegmentShapeGetB(shape);
        b.x *= factorX;
        b.y *= factorY;
        cpSegmentShapeSetEndpoints(shape, a, b);
    }
    
    PhysicsShape::updateScale();
}
Beispiel #4
0
static void
update(int ticks)
{
	messageString[0] = '\0';
	
	cpVect start = cpvzero;
	cpVect end = /*cpv(0, 85);//*/mousePoint;
	cpVect lineEnd = end;
	
	{
		char infoString[1024];
		sprintf(infoString, "Query: Dist(%f) Point%s, ", cpvdist(start, end), cpvstr(end));
		strcat(messageString, infoString);
	}
	
	cpSegmentQueryInfo info = {};
	if(cpSpaceSegmentQueryFirst(space, start, end, CP_ALL_LAYERS, CP_NO_GROUP, &info)){
		cpVect point = cpSegmentQueryHitPoint(start, end, info);
		lineEnd = cpvadd(point, cpvzero);//cpvmult(info.n, 4.0f));
		
		char infoString[1024];
		sprintf(infoString, "Segment Query: Dist(%f) Normal%s", cpSegmentQueryHitDist(start, end, info), cpvstr(info.n));
		strcat(messageString, infoString);
	} else {
		strcat(messageString, "Segment Query (None)");
	}
	
	cpSegmentShapeSetEndpoints(querySeg, start, lineEnd);
	cpShapeCacheBB(querySeg); // force it to update it's collision detection data so it will draw
	
	// normal other stuff.
	int steps = 1;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		cpSpaceStep(space, dt);
	}
}
Beispiel #5
0
void wrSegmentShapeSetEndpoints(cpShape *shape, cpVect *a, cpVect *b) {
    cpSegmentShapeSetEndpoints(shape, *a, *b);
}
JNIEXPORT void JNICALL Java_com_wiyun_engine_chipmunk_Segment_setEndpoints
  (JNIEnv * env, jobject thiz, jfloat aX, jfloat aY, jfloat bX, jfloat bY) {
	cpShape* shape = (cpShape*)env->GetIntField(thiz, g_fid_Shape_mPointer);
	cpSegmentShapeSetEndpoints(shape, cpv(aX, aY), cpv(bX, bY));
}