public void ContainsTest2() { var a = new Box2D(0, 0, 1f, 1f); var b = new Box2D(0, 0, 1f, 1f); Assert.IsTrue(a.Contains(b)); }
internal Path(Winding winding, PixelRatio pixelRatio) { Winding = winding; _pixelRatio = pixelRatio; _bounds = new Box2D <float>(new Vector2D <float>(1e6f, 1e6f), new Vector2D <float>(-1e6f, -1e6f)); }
private void RenderCollision2D <T>(Type type) where T : Collider2D { T[] colliders = UnityEngine.Object.FindObjectsOfType <T>(); Color color = ColliderColor(type); AddToRenderList2D(colliders); switch (type) { case Type.Boxes: Box2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth)); Box2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth)); break; case Type.Spheres: Circle2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth)); Circle2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth)); break; case Type.Meshes: if (typeof(T) == typeof(EdgeCollider2D)) { Edge2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth)); Edge2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth)); } else { Mesh2D.Render(colliderList2D, color, EdgeAlpha, color, FaceAlpha, IsSet(Flags.NoDepth)); Mesh2D.Render(triggerList2D, triggerColor, EdgeAlpha, triggerColor, FaceAlpha, IsSet(Flags.NoDepth)); } break; } guiColliderCount[(int)type] += colliderList2D.Count + triggerList2D.Count; }
public Box2D GetBroadPhaseBox2D(Box2D box) { Box2D broadPhaseBox = new Box2D(); if (box.vx > 0) { // x broadPhaseBox.x = box.x; // w broadPhaseBox.width = (int)((box.vx * 1.0f) + box.width); } else { // x broadPhaseBox.x = box.x + (box.vx * 1.0f); // w broadPhaseBox.width = (int)(box.width - (box.vx * 1000.0f)); } if (box.vy > 0) { // y broadPhaseBox.y = box.y; // h broadPhaseBox.height = (int)((box.vy * 1.0f) + box.height); } else { // y broadPhaseBox.y = box.y + (box.vy * 1.0f); // h broadPhaseBox.height = (int)(box.height - (box.vy * 1.0f)); } return(broadPhaseBox); }
/// <summary> /// 计算位移碰撞 /// 计算出最大移动距离 /// 缺陷:速度1帧超过了碰撞器大小 无法验证 应该没有那么变态 /// </summary> /// <param name="box"></param> /// <param name="dir"></param> /// <param name="dst"></param> /// <param name="len"></param> /// <returns></returns> public bool isCollision(Box2D box, Vector2 dir, float dst, ref float len) { //copy一个出来 float offsetX = dir.x * dst; float offsetY = dir.y * dst; dyBox.OnlyUpdateCenter(box.centerX + offsetX, box.centerY + offsetY); dyBox.UpdateSize(box.width, box.height); len = dst; for (int i = 0; i < colliders.Count; i++) { //如果碰撞到了 计算当前box可以移动最远距离 if (Physics2D.isCollision(dyBox, colliders[i])) { if (dir.x != 0) { len = Math.Abs(box.centerX - colliders[i].centerX) - (box.width + colliders[i].width) / 2; } else { len = Math.Abs(box.centerY + box.height / 2 - colliders[i].centerY) - (box.height + colliders[i].height) / 2; } len -= 0.01f; return(true); } } return(false); }
/// Called for each fixture found in the query AABB. /// @return false to terminate the query. public override bool ReportFixture(Fixture fixture) { if (aabbs.Count == e_maxCount) { return(false); } Body body = fixture.Body; Shape shape = fixture.Shape; if (body.BodyType == BodyType.Static) { return(false); } bool overlap = Box2D.TestOverlap(shape, m_circle, body.Transform, m_transform); if (overlap) { //DrawFixture(fixture); //m_debugDraw.DrawAABB(fixture.AABB, new ColorF(1, 0, 0)); aabbs.Add(fixture.AABB); } return(true); }
private Box2D ComputeBestOutline() { Box2D cutOffCount = this.CutOffRatio * (float)this.TileCount; if (cutOffCount.DiagonalSize < 5f) { return(this.Cluster.Outline); } Histogram <TTile> histogram = new Histogram <TTile>((TTile item) => (double)item.Location.Center.Y, (double)this.parent.Boundary.Y, (double)this.parent.Boundary.Bottom, (double)this.parent.UnscaledTileSize.Y); Histogram <TTile> histogram2 = new Histogram <TTile>((TTile item) => (double)item.Location.Center.X, (double)this.parent.Boundary.X, (double)this.parent.Boundary.Right, (double)this.parent.UnscaledTileSize.X); foreach (TTile item2 in this.Tiles) { histogram.Add(item2); histogram2.Add(item2); } double verticalCutThreshold = (from bin in histogram.Bins select bin.Items.Count).Average() / 2.0; double horizontalCutThreshold = (from bin in histogram2.Bins select bin.Items.Count).Average() / 2.0; double ymin = histogram.ScanForRange((double)this.Cluster.Outline.Y, (double)this.Cluster.Outline.Bottom, (Bin <TTile> bin) => (double)bin.Items.Count, (double a, double v) => a + v, (double a, double v) => a >= (double)cutOffCount.Y || v > verticalCutThreshold); double ymax = histogram.ScanForRange((double)this.Cluster.Outline.Bottom, (double)this.Cluster.Outline.Y, (Bin <TTile> bin) => (double)bin.Items.Count, (double a, double v) => a + v, (double a, double v) => a >= (double)cutOffCount.Bottom || v > verticalCutThreshold); double xmin = histogram2.ScanForRange((double)this.Cluster.Outline.X, (double)this.Cluster.Outline.Right, (Bin <TTile> bin) => (double)bin.Items.Count, (double a, double v) => a + v, (double a, double v) => a >= (double)cutOffCount.X || v > horizontalCutThreshold); double xmax = histogram2.ScanForRange((double)this.Cluster.Outline.Right, (double)this.Cluster.Outline.X, (Bin <TTile> bin) => (double)bin.Items.Count, (double a, double v) => a + v, (double a, double v) => a >= (double)cutOffCount.Right || v > horizontalCutThreshold); Box2D result = new Box2D(xmin, ymin, xmax, ymax); return(result); }
public override void DrawSolidCircle(Box2D.Common.b2Vec2 center, float radius, Box2D.Common.b2Vec2 axis, Box2D.Common.b2Color color) { CCPoint centerToPoint = new CCPoint (center.x * 50f, center.y * 50f); //CCColor4B Color = new CCColor4B (color.r, color.g, color.b, 255); DrawNode.DrawCircle (centerToPoint, radius, CollusionColor); }
void FactoryViewer_MouseMove(object sender, MouseEventArgs e) { try { if (e.Button == MouseButtons.Left) { Point ptDiff = new Point(e.Location.X - _mousePositionPrev.X, e.Location.Y - _mousePositionPrev.Y); Box2D box = _picGraphics.DrawingBox; Vector2D centerScreen = new Vector2D( box.Center.X - (double)ptDiff.X * box.Width / ClientSize.Width , box.Center.Y + (double)ptDiff.Y * box.Height / ClientSize.Height); box.Center = centerScreen; _picGraphics.DrawingBox = box; Invalidate(); } _mousePositionPrev = e.Location; } catch (InvalidBoxException ex) { _log.Error(ex.ToString()); } catch (Exception ex) { _log.Error(ex.ToString()); } finally { } }
private void OnMouseMove(object sender, MouseEventArgs e) { SplitterPanel panel1 = splitContHorizLeft.Panel1; panel1.Focus(); try { if (e.Button == MouseButtons.Left) { Point ptDiff = new Point(e.Location.X - _mousePositionPrev.X, e.Location.Y - _mousePositionPrev.Y); double aspectRatio = 1.0; Box2D box = _picGraphics.DrawingBox; box.Center = new Vector2D( box.Center.X - ptDiff.X * box.Width / (double)panel1.ClientSize.Width , box.Center.Y + ptDiff.Y * box.Height / ((double)panel1.ClientSize.Height * aspectRatio)); _picGraphics.DrawingBox = box; panel1.Invalidate(); } _mousePositionPrev = e.Location; } catch (InvalidBoxException /*ex*/) { _computeBbox = true; } catch (Exception ex) { log.Debug(ex.ToString()); } finally { } }
// Start is called before the first frame update void Start() { Filter[] tab = (Filter[])System.Enum.GetValues(typeof(Filter)); dropdown.ClearOptions(); List <Dropdown.OptionData> optionList = new List <Dropdown.OptionData>(); foreach (var item in tab) { //string itemPrep = item.ToString().ToLowerInvariant().Replace('_',' '); optionList.Add(new Dropdown.OptionData(item.ToString())); } dropdown.AddOptions(optionList); slider.SetLimits(0, Hhaut * 2); slider.SetValues(Hbas, Hhaut); //slider.onValueChanged = ; //h saine (blackH) = 26 //h tour eiffel whiteH = 324 Box2D box = new Box2D(test.width, test.height); hf = new HeightField(test, box, Hbas, Hhaut); //meshView.CreateMeshFromsize(MAX_MESH_SIZE, MAX_MESH_SIZE);//255 max pour un mesh (yes merci les terrain qui marche mal) meshView.CreateMeshFromsize(test.width, test.height); //meshView.createBaseTest(); StartCoroutine("updateHeigth"); }
public static Vector2 UnrotatedOverlap(Box2D first, Box2D second) { var newFirst = new Box2D(first); newFirst.UndoOverlap(second); return(new Vector2(newFirst.MinX - first.MinX, newFirst.MinY - first.MinY)); }
public void Dimensions(ParameterStack stack, out double width, out double height, out double lengthCut, out double lengthFold) { // build factory PicFactory factory = new PicFactory(); Component.CreateFactoryEntities(factory, stack); if (ReflexionX) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionX)); } if (ReflexionY) { factory.ProcessVisitor(new PicVisitorTransform(Transform2D.ReflectionY)); } // get bounding box PicVisitorBoundingBox visitorBoundingBox = new PicVisitorBoundingBox(); factory.ProcessVisitor(visitorBoundingBox, ShowCotations ? PicFilter.FilterNone : !PicFilter.FilterCotation); Box2D box = visitorBoundingBox.Box; width = box.Width; height = box.Height; // get length PicVisitorDieCutLength visitorLength = new PicVisitorDieCutLength(); factory.ProcessVisitor(visitorLength, PicFilter.FilterNone); lengthCut = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CUT) ? visitorLength.Lengths[PicGraphics.LT.LT_CUT] : 0.0; lengthFold = visitorLength.Lengths.ContainsKey(PicGraphics.LT.LT_CREASING) ? visitorLength.Lengths[PicGraphics.LT.LT_CREASING] : 0.0; }
public override void BeginContact(Box2D.XNA.Contact contact) { base.BeginContact(contact); LaneVehicle v = null; Sprite ch = null; if (collisionObjA is LaneVehicle && collisionObjA.RootName == "laneChanger") { v = (LaneVehicle)collisionObjA; ch = collisionObjB; } else if (collisionObjB is LaneVehicle && collisionObjA.RootName == "laneChanger") { v = (LaneVehicle)collisionObjB; ch = collisionObjA; } if (v != null) { if (ch.Index == 0) { v.laneY = lanes[v.Lane.laneIndex - 1].yLocation + (lanes[v.Lane.laneIndex - 1].laneHeight - v.VisibleHeight) / 2f; } else { v.laneY = lanes[v.Lane.laneIndex + 1].yLocation + (lanes[v.Lane.laneIndex + 1].laneHeight - v.VisibleHeight) / 2f + v.VisibleHeight; } } }
public Box2D GetTileOutline(TileCoordinate coordinate) { int num = (int)coordinate.Index % this.WidthInTiles; int num2 = (int)coordinate.Index / this.WidthInTiles; return(Box2D.FromSize(this.Boundary.Min + this.UnscaledTileSize * new Vector2((float)num, (float)num2), this.UnscaledTileSize)); }
public void IntersectsTestNull() { var a = new Box2D(0, 0, 1, 1); var expectedA = new Box2D(a); a.Intersects(null); }
public RenderBoxComponent(Box2D box) : this( new PointF(box.MinX, box.MinY), new PointF(box.MinX, box.MaxY), new PointF(box.MaxX, box.MaxY), new PointF(box.MaxX, box.MinY)) { }
private static void DrawGridCells(IGameState state) { GL.LineWidth(5.0f); var deltaX = 2.0f / (float)state.GridWidth; var deltaY = 2.0f / (float)state.GridHeight; var cell = new Box2D(0, 0, deltaX, deltaY); for (int u = 0; u < state.GridWidth; ++u) { for (int v = 0; v < state.GridHeight; ++v) { cell.MinX = deltaX * u - 1f; cell.MinY = deltaY * v - 1f; switch (state[u, v]) { case FieldType.DIAMONT: DrawDiamont(cell); break; case FieldType.CROSS: DrawCross(cell); break; default: break; } } } }
public void IntersectsTest() { var box = new Box2D(0, 0, 1, 1); var circle = new Circle(1, 1, 1); Assert.IsTrue(box.Intersects(circle)); }
public ConstantMovement(Box2D frame, float absoluteTime, float speedX, float speedY) { this.SpeedX = speedX; this.SpeedY = speedY; this.Frame = frame; lastUpdate = absoluteTime; }
private static void FillVertices(Point2D[] arrVertices, Box2D box) { arrVertices[0] = new Point2D(box.Left, box.Top); arrVertices[1] = new Point2D(box.Right, box.Top); arrVertices[2] = new Point2D(box.Right, box.Bottom); arrVertices[3] = new Point2D(box.Left, box.Bottom); }
public bool Intersect(Box2D other) { if (m_radius == 0 || other.size_ == Vector2_.zero) { return(false); } var dx = Mathd.Abs(m_x - other.x); var dy = Mathd.Abs(m_y - other.y); if (dx > other.width * 0.5 + m_radius || dy > other.height * 0.5 + m_radius) { return(false); } if (dx <= other.width * 0.5 || dy <= other.height * 0.5) { return(true); } var hdx = (dx - other.width * 0.5); var hdy = (dy - other.height * 0.5); var dsq = hdx * hdx + hdy * hdy; return(dsq <= m_radius * m_radius); }
public void IntersectsTestNull() { var a = new Box2D(0, 0, 1, 1); var expectedA = new Box2D(a); IReadOnlyBox2Dextensions.Intersects(a, null); }
public void ContainsTest() { var box = new Box2D(0, 0, 1f, 1f); var point = new Vector2(0, 0); Assert.IsTrue(box.Contains(point)); }
public Box2D(Box2D rectangle) { this.X = rectangle.X; this.Y = rectangle.Y; this.SizeX = rectangle.SizeX; this.SizeY = rectangle.SizeY; }
internal override void DebugRender(Transform transform, bool isUiElement) { var transformedRect = new Box2D(Rect); transformedRect.TransformCenter(transform.GetTransformationMatrixCached(!isUiElement)); var p1 = new Vector2(transformedRect.MinX, transformedRect.MinY); var p2 = new Vector2(transformedRect.MinX, transformedRect.MaxY); var p3 = new Vector2(transformedRect.MaxX, transformedRect.MaxY); var p4 = new Vector2(transformedRect.MaxX, transformedRect.MinY); GL.LineWidth(1f); GL.Color4(Color.Red); GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(p1); GL.Vertex2(p2); GL.Vertex2(p3); GL.Vertex2(p4); GL.End(); GL.Begin(PrimitiveType.Lines); GL.Vertex2(p1); GL.Vertex2(p3); GL.Vertex2(p2); GL.Vertex2(p4); GL.End(); }
public void addBox(Box2D box) { if (!colliders.Contains(box)) { colliders.Add(box); } }
/// <summary> /// Checks if the box intersects this segment. /// </summary> /// <param name="box">The box to check.</param> /// <returns>True if it intersects, false if not.</returns> public bool Intersects(Box2D box) { if (!Box.Overlaps(box)) { return(false); } switch (Direction) { case SegmentDirection.Vertical: return(box.Min.X < Start.X && Start.X < box.Max.X); case SegmentDirection.Horizontal: return(box.Min.Y < Start.Y && Start.Y < box.Max.Y); case SegmentDirection.PositiveSlope: return(DifferentSides(box.TopLeft, box.BottomRight)); case SegmentDirection.NegativeSlope: return(DifferentSides(box.BottomLeft, box.TopRight)); default: throw new InvalidOperationException("Invalid box intersection direction enumeration"); } }
public Box2D GetTransformedRect() { var transformedRectCached = new Box2D(Rect); transformedRectCached.TransformCenter(GameObject.Transform.GetTransformationMatrixCached(true)); return(transformedRectCached); }
public void DrawScreen(Box2D clipFrame, uint points) { GL.Clear(ClearBufferMask.ColorBufferBit); GL.LoadIdentity(); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); if (!ReferenceEquals(null, clipFrame)) { foreach (IDrawable drawable in drawables) { if (clipFrame.Intersects(drawable.Rect)) { drawable.Draw(); } } } else { foreach (IDrawable drawable in drawables) { drawable.Draw(); } } Print(-0.15f, 0.0f, 0.0f, 0.04f, points.ToString()); GL.Disable(EnableCap.Blend); }
public void IntersectsTest4() { var box = new Box2D(0, 0, 1, 1); var circle = new Circle(2, 2, 1); Assert.IsFalse(box.Intersects(circle)); }
public void ChangeFieldSize(Graphics graphics, Box2D box) { gdiPainter.Graph = graphics; if (field != null) { field.ChangeBox(box); } }
public override void BeginContact(Box2D.Dynamics.Contacts.b2Contact contact) { if (contact.FixtureA.Body.UserData == bird || contact.FixtureB.Body.UserData == bird) { SimpleAudioEngine.sharedEngine().playEffect(@"musics/sfx_hit"); //游戏结束 ((GameScene)scene).GameOver(); } }
public override void DrawSolidPolygon(Box2D.Common.b2Vec2[] vertices, int vertexCount, Box2D.Common.b2Color color) { CCPoint[] verticesToPoint = new CCPoint[vertexCount]; CCColor4B Color = new CCColor4B (color.r, color.g, color.b, 255); for (int i = 0; i < vertexCount; i++) { verticesToPoint [i] = new CCPoint (vertices [i].x * 50f, vertices [i].y * 50f); } DrawNode.DrawPolygon (verticesToPoint, vertexCount, Color, 3f, Color); }
private void processImage(Bgr<byte>[,] frame, out Gray<byte>[,] probabilityMap, out Rectangle prevSearchArea, out Box2D foundBox) { prevSearchArea = searchArea; //convert to HSV var hsvImg = frame.ToHsv(); //back-project ratio hist => create probability map probabilityMap = ratioHist.BackProject(hsvImg.SplitChannels<Hsv<byte>, byte>(0, 1)); //or new Image<Gray<byte>>[]{ hsvImg[0], hsvImg[1]...} //user constraints... Gray<byte>[,] mask = hsvImg.InRange(new Hsv<byte>(0, 0, (byte)minV), new Hsv<byte>(0, 0, (byte)maxV), Byte.MaxValue, 2); probabilityMap.AndByte(mask, inPlace:true); //run Camshift algorithm to find new object position, size and angle foundBox = Camshift.Process(probabilityMap, searchArea); var foundArea = Rectangle.Round(foundBox.GetMinArea()); searchArea = foundArea.Inflate(0.05, 0.05, frame.Size()); //inflate found area for search (X factor)... if (searchArea.IsEmpty) isROISelected = false; //reset tracking }
public override void DrawSegment(Box2D.Common.b2Vec2 p1, Box2D.Common.b2Vec2 p2, Box2D.Common.b2Color color) { throw new NotImplementedException (); }
public override void PreSolve(Box2D.Dynamics.Contacts.b2Contact contact, Box2D.Collision.b2Manifold oldManifold) { //throw new NotImplementedException(); }
public override void PostSolve(Contact contact, ref Box2D.XNA.ContactImpulse impulse) { float intensity = impulse.normalImpulses[0] / 2800F; //intensity = Math.Min(1F, intensity); if (intensity > 0.20F) { Camera.Shake(intensity); OnShake(contact, intensity); } base.PostSolve(contact, ref impulse); }
public override void DrawTransform(Box2D.Common.b2Transform xf) { throw new NotImplementedException (); }
public override void Step(Box2D.XNA.TestBed.Framework.Settings settings) { base.Step(settings); _debugDraw.DrawString(5, _textLine, "This tests various character collision shapes"); _textLine += 15; }
public bool Inside(Box2D rectangle) { if (X < rectangle.X) return false; if (MaxX > rectangle.MaxX) return false; if (Y < rectangle.Y) return false; if (MaxY > rectangle.MaxY) return false; return true; }
public override void PreSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref Box2D.Collision.b2Manifold oldManifold) { b2Manifold manifold = contact.GetManifold(); if (manifold.pointCount == 0) { return; } b2Fixture fixtureA = contact.GetFixtureA(); b2Fixture fixtureB = contact.GetFixtureB(); b2PointState[] state1 = new b2PointState[b2Settings.b2_maxManifoldPoints]; b2PointState[] state2 = new b2PointState[b2Settings.b2_maxManifoldPoints]; b2Collision.b2GetPointStates(state1, state2, ref oldManifold, ref manifold); b2WorldManifold worldManifold = new b2WorldManifold(); contact.GetWorldManifold(ref worldManifold); for (int i = 0; i < manifold.pointCount && m_pointCount < k_maxContactPoints; ++i) { ContactPoint cp = m_points[m_pointCount]; cp.fixtureA = fixtureA; cp.fixtureB = fixtureB; cp.position = worldManifold.points[i]; cp.normal = worldManifold.normal; cp.state = state2[i]; m_points[m_pointCount] = cp; ++m_pointCount; } }
public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse) { //throw new NotImplementedException(); }
public override void EndContact(Box2D.Dynamics.Contacts.b2Contact contact) { if (contact.FixtureA.UserData != null && contact.FixtureB.UserData != null) { switch ((WorldFixtureData)contact.FixtureA.UserData) { case WorldFixtureData.playergroundsensor: if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.platform) { playerGroundBody = null; playerGround = WorldFixtureData.air; } else if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.jumppad) { playerGroundJumpPad = null; playerGround = WorldFixtureData.air; } else { playerGround = WorldFixtureData.air; } break; case WorldFixtureData.playerleftsensor: WallContact = Direction.None; break; case WorldFixtureData.playerrightsensor: WallContact = Direction.None; break; default: switch ((WorldFixtureData)contact.FixtureB.UserData) { case WorldFixtureData.playergroundsensor: if ((WorldFixtureData)contact.FixtureA.UserData == WorldFixtureData.platform) { playerGroundBody = null; playerGround = WorldFixtureData.air; } else if ((WorldFixtureData)contact.FixtureA.UserData == WorldFixtureData.jumppad) { playerGroundJumpPad = null; playerGround = WorldFixtureData.air; } else { playerGround = WorldFixtureData.air; } break; case WorldFixtureData.playerleftsensor: WallContact = Direction.None; break; case WorldFixtureData.playerrightsensor: WallContact = Direction.None; break; } break; } if ((WorldFixtureData)contact.FixtureA.UserData == WorldFixtureData.playergroundsensor && (WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.platform || (WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.playergroundsensor && (WorldFixtureData)contact.FixtureA.UserData == WorldFixtureData.platform) { } else if ((WorldFixtureData)contact.FixtureA.UserData == WorldFixtureData.playergroundsensor || (WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.playergroundsensor) { } } }
public override void BeginContact(Box2D.Dynamics.Contacts.b2Contact contact) { base.BeginContact (contact); if (contact.FixtureA.UserData != null && contact.FixtureB.UserData != null) { switch ((WorldFixtureData)contact.FixtureA.UserData) { case WorldFixtureData.playergroundsensor: switch ((WorldFixtureData)contact.FixtureB.UserData) { case WorldFixtureData.ground: playerGround = WorldFixtureData.ground; break; case WorldFixtureData.platform: playerGround = WorldFixtureData.platform; playerGroundBody = contact.FixtureB.Body; break; case WorldFixtureData.jumppad: playerGround = WorldFixtureData.jumppad; playerGroundJumpPad = gameContainer.jumpPadContainer.First (search => search.JumpPadBody.Position == contact.FixtureB.Body.Position); break; default: playerGround = WorldFixtureData.air; break; } break; case WorldFixtureData.playerleftsensor: if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.ground) { WallContact = Direction.Left; } else { WallContact = Direction.None; } break; case WorldFixtureData.playerrightsensor: if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.ground) { WallContact = Direction.Right; } else { WallContact = Direction.None; } break; default: switch ((WorldFixtureData)contact.FixtureB.UserData) { case WorldFixtureData.playergroundsensor: switch ((WorldFixtureData)contact.FixtureA.UserData) { case WorldFixtureData.ground: playerGround = WorldFixtureData.ground; break; case WorldFixtureData.platform: playerGround = WorldFixtureData.platform; playerGroundBody = contact.FixtureA.Body; break; case WorldFixtureData.jumppad: playerGround = WorldFixtureData.jumppad; playerGroundJumpPad = gameContainer.jumpPadContainer.First (search => search.JumpPadBody.Position == contact.FixtureB.Body.Position); break; default: playerGround = WorldFixtureData.air; break; } break; case WorldFixtureData.playerleftsensor: if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.ground) { WallContact = Direction.Left; } else { WallContact = Direction.None; } break; case WorldFixtureData.playerrightsensor: if ((WorldFixtureData)contact.FixtureB.UserData == WorldFixtureData.ground) { WallContact = Direction.Right; } else { WallContact = Direction.None; } break; } break; } } }
public bool Intersects(Box2D rectangle) { if (null == rectangle) return false; bool noXintersect = (MaxX < rectangle.X) || (X > rectangle.MaxX); bool noYintersect = (MaxY < rectangle.Y) || (Y > rectangle.MaxY); return !(noXintersect || noYintersect); }
public static Box2D CreateFromCenterSize(float centerX, float centerY, float sizeX, float sizeY) { var rectangle = new Box2D(0, 0, sizeX, sizeY); rectangle.CenterX = centerX; rectangle.CenterY = centerY; return rectangle; }
public override void PreSolve(b2Contact contact, Box2D.Collision.b2Manifold oldManifold) { }
private void trackOneStep(Bgr<byte>[,] frame, out Gray<byte>[,] probabilityMap, out Box2D foundBox) { const float SEARCH_AREA_INFLATE_FACTOR = 0.05f; /**************************** KALMAN predict **************************/ kalman.Predict(); searchArea = createRect(kalman.State.Position, searchArea.Size, frame.Size()); /**************************** KALMAN predict **************************/ trackCamshift(frame, searchArea, out probabilityMap, out foundBox); if (!foundBox.IsEmpty) { /**************************** KALMAN correct **************************/ kalman.Correct(new PointF(foundBox.Center.X, foundBox.Center.Y)); //correct predicted state by measurement /**************************** KALMAN correct **************************/ var foundArea = Rectangle.Round(foundBox.GetMinArea()); searchArea = foundArea.Inflate(SEARCH_AREA_INFLATE_FACTOR, SEARCH_AREA_INFLATE_FACTOR, frame.Size()); //inflate found area for search (X factor)... nonVisibleCount = 0; } else { nonVisibleCount++; if (nonVisibleCount == 1) //for the first time { searchArea = searchArea.Inflate(-SEARCH_AREA_INFLATE_FACTOR * 1.5, -SEARCH_AREA_INFLATE_FACTOR * 1.5, frame.Size()); //shrink (hysteresis) } searchArea = createRect(kalman.State.Position, searchArea.Size, frame.Size()); } if (nonVisibleCount > 100) //if not visible for a longer time => reset tracking { nonVisibleCount = 0; isROISelected = false; } }
public override void Step(Box2D.XNA.TestBed.Framework.Settings settings) { bool advanceRay = settings.pause == 0 || settings.singleStep != 0; base.Step(settings); _debugDraw.DrawString(5, _textLine, "Press 1-5 to drop stuff"); _textLine += 15; float L = 25.0f; Vector2 point1 = new Vector2(0.0f, 10.0f); Vector2 d = new Vector2(L * (float)Math.Cos(_angle), -L * Math.Abs((float)Math.Sin(_angle))); Vector2 point2 = point1 + d; _world.RayCast((fixture, point, normal, fraction) => { _fixture = fixture; _point = point; _normal = normal; return fraction; }, point1, point2); if (_fixture != null) { _debugDraw.DrawPoint(_point, .5f, new Color(0.4f, 0.9f, 0.4f)); _debugDraw.DrawSegment(point1, _point, new Color(0.8f, 0.8f, 0.8f)); Vector2 head = _point + 0.5f * _normal; _debugDraw.DrawSegment(_point, head, new Color(0.9f, 0.9f, 0.4f)); } else { _debugDraw.DrawSegment(point1, point2, new Color(0.8f, 0.8f, 0.8f)); } if (advanceRay) { _angle += 0.25f * (float)Math.PI / 180.0f; } }
private void trackCamshift(Bgr<byte>[,] frame, Rectangle searchArea, out Gray<byte>[,] probabilityMap, out Box2D foundBox) { const int PROBABILITY_MIN_VAL = (int)(0.3f * Byte.MaxValue); //convert to HSV var hsvImg = frame.ToHsv(); //back-project ratio hist => create probability map probabilityMap = ratioHist.BackProject(hsvImg.SplitChannels<Hsv<byte>, byte>(0, 1)); //or new Image<Gray<byte>>[]{ hsvImg[0], hsvImg[1]...} //user constraints... Gray<byte>[,] mask = hsvImg.InRange(new Hsv<byte>(0, 0, (byte)minV), new Hsv<byte>(0, 0, (byte)maxV), Byte.MaxValue, 2); probabilityMap.AndByte(mask, inPlace: true); //run Camshift algorithm to find new object position, size and angle CentralMoments centralMoments; foundBox = Camshift.Process(probabilityMap, searchArea, Meanshift.DEFAULT_TERM, out centralMoments); //stopping conditions float avgIntensity = centralMoments.Mu00 / (foundBox.Size.Area() + Single.Epsilon); if (avgIntensity < PROBABILITY_MIN_VAL || foundBox.Size.IsEmpty || foundBox.Size.Height < 12) { foundBox = Box2D.Empty; //invalid box } }
public override void PreSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref Box2D.Collision.b2Manifold oldManifold) { }
public override void Step(Box2D.XNA.TestBed.Framework.Settings settings) { ContactManager cm = _world.GetContactManager(); int height = cm._broadPhase.ComputeHeight(); int leafCount = cm._broadPhase.ProxyCount; int minimumNodeCount = 2 * leafCount - 1; float minimumHeight = (float)(Math.Ceiling(Math.Log((double)minimumNodeCount) / Math.Log(2.0))); _debugDraw.DrawString(5, _textLine, string.Format("dynamic tree height = {0}, min = {1}", height, minimumHeight)); _textLine += 15; base.Step(settings); }
public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse) { }
public override void PostSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref b2ContactImpulse impulse) { // CCLog.Log("Post solve: {0} vs {1}", contact.FixtureA.Body.BodyType, contact.FixtureB.Body.BodyType); }
public override void PreSolve(Box2D.Dynamics.Contacts.b2Contact contact, ref Box2D.Collision.b2Manifold oldManifold) { // CCLog.Log("Pre solve: {0} vs {1}", contact.FixtureA.Body.BodyType, contact.FixtureB.Body.BodyType); if (contact.FixtureA.Body.BodyType == contact.FixtureB.Body.BodyType) { contact.FixtureB.Body.World.Dump(); } }