Здравствуйте, такой вопрос: сделал разрезание тел, но мне нужно чтобы не просто тела резались, а сохранялись соединения разрезанного тела, например два тела скреплены PivotJoint одно из них я режу, и надо сделать так чтобы Один из кусков имел соединение PivotJoint.
Код AS3:
private function cut():void
{
var ray:Ray = new Ray(_sPoint, Vec2.fromPolar(1, AntMath.angle(_sPoint.x, _sPoint.y, _ePoint.x, _ePoint.y)));
var rayResults:RayResultList = space.rayMultiCast(ray, true);
if (rayResults.length > 1)
{
var polygon:Polygon = rayResults.at(0).shape as Polygon;
if (polygon != null)
{
var pt0:Vec2 = ray.at(rayResults.at(0).distance);
var pt1:Vec2 = null;
for (var i:int = 1; i < rayResults.length; ++i)
{
if (rayResults.at(i).shape == polygon)
{
pt1 = ray.at(rayResults.at(i).distance);
break;
}
}
if (pt1 != null)
{
var normal:Vec2 = new Vec2( -(pt1.y - pt0.y), pt1.x - pt0.x);
var vertN:int = polygon.worldVerts.length;
function side(n:int):Boolean
{
return normal.dot(polygon.worldVerts.at(n).sub(pt0)) > 0;
}
//find first vertice over pt0-pt1
//iterate while vertices are over
for (i = 0; side(i) == true; i = (i + 1) % vertN) {}
//iterate while vertices are below, stop when vertice is again over
for (; side(i) == false; i = (i + 1) % vertN) {}
//get distance from pt0 and from pt1 to edge (i)-(i-1). intersection0 - current intersection, intersection1 - next intersection
var distPt0:Number = Math.abs(polygon.worldVerts.at(i).sub(pt0).dot(polygon.edges.at((i - 1 + vertN) % vertN).worldNormal));
var distPt1:Number = Math.abs(polygon.worldVerts.at(i).sub(pt1).dot(polygon.edges.at((i - 1 + vertN) % vertN).worldNormal));
var intersection0:Vec2;
var intersection1:Vec2;
if (distPt0 < distPt1)
{
intersection0 = pt0;
intersection1 = pt1;
}
else
{
intersection0 = pt1;
intersection1 = pt0;
}
var b:Body = polygon.body;
//create slices
for (var n:int = 0; n < 2; ++n)
{
var verts:Array = [n == 0 ? intersection0 : intersection1];
for (; side(i) == (n == 0); i = (i + 1) % vertN)
verts.push(polygon.worldVerts.at(i));
verts.push(n == 0 ? intersection1 : intersection0);
var newB:Body = new Body(BodyType.DYNAMIC);
newB.shapes.add(new Polygon(verts, polygon.material, polygon.filter));
newB.align();
newB.space = space;
}
for (var i:int = 0; i < b.constraints.length; i++)
{
b.constraints.at(0).space = null;
}
polygon.body.space = null;
}
}
}
}