Здравтсвуйте!!!
Помогите, пожалуйста, разобраться со следующим кодом:

Код:
function ProjCircle_Concave(x,y,oH,oV,obj,t) {
//if we're colliding diagonally:
// -if obj is in the diagonal pointed to by the slope normal: we can't collide, do nothing
// -else, collide vs. the appropriate vertex
//if obj is horiz OR very neighb in direction of slope: collide vs vert
//if obj is horiz or vert neigh against direction of slope: collide vs. face
var signx = t.signx;
var signy = t.signy;
if(oH == 0) {
if(oV == 0) {
//colliding with current tile
var ox = (t.pos.x + (signx*t.xw)) - obj.pos.x;
var oy = (t.pos.y + (signy*t.yw)) - obj.pos.y;
var twid = t.xw*2;
var trad = Math.sqrt(twid*twid + 0);
var len = Math.sqrt(ox*ox + oy*oy);
var pen = (len + obj.r) - trad;
if(0 < pen) {
//find the smallest axial projection vector
if(x < y) {
//penetration in x is smaller
lenP = x;
y = 0;
//get sign for projection along x-axis
if((obj.pos.x - t.pos.x) < 0) {
x *= -1;
}
}
else {
//penetration in y is smaller
lenP = y;
x = 0;
//get sign for projection along y-axis
if((obj.pos.y - t.pos.y)< 0) {
y *= -1;
}
}
if(lenP < pen) {
obj.ReportCollisionVsWorld(x,y,x/lenP, y/lenP, t);
return COL_AXIS;
}
else {
ox /= len;
oy /= len;
obj.ReportCollisionVsWorld(ox*pen, oy*pen, ox, oy, t);
return COL_OTHER;
}
}
else {
return COL_NONE;
}
}
else {
//colliding vertically
if((signy*oV) < 0) {
//colliding with face/edge
obj.ReportCollisionVsWorld(0,y*oV, 0, oV, t);
return COL_AXIS;
}
else {
var vx = t.pos.x - (signx*t.xw);
var vy = t.pos.y + (oV*t.yw);
var dx = obj.pos.x - vx;
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.r - len;
if(0 < pen) {
//vertex is in the circle; project outward
if(len == 0) {
//project out vertically
dx = 0;
dy = oV;
}
else {
dx /= len;
dy /= len;
}
obj.ReportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
return COL_OTHER;
}
}
}
}
else if(oV == 0) {
//colliding horizontally
if((signx*oH) < 0) {
//colliding with face/edge
obj.ReportCollisionVsWorld(x*oH, 0, oH, 0, t);
return COL_AXIS;
}
else {
//we could only be colliding vs the horizontal tip
//get diag vertex position
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y - (signy*t.yw);
var dx = obj.pos.x - vx;//calc vert->circle vector
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.r - len;
if(0 < pen) {
//vertex is in the circle; project outward
if(len == 0) {
//project out horizontally
dx = oH;
dy = 0;
}
else {
dx /= len;
dy /= len;
}
obj.ReportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
return COL_OTHER;
}
}
}
else {
//colliding diagonally
if( 0 < ((signx*oH) + (signy*oV)) ) {
//the dotprod of slope normal and cell offset is strictly positive,
//therefore obj is in the diagonal neighb pointed at by the normal, and
//it cannot possibly reach/touch/penetrate the slope
return COL_NONE;
}
else {
//collide vs. vertex
//get diag vertex position
var vx = t.pos.x + (oH*t.xw);
var vy = t.pos.y + (oV*t.yw);
var dx = obj.pos.x - vx;//calc vert->circle vector
var dy = obj.pos.y - vy;
var len = Math.sqrt(dx*dx + dy*dy);
var pen = obj.r - len;
if(0 < pen) {
//vertex is in the circle; project outward
if(len == 0) {
//project out by 45deg
dx = oH / Math.SQRT2;
dy = oV / Math.SQRT2;
}
else {
dx /= len;
dy /= len;
}
obj.ReportCollisionVsWorld(dx*pen, dy*pen, dx, dy, t);
return COL_OTHER;
}
}
}
return COL_NONE;
}