Beispiel #1
0
        private PPolygonPolygonCollider.PWContactedVertex [] GetEdgeOfPotentialCollision(
            PConvexPolygonShape p1, PConvexPolygonShape p2, int r1edge,
            bool flip)
        {
            PPolygonPolygonCollider.PWContactedVertex [] line = new PPolygonPolygonCollider.PWContactedVertex [2];
            Vector2f normal  = p1.nors[r1edge];
            float    dist    = 1.0F;
            int      ver     = -1;
            int      nextVer = -1;

            for (int i = 0; i < p2.numVertices; i++)
            {
                float dot = normal.Dot(p2.nors[i]);
                if (dot < dist || dist == 1.0F)
                {
                    dist    = dot;
                    ver     = i;
                    nextVer = (i + 1) % p2.numVertices;
                }
            }

            line[0] = new PPolygonPolygonCollider.PWContactedVertex();
            line[0].v.Set(p2.vers[ver].x, p2.vers[ver].y);
            line[0].data.Set(r1edge + ver * 2 + ver * 4, false);
            line[1] = new PPolygonPolygonCollider.PWContactedVertex();
            line[1].v.Set(p2.vers[nextVer].x, p2.vers[nextVer].y);
            line[1].data.Set(r1edge + ver * 2 + nextVer * 4, false);
            return(line);
        }
Beispiel #2
0
 public virtual PPolygonPolygonCollider.PWContactedVertex  Clone()
 {
     PPolygonPolygonCollider.PWContactedVertex cv = new PPolygonPolygonCollider.PWContactedVertex();
     cv.v    = v.Clone();
     cv.data = data.Clone();
     return(cv);
 }
		private PPolygonPolygonCollider.PWContactedVertex [] ClipEdge(PPolygonPolygonCollider.PWContactedVertex [] clips,
				Vector2f normal, float dist) {
			PPolygonPolygonCollider.PWContactedVertex [] line = new PPolygonPolygonCollider.PWContactedVertex [2];
			int numClips = 0;
			float dist0 = normal.Dot(clips[0].v) - dist;
			float dist1 = normal.Dot(clips[1].v) - dist;
			if (dist0 < 0.0F) {
				line[numClips] = clips[0];
				numClips++;
			}
			if (dist1 < 0.0F) {
				line[numClips] = clips[1];
				numClips++;
			}
			if (numClips == 0)
				return null;
			if (numClips == 2)
				return line;
			int c = 0;
			if (dist0 < 0.0F && dist1 > 0.0F)
				c = 1;
			float d = dist0 / (dist0 - dist1);
			line[1] = new PPolygonPolygonCollider.PWContactedVertex ();
			line[1].v = clips[1].v.Sub(clips[0].v).Clone();
			line[1].v.MulLocal(d);
			line[1].v.AddLocal(clips[0].v);
			line[1].data = clips[c].data;
			return line;
		}
Beispiel #4
0
        private PPolygonPolygonCollider.PWContactedVertex [] ClipEdge(PPolygonPolygonCollider.PWContactedVertex [] clips,
                                                                      Vector2f normal, float dist)
        {
            PPolygonPolygonCollider.PWContactedVertex [] line = new PPolygonPolygonCollider.PWContactedVertex [2];
            int   numClips = 0;
            float dist0    = normal.Dot(clips[0].v) - dist;
            float dist1    = normal.Dot(clips[1].v) - dist;

            if (dist0 < 0.0F)
            {
                line[numClips] = clips[0];
                numClips++;
            }
            if (dist1 < 0.0F)
            {
                line[numClips] = clips[1];
                numClips++;
            }
            if (numClips == 0)
            {
                return(null);
            }
            if (numClips == 2)
            {
                return(line);
            }
            int c = 0;

            if (dist0 < 0.0F && dist1 > 0.0F)
            {
                c = 1;
            }
            float d = dist0 / (dist0 - dist1);

            line[1]   = new PPolygonPolygonCollider.PWContactedVertex();
            line[1].v = clips[1].v.Sub(clips[0].v).Clone();
            line[1].v.MulLocal(d);
            line[1].v.AddLocal(clips[0].v);
            line[1].data = clips[c].data;
            return(line);
        }
		private PPolygonPolygonCollider.PWContactedVertex [] GetEdgeOfPotentialCollision(
				PConvexPolygonShape p1, PConvexPolygonShape p2, int r1edge,
				bool flip) {
			PPolygonPolygonCollider.PWContactedVertex [] line = new PPolygonPolygonCollider.PWContactedVertex [2];
			Vector2f normal = p1.nors[r1edge];
			float dist = 1.0F;
			int ver = -1;
			int nextVer = -1;
			for (int i = 0; i < p2.numVertices; i++) {
				float dot = normal.Dot(p2.nors[i]);
				if (dot < dist || dist == 1.0F) {
					dist = dot;
					ver = i;
					nextVer = (i + 1) % p2.numVertices;
				}
			}
	
			line[0] = new PPolygonPolygonCollider.PWContactedVertex ();
			line[0].v.Set(p2.vers[ver].x, p2.vers[ver].y);
			line[0].data.Set(r1edge + ver * 2 + ver * 4, false);
			line[1] = new PPolygonPolygonCollider.PWContactedVertex ();
			line[1].v.Set(p2.vers[nextVer].x, p2.vers[nextVer].y);
			line[1].data.Set(r1edge + ver * 2 + nextVer * 4, false);
			return line;
		}
			public virtual PPolygonPolygonCollider.PWContactedVertex  Clone() {
				PPolygonPolygonCollider.PWContactedVertex  cv = new PPolygonPolygonCollider.PWContactedVertex ();
				cv.v = v.Clone();
				cv.data = data.Clone();
				return cv;
			}