Thanks kne!
I Really appreciated that! I Start your port to the actual Box2D - Cocos2D version! Soon as get ready i share here!
By now, i never work with pyton, so i get some problems to understand your port! can u help me with that?
What is the hitLoc1 in this function?
hitLoc1 = (1-lambda_)*segment1.p1+lambda_*segment1.p2
By now, i have the first user input and the last stored in a array:
Code:
-(void)cutBodyes
{
CGPoint firstLocation = CGPointFromString([arrTouches objectAtIndex:0]);
CGPoint secondLocation = CGPointFromString([arrTouches objectAtIndex:1]);
firstLocation.x = firstLocation.x/PTM_RATIO;
firstLocation.y = firstLocation.y/PTM_RATIO;
secondLocation.x = secondLocation.x/PTM_RATIO;
secondLocation.y = secondLocation.y/PTM_RATIO;
b2Vec2 firstPoint(firstLocation.x, firstLocation.y);
b2Vec2 secondPoint(secondLocation.x, secondLocation.y);
RayCastMultipleCallback callback;
world->RayCast(&callback ,firstPoint, secondPoint);
}
I Have a list of all hitting bodies between this 2 points:
Code:
for(int i = 0; i< callback.m_count;i++)
{
b2Body* tryBody = callback.m_body[i];
}
Follow the path you follow!
I get the In point of Colision and Out point of colision:
Code:
// Get the Callback from In to Out
RayCastMultipleCallback callbackIn;
world->RayCast(&callbackIn ,firstPoint, secondPoint);
// Get the Callback from Out to Ind
RayCastMultipleCallback callbackOut;
world->RayCast(&callbackOut ,secondPoint, firstPoint);
fb2Body *tryBody = callbackIn.m_body[i];
b2Vec2 inPointOfColision = callbackIn.m_points[i];
b2Vec2 outPointOfColision = callbackOut.m_points[((callbackOut.m_count-1)-i)];
//NSLog(@"Actual %i Reverse: %i",i,((callbackOut.m_count-1)-i));
//NSLog(@"In at x:%f y:%f Exit at: x:%f y:%f",inPointOfColision.x,inPointOfColision.y,outPointOfColision.x,outPointOfColision.y);
b2Vec2 localInPoint = tryBody->GetLocalPoint(inPointOfColision);
b2Vec2 localOutPoint = tryBody->GetLocalPoint(outPointOfColision);
Ok, now i must create 2 objects!
I get stuck on this part now =/
Code:
for(int i = 0; i< callbackIn.m_count;i++)
{
b2Body *tryBody = callbackIn.m_body[i];
b2Vec2 inPointOfColision = callbackIn.m_points[i];
b2Vec2 outPointOfColision = callbackOut.m_points[((callbackOut.m_count-1)-i)];
//NSLog(@"Actual %i Reverse: %i",i,((callbackOut.m_count-1)-i));
//NSLog(@"In at x:%f y:%f Exit at: x:%f y:%f",inPointOfColision.x,inPointOfColision.y,outPointOfColision.x,outPointOfColision.y);
b2Vec2 localInPoint = tryBody->GetLocalPoint(inPointOfColision);
b2Vec2 localOutPoint = tryBody->GetLocalPoint(outPointOfColision);
b2PolygonShape* bodyShape = (b2PolygonShape *)tryBody->GetFixtureList()->GetShape();
int verticeCount = bodyShape->GetVertexCount();
int cutAdded[2] = {0,0};
int last = -1;
b2Vec2 vertex1[4];
int vertex1Count = 0;
b2Vec2 vertex2[4];
int vertex2Count = 0;
b2PolygonShape newSquare[2];
for(int v = 0; v < verticeCount; v++)
{
int n = -1;
b2Vec2 targetVertice = bodyShape->GetVertex(v);
if(b2Dot(b2Cross(localOutPoint - localInPoint, 1), targetVertice-localInPoint))
{
n = 0;
}
else
{
n = 1;
}
if(last != n)
{
if(last == 0)
{
cutAdded[0] = 1;
vertex1[vertex1Count] = localOutPoint;
vertex1Count++;
vertex1[vertex1Count] = localInPoint;
vertex1Count++;
}
else if(last == 1)
{
cutAdded[last] = 1;
vertex2[vertex2Count] = localInPoint;
vertex2Count++;
vertex2[vertex2Count] = localOutPoint;
vertex2Count++;
}
}
}
}