/* * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ import { Features } from "../../Collision/Features"; import { b2ConcaveArcShape } from "../../Collision/Shapes/b2ConcaveArcShape"; import { b2PolygonShape } from "../../Collision/Shapes/b2PolygonShape"; import { b2Shape } from "../../Collision/Shapes/b2Shape"; import { b2Collision } from "../../Collision/b2Collision"; import { b2Manifold } from "../../Collision/b2Manifold"; import { b2ManifoldPoint } from "../../Collision/b2ManifoldPoint"; import { b2Mat22, b2Math, b2Vec2 } from "../../Common/Math"; import { b2Body } from "../b2Body"; import { b2ContactListener } from "../b2ContactListener"; import { b2Contact } from "./b2Contact"; import { b2PolygonContact } from "./b2PolygonContact"; export class b2PolyAndConcaveArcContact extends b2PolygonContact { public static Create(shape1:b2Shape, shape2:b2Shape, allocator:any):b2Contact{ //void* mem = allocator->Allocate(sizeof(b2PolyContact)); return new b2PolyAndConcaveArcContact(shape1, shape2); } public static Destroy(contact:b2Contact, allocator:any): void{ //((b2PolyContact*)contact)->~b2PolyContact(); //allocator->Free(contact, sizeof(b2PolyContact)); } constructor(shape1:b2Shape, shape2:b2Shape){ super(shape1, shape2); } //~b2PolyContact() {} //Flash only: Allow variable sized manifold field private enlargeManifolds(l:number):void{ while(this.m_arcManifolds.length0) continue; var v2x:number = local.x-polyVx.x; var v2y:number = local.y-polyVx.y; //Get separation s = v2x*polyNormal.x+v2y*polyNormal.y; if(s>0) { maxEdge = -1; break; } if(s>maxS) { maxS = s; maxEdge = j; } } if(maxEdge!=-1) { polyNormal = poly.m_normals[maxEdge]; polyVx = poly.m_vertices[maxEdge]; var polyVx2:b2Vec2 = poly.m_vertices[maxEdge+1v2x*v2x+v2y*v2y){ maxEdge=-1; } } //Technically, we should check for the poly stabbing the wedge case as well //But this has problems about treating the wedge as infinite //Instead we do a cheaper test. It's not so much wrong as just different from PolyContact if(maxEdge!=-1) { arcLimitations[i] = maxEdge; if(i==0) { s = (polyVx2.x-local.x)*arcNormal2.x+(polyVx2.y-local.y)*arcNormal2.y; if(maxS0 ) } if(arcLimitations[1]!=-1) { l = arcLimitations[1]; topVx = poly.m_vertices[l]; bool1 = bool1 && ( (tVec.x-topVx.x)*poly.m_normals[l].y-(tVec.y-topVx.y)*poly.m_normals[l].x<0 ) } if(foundBlock&&!bool1) { //Make this loop the last, just incase it's autoapprove startVx = (currVx+direction) % poly.m_vertexCount; } if(bool1) foundBlock=true; //Test vs __^__ tVec = new b2Vec2(poly.m_vertices[currVx].x-localCenter.x,poly.m_vertices[currVx].y-localCenter.y); d2=tVec.x*tVec.x+tVec.y*tVec.y; d = Math.sqrt(d2); s1 = arc.m_radius-d; s2 = (poly.m_vertices[currVx].x-local0.x)*localNorm.x+(poly.m_vertices[currVx].y-local0.y)*localNorm.y; s = Math.max(s1,s2); arcSep = Math.min(arcSep, s); bool1 = bool1 && (s<0) if(bool1||currVx==autoApprove[0]||currVx==autoApprove[1]) { this.m_manifoldCount++; this.enlargeManifolds(this.m_manifoldCount); tMani=this.m_arcManifolds[this.m_manifoldCount-1]; tMani.pointCount=1; tPoint = tMani.points[0]; tPoint.id.features.incidentEdge = b2_nullFeature; tPoint.id.features.incidentVertex = currVx; tPoint.id.features.referenceEdge = 0; tPoint.id.features.flip = 0; tPoint.normalImpulse = 0; tPoint.tangentImpulse = 0; tVec.x /= d; tVec.y /= d; var tMat:b2Mat22 = b1.m_xf.R; tMani.normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y; tMani.normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y; tVec=poly.m_vertices[currVx]; //tVec=new b2Vec2(localCenter.x,localCenter.y);//Use this instead? tPoint.localPoint1.SetV(tVec); tPoint.localPoint2.SetV(b2Math.b2MulXT(b2.m_xf,b2Math.b2MulX(b1.m_xf,tVec))) tPoint.separation = arc.m_radius-d; } currVx = (currVx+direction) % poly.m_vertexCount; }while(currVx!=startVx) } var arcManiCount:number /** int */=this.m_manifoldCount; if(polySep>arcSep) { this.m_arcColl = false; this.m_manifoldCount = polyManiCount; //Match contact points for(i=0;i