Inheritance: IDisposable
Beispiel #1
0
 public void OnContact(Box2DX.Collision.Shape other, ContactPoint point)
 {
     if (!collisionShapes.Contains(other))
     {
         collisionShapes.Add(other);
     }
 }
Beispiel #2
0
		public ShapeEditing()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);

				Body ground = _world.CreateBody(bd);
				ground.CreateShape(sd);
			}

			BodyDef bodydef = new BodyDef();
			bodydef.Position.Set(0.0f, 10.0f);
			_body = _world.CreateBody(bodydef);

			PolygonDef sd_ = new PolygonDef();
			sd_.SetAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f);
			sd_.Density = 10.0f;
			_shape1 = _body.CreateShape(sd_);
			_body.SetMassFromShapes();

			_shape2 = null;
		}
Beispiel #3
0
		public PolygonContact(Shape s1, Shape s2)
			: base(s1, s2)
		{
			Box2DXDebug.Assert(_shape1.GetType() == ShapeType.PolygonShape);
			Box2DXDebug.Assert(_shape2.GetType() == ShapeType.PolygonShape);
			_manifold.PointCount = 0;
		}
Beispiel #4
0
 public PolyAndCircleContact(Shape s1, Shape s2)
     : base(s1, s2)
 {
     Box2DXDebug.Assert(this._shape1.GetType() == ShapeType.PolygonShape);
     Box2DXDebug.Assert(this._shape2.GetType() == ShapeType.CircleShape);
     this._manifold.PointCount = 0;
 }
Beispiel #5
0
		public DistanceTest()
		{
			PolygonDef sd = new PolygonDef();
			sd.SetAsBox(1.0f, 1.0f);
			sd.Density = 0.0f;

			BodyDef bd = new BodyDef();
			bd.Position.Set(0.0f, 10.0f);
			_body1 = _world.CreateBody(bd);
			_shape1 = _body1.CreateShape(sd);

			PolygonDef sd2 = new PolygonDef();
			sd2.VertexCount = 3;
			sd2.Vertices[0].Set(-1.0f, 0.0f);
			sd2.Vertices[1].Set(1.0f, 0.0f);
			sd2.Vertices[2].Set(0.0f, 15.0f);
			sd2.Density = 1.0f;

			BodyDef bd2 = new BodyDef();

			bd2.Position.Set(0.0f, 10.0f);

			_body2 = _world.CreateBody(bd2);
			_shape2 = _body2.CreateShape(sd2);
			_body2.SetMassFromShapes();

			_world.Gravity = new Vec2(0.0f, 0.0f);
		}
Beispiel #6
0
		public override void Keyboard(System.Windows.Forms.Keys key)
		{
			switch (key)
			{
				case System.Windows.Forms.Keys.C:
					if (_shape2 == null)
					{
						CircleDef sd = new CircleDef();
						sd.Radius = 3.0f;
						sd.Density = 10.0f;
						sd.LocalPosition.Set(0.5f, -4.0f);
						_shape2 = _body.CreateShape(sd);
						_body.SetMassFromShapes();
						_body.WakeUp();
					}
					break;

				case System.Windows.Forms.Keys.D:
					if (_shape2 != null)
					{
						_body.DestroyShape(_shape2);
						_shape2 = null;
						_body.SetMassFromShapes();
						_body.WakeUp();
					}
					break;
			}
		}
Beispiel #7
0
		public TimeOfImpact()
		{
			{
				PolygonDef sd = new PolygonDef();
				sd.Density = 0.0f;

				sd.SetAsBox(0.1f, 10.0f, new Vec2(10.0f, 0.0f), 0.0f);

				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, 20.0f);
				bd.Angle = 0.0f;
				_body1 = _world.CreateBody(bd);
				_shape1 = _body1.CreateShape(sd);
			}

			{
				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(0.25f, 0.25f);
				sd.Density = 1.0f;

				BodyDef bd = new BodyDef();
				bd.Position.Set(9.6363468f, 28.050615f);
				bd.Angle = 1.6408679f;
				_body2 = _world.CreateBody(bd);
				_shape2 = (PolygonShape)_body2.CreateShape(sd);
				_body2.SetMassFromShapes();
			}
		}
 /// <summary>
 /// Return true if the given shape should be considered for ray intersection.
 /// </summary>
 public bool RayCollide(object userData, Shape shape)
 {
     //By default, cast userData as a shape, and then collide if the shapes would collide
     if (userData == null)
         return true;
     return ShouldCollide((Shape)userData, shape);
 }
Beispiel #9
0
 public Fixture()
 {
     UserData = null;
     Body = null;
     _next = null;
     ProxyId = BroadPhase.NullProxy;
     Shape = null;
 }
Beispiel #10
0
 public CircleContact(Shape s1, Shape s2)
     : base(s1, s2)
 {
     Box2DXDebug.Assert(this._shape1.GetType() == ShapeType.CircleShape);
     Box2DXDebug.Assert(this._shape2.GetType() == ShapeType.CircleShape);
     this._manifold.PointCount = 0;
     this._manifold.Points[0].NormalImpulse = 0f;
     this._manifold.Points[0].TangentImpulse = 0f;
 }
Beispiel #11
0
		/// <summary>
		/// Return true if contact calculations should be performed between these two shapes.
		/// If you implement your own collision filter you may want to build from this implementation.
		/// @warning for performance reasons this is only called when the AABBs begin to overlap.
		/// </summary>
		public virtual bool ShouldCollide(Shape shape1, Shape shape2)
		{
			FilterData filter1 = shape1.FilterData;
			FilterData filter2 = shape2.FilterData;

			if (filter1.GroupIndex == filter2.GroupIndex && filter1.GroupIndex != 0)
			{
				return filter1.GroupIndex > 0;
			}

			bool collide = (filter1.MaskBits & filter2.CategoryBits) != 0 && (filter1.CategoryBits & filter2.MaskBits) != 0;
			return collide;
		}
Beispiel #12
0
 protected Shape(ShapeDef def)
 {
     this._userData = def.UserData;
     this._friction = def.Friction;
     this._restitution = def.Restitution;
     this._density = def.Density;
     this._body = null;
     this._sweepRadius = 0f;
     this._next = null;
     this._proxyId = PairManager.NullProxy;
     this._filter = def.Filter;
     this._isSensor = def.IsSensor;
 }
Beispiel #13
0
 public virtual bool ShouldCollide(Shape shape1, Shape shape2)
 {
     FilterData filterData = shape1.FilterData;
     FilterData filterData2 = shape2.FilterData;
     bool result;
     if (filterData.GroupIndex == filterData2.GroupIndex && filterData.GroupIndex != 0)
     {
         result = (filterData.GroupIndex > 0);
     }
     else
     {
         bool flag = (filterData.MaskBits & filterData2.CategoryBits) != 0 && (filterData.CategoryBits & filterData2.MaskBits) != 0;
         result = flag;
     }
     return result;
 }
Beispiel #14
0
 public Contact(Shape s1, Shape s2)
 {
     this._flags = (Contact.CollisionFlags)0;
     if (s1.IsSensor || s2.IsSensor)
     {
         this._flags |= Contact.CollisionFlags.NonSolid;
     }
     this._shape1 = s1;
     this._shape2 = s2;
     this._manifoldCount = 0;
     this._prev = null;
     this._next = null;
     this._node1 = new ContactEdge();
     this._node1.Contact = null;
     this._node1.Prev = null;
     this._node1.Next = null;
     this._node1.Other = null;
     this._node2 = new ContactEdge();
     this._node2.Contact = null;
     this._node2.Prev = null;
     this._node2.Next = null;
     this._node2.Other = null;
 }
Beispiel #15
0
		public SensorTest()
		{
			{
				BodyDef bd = new BodyDef();
				bd.Position.Set(0.0f, -10.0f);

				Body ground = _world.CreateBody(bd);

				PolygonDef sd = new PolygonDef();
				sd.SetAsBox(50.0f, 10.0f);
				ground.CreateShape(sd);

				CircleDef cd = new CircleDef();
				cd.IsSensor = true;
				cd.Radius = 5.0f;
				cd.LocalPosition.Set(0.0f, 20.0f);
				_sensor = ground.CreateShape(cd);
			}

			{
				CircleDef sd = new CircleDef();
				sd.Radius = 1.0f;
				sd.Density = 1.0f;

				for (int i = 0; i < 7; ++i)
				{
					BodyDef bd = new BodyDef();
					bd.Position.Set(-10.0f + 3.0f * i, 20.0f);

					Body body = _world.CreateBody(bd);

					body.CreateShape(sd);
					body.SetMassFromShapes();
				}
			}
		}
		static void Distance(out DistanceOutput output, ref SimplexCache cache, ref DistanceInput input, Shape shapeA, Shape shapeB)
		{
			output = new DistanceOutput();

			Transform transformA = input.TransformA;
			Transform transformB = input.TransformB;

			// Initialize the simplex.
			Simplex simplex = new Simplex();
#if ALLOWUNSAFE
			fixed (SimplexCache* sPtr = &cache)
			{
				simplex.ReadCache(sPtr, shapeA, transformA, shapeB, transformB);
			}
#else
			simplex.ReadCache(cache, shapeA, transformA, shapeB, transformB);
#endif

			// Get simplex vertices as an array.
#if ALLOWUNSAFE
			SimplexVertex* vertices = &simplex._v1;
#else
			SimplexVertex[] vertices = new SimplexVertex[] { simplex._v1, simplex._v2, simplex._v3 };
#endif 

			// These store the vertices of the last simplex so that we
			// can check for duplicates and prevent cycling.
#if ALLOWUNSAFE
			int* lastA = stackalloc int[4], lastB = stackalloc int[4];
#else
			int[] lastA = new int[4];
			int[] lastB = new int[4];
#endif // ALLOWUNSAFE
			int lastCount;

			// Main iteration loop.
			int iter = 0;
			const int k_maxIterationCount = 20;
			while (iter < k_maxIterationCount)
			{
				// Copy simplex so we can identify duplicates.
				lastCount = simplex._count;
				int i;
				for (i = 0; i < lastCount; ++i)
				{
					lastA[i] = vertices[i].indexA;
					lastB[i] = vertices[i].indexB;
				}

				switch (simplex._count)
				{
					case 1:
						break;

					case 2:
						simplex.Solve2();
						break;

					case 3:
						simplex.Solve3();
						break;

					default:
#if DEBUG
						Box2DXDebug.Assert(false);
#endif
						break;
				}

				// If we have 3 points, then the origin is in the corresponding triangle.
				if (simplex._count == 3)
				{
					break;
				}

				// Compute closest point.
				Vector2 p = simplex.GetClosestPoint();
				float distanceSqr = p.sqrMagnitude;

				// Ensure the search direction is numerically fit.
				if (distanceSqr < Common.Settings.FLT_EPSILON_SQUARED)
				{
					// The origin is probably contained by a line segment
					// or triangle. Thus the shapes are overlapped.

					// We can't return zero here even though there may be overlap.
					// In case the simplex is a point, segment, or triangle it is difficult
					// to determine if the origin is contained in the CSO or very close to it.
					break;
				}

				// Compute a tentative new simplex vertex using support points.
#if ALLOWUNSAFE
				SimplexVertex* vertex = vertices + simplex._count;
				vertex->indexA = shapeA.GetSupport(transformA.InverseTransformDirection(p));
				vertex->wA = transformA.TransformPoint(shapeA.GetVertex(vertex->indexA));
				//Vec2 wBLocal;
				vertex->indexB = shapeB.GetSupport(transformB.InverseTransformDirection(-p));
				vertex->wB = transformB.TransformPoint(shapeB.GetVertex(vertex->indexB));
				vertex->w = vertex->wB - vertex->wA;
#else
				SimplexVertex vertex = vertices[simplex._count - 1];
				vertex.indexA = shapeA.GetSupport(transformA.InverseTransformDirection(p));
				vertex.wA = transformA.TransformPoint(shapeA.GetVertex(vertex.indexA));
				//Vec2 wBLocal;
				vertex.indexB = shapeB.GetSupport(transformB.InverseTransformDirection(-p));
				vertex.wB = transformB.TransformPoint(shapeB.GetVertex(vertex.indexB));
				vertex.w = vertex.wB - vertex.wA;	
#endif // ALLOWUNSAFE

				// Iteration count is equated to the number of support point calls.
				++iter;

				// Check for convergence.
#if ALLOWUNSAFE
				float lowerBound = Vector2.Dot(p, vertex->w);
#else
				float lowerBound = Vector2.Dot(p, vertex.w);
#endif
				float upperBound = distanceSqr;
				const float k_relativeTolSqr = 0.01f * 0.01f;	// 1:100
				if (upperBound - lowerBound <= k_relativeTolSqr * upperBound)
				{
					// Converged!
					break;
				}

				// Check for duplicate support points.
				bool duplicate = false;
				for (i = 0; i < lastCount; ++i)
				{
#if ALLOWUNSAFE
					if (vertex->indexA == lastA[i] && vertex->indexB == lastB[i])
#else
					if (vertex.indexA == lastA[i] && vertex.indexB == lastB[i])
#endif
					{
						duplicate = true;
						break;
					}
				}

				// If we found a duplicate support point we must exit to avoid cycling.
				if (duplicate)
				{
					break;
				}

				// New vertex is ok and needed.
				++simplex._count;
			}

			
#if ALLOWUNSAFE
			fixed (DistanceOutput* doPtr = &output)
			{
				// Prepare output.
				simplex.GetWitnessPoints(&doPtr->PointA, &doPtr->PointB);
				doPtr->Distance = Vector2.Distance(doPtr->PointA, doPtr->PointB);
				doPtr->Iterations = iter;
			}

			fixed (SimplexCache* sPtr = &cache)
			{
				// Cache the simplex.
				simplex.WriteCache(sPtr);
			}
#else
			// Prepare output.
			simplex.GetWitnessPoints(out output.PointA, out output.PointB);
			output.Distance = Vector2.Distance(output.PointA, output.PointB);
			output.Iterations = iter;
			
			// Cache the simplex.
			simplex.WriteCache(cache);
#endif

			// Apply radii if requested.
			if (input.UseRadii)
			{
				float rA = shapeA._radius;
				float rB = shapeB._radius;

				if (output.Distance > rA + rB && output.Distance > Common.Settings.FLT_EPSILON)
				{
					// Shapes are still no overlapped.
					// Move the witness points to the outer surface.
					output.Distance -= rA + rB;
					Vector2 normal = output.PointB - output.PointA;
					normal.Normalize();
					output.PointA += rA * normal;
					output.PointB -= rB * normal;
				}
				else
				{
					// Shapes are overlapped when radii are considered.
					// Move the witness points to the middle.
					Vector2 p = 0.5f * (output.PointA + output.PointB);
					output.PointA = p;
					output.PointB = p;
					output.Distance = 0.0f;
				}
			}
		}
		internal void ReadCache(SimplexCache cache, Shape shapeA, Transform transformA, Shape shapeB, Transform transformB)
		{
			Box2DXDebug.Assert(0 <= cache.Count && cache.Count <= 3);

			// Copy data from cache.
			_count = cache.Count;
			SimplexVertex[] vertices = new SimplexVertex[] { _v1, _v2, _v3 };
			for (int i = 0; i < _count; ++i)
			{
				SimplexVertex v = vertices[i];
				v.indexA = cache.IndexA[i];
				v.indexB = cache.IndexB[i];
				Vector2 wALocal = shapeA.GetVertex(v.indexA);
				Vector2 wBLocal = shapeB.GetVertex(v.indexB);
				v.wA = transformA.TransformPoint(wALocal);
				v.wB = transformB.TransformPoint(wBLocal);
				v.w = v.wB - v.wA;
				v.a = 0.0f;
			}

			// Compute the new simplex metric, if it is substantially different than
			// old metric then flush the simplex.
			if (_count > 1)
			{
				float metric1 = cache.Metric;
				float metric2 = GetMetric();
				if (metric2 < 0.5f * metric1 || 2.0f * metric1 < metric2 || metric2 < Common.Settings.FLT_EPSILON)
				{
					// Reset the simplex.
					_count = 0;
				}
			}

			// If the cache is empty or invalid ...
			if (_count == 0)
			{
				SimplexVertex v = vertices[0];
				v.indexA = 0;
				v.indexB = 0;
				Vector2 wALocal = shapeA.GetVertex(0);
				Vector2 wBLocal = shapeB.GetVertex(0);
				v.wA = transformA.TransformPoint(wALocal);
				v.wB = transformB.TransformPoint(wBLocal);
				v.w = v.wB - v.wA;
				_count = 1;
			}
		}
		internal unsafe void ReadCache(SimplexCache* cache, Shape shapeA, Transform TransformA, Shape shapeB, Transform TransformB)
		{
			Box2DXDebug.Assert(0 <= cache->Count && cache->Count <= 3);

			// Copy data from cache.
			_count = cache->Count;
			SimplexVertex** vertices = stackalloc SimplexVertex*[3];
			fixed (SimplexVertex* v1Ptr = &_v1, v2Ptr = &_v2, v3Ptr = &_v3)
			{
				vertices[0] = v1Ptr;
				vertices[1] = v2Ptr;
				vertices[2] = v3Ptr;
				for (int i = 0; i < _count; ++i)
				{
					SimplexVertex* v = vertices[i];
					v->indexA = cache->IndexA[i];
					v->indexB = cache->IndexB[i];
					Vector2 wALocal = shapeA.GetVertex(v->indexA);
					Vector2 wBLocal = shapeB.GetVertex(v->indexB);
					v->wA = TransformA.TransformPoint(wALocal);
					v->wB = TransformB.TransformPoint(wBLocal);
					v->w = v->wB - v->wA;
					v->a = 0.0f;
				}

				// Compute the new simplex metric, if it is substantially different than
				// old metric then flush the simplex.
				if (_count > 1)
				{
					float metric1 = cache->Metric;
					float metric2 = GetMetric();
					if (metric2 < 0.5f * metric1 || 2.0f * metric1 < metric2 || metric2 < Common.Settings.FLT_EPSILON)
					{
						// Reset the simplex.
						_count = 0;
					}
				}

				// If the cache is empty or invalid ...
				if (_count == 0)
				{
					SimplexVertex* v = vertices[0];
					v->indexA = 0;
					v->indexB = 0;
					Vector2 wALocal = shapeA.GetVertex(0);
					Vector2 wBLocal = shapeB.GetVertex(0);
					v->wA = TransformA.TransformPoint(wALocal);
					v->wB = TransformB.TransformPoint(wBLocal);
					v->w = v->wB - v->wA;
					_count = 1;
				}
			}
		}
Beispiel #19
0
		private static void CollideCircles(ref Manifold manifold, Shape shape1, XForm xf1, Shape shape2, XForm xf2)
		{
			Collision.Collision.CollideCircles(ref manifold, (CircleShape)shape1, xf1, (CircleShape)shape2, xf2);
		}
Beispiel #20
0
        /// Creates a fixture from a shape and attach it to this body.
        /// This is a convenience function. Use b2FixtureDef if you need to set parameters
        /// like friction, restitution, user data, or filtering.
        /// This function automatically updates the mass of the body.
        /// @param shape the shape to be cloned.
        /// @param density the shape density (set to zero for static bodies).
        /// @warning This function is locked during callbacks.
        public Fixture CreateFixture(Shape shape, float density)
        {
            FixtureDef def = new FixtureDef();
            def.Shape = shape;
            def.Density = density;

            return CreateFixture(def);
        }
Beispiel #21
0
        public void Destroy(BroadPhase broadPhase)
        {
            // Remove proxy from the broad-phase.
            if (ProxyId != BroadPhase.NullProxy)
            {
                broadPhase.DestroyProxy(ProxyId);
                ProxyId = BroadPhase.NullProxy;
            }

            // Free the child shape.
            switch (Shape.Type)
            {
                case ShapeType.CircleShape:
                    {
                        //CircleShape s = (CircleShape)Shape;
                        //s->~b2CircleShape();
                        //allocator->Free(s, sizeof(b2CircleShape));
                    }
                    break;

                case ShapeType.PolygonShape:
                    {
                        //b2PolygonShape* s = (b2PolygonShape*)m_shape;
                        //s->~b2PolygonShape();
                        //allocator->Free(s, sizeof(b2PolygonShape));
                    }
                    break;
                default:
                    Box2DXDebug.Assert(false);
                    break;
            }

            Shape = null;
        }
Beispiel #22
0
		/// <summary>
		/// Performs a raycast as with Raycast, finding the first intersecting shape.
		/// </summary>
		/// <param name="segment">Defines the begin and end point of the ray cast, from p1 to p2.
		/// Use Segment.Extend to create (semi-)infinite rays.</param>
		/// <param name="lambda">Returns the hit fraction. You can use this to compute the contact point
		/// p = (1 - lambda) * segment.p1 + lambda * segment.p2.</param>
		/// <param name="normal">Returns the normal at the contact point. If there is no intersection, the normal is not set.</param>
		/// <param name="solidShapes">Determines if shapes that the ray starts in are counted as hits.</param>
		/// <param name="userData"></param>
		/// <returns>Returns the colliding shape shape, or null if not found.</returns>
		public Shape RaycastOne(Segment segment, out float lambda, out Vec2 normal, bool solidShapes, object userData)
		{
			lambda = 0;
			normal = new Vec2(0,0);

			int maxCount = 1;
			Shape[] shape = new Shape[maxCount];

			int count = Raycast(segment, shape, maxCount, solidShapes, userData);

			if (count == 0)
				return null;

			Box2DXDebug.Assert(count == 1);

			//Redundantly do TestSegment a second time, as the previous one's results are inaccessible

			XForm xf = shape[0].GetBody().GetXForm();
			shape[0].TestSegment(xf, out lambda, out normal, segment, 1);
			//We already know it returns true
			return shape[0];
		}
Beispiel #23
0
        /// <summary>
        /// Mouse interaction event.
        /// </summary>
		public void MouseDown(Vec2 p)
		{
			if (_mouseJoint != null)
			{
				return;
			}

			// Make a small box.
			AABB aabb = new AABB();
			Vec2 d = new Vec2();
			d.Set(0.001f, 0.001f);
			aabb.LowerBound = p - d;
			aabb.UpperBound = p + d;

			// Query the world for overlapping shapes.
			int k_maxCount = 10;
			Shape[] shapes = new Shape[k_maxCount];
			int count = _world.Query(aabb, shapes, k_maxCount);
			Body body = null;
			for (int i = 0; i < count; ++i)
			{
				Body shapeBody = shapes[i].GetBody();
				if (shapeBody.IsStatic() == false && shapeBody.GetMass() > 0.0f)
				{
					bool inside = shapes[i].TestPoint(shapeBody.GetXForm(), p);
					if (inside)
					{
						body = shapes[i].GetBody();
						break;
					}
				}
			}

			if (body != null)
			{
				MouseJointDef md = new MouseJointDef();
				md.Body1 = _world.GetGroundBody();
				md.Body2 = body;
				md.Target = p;
                md.MaxForce = 1000.0f * body.GetMass();
                md.FrequencyHz = 30f;
				_mouseJoint = (MouseJoint)_world.CreateJoint(md);
				body.WakeUp();
			}
		}
Beispiel #24
0
		public ContactCB()
		{
			PolygonDef sd = new PolygonDef();
			sd.Friction = 0;
			sd.VertexCount = 3;

			sd.Vertices[0].Set(10, 10);
			sd.Vertices[1].Set(9, 7);
			sd.Vertices[2].Set(10, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(9, 7);
			sd.Vertices[1].Set(8, 0);
			sd.Vertices[2].Set(10, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(9, 7);
			sd.Vertices[1].Set(8, 5);
			sd.Vertices[2].Set(8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(8, 5);
			sd.Vertices[1].Set(7, 4);
			sd.Vertices[2].Set(8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(7, 4);
			sd.Vertices[1].Set(5, 0);
			sd.Vertices[2].Set(8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(7, 4);
			sd.Vertices[1].Set(5, 3);
			sd.Vertices[2].Set(5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(5, 3);
			sd.Vertices[1].Set(2, 2);
			sd.Vertices[2].Set(5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(2, 2);
			sd.Vertices[1].Set(0, 0);
			sd.Vertices[2].Set(5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[0].Set(2, 2);
			sd.Vertices[1].Set(-2, 2);
			sd.Vertices[2].Set(0, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-2, 2);
			sd.Vertices[1].Set(0, 0);
			sd.Vertices[0].Set(-5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-5, 3);
			sd.Vertices[1].Set(-2, 2);
			sd.Vertices[0].Set(-5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-7, 4);
			sd.Vertices[1].Set(-5, 3);
			sd.Vertices[0].Set(-5, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-7, 4);
			sd.Vertices[1].Set(-5, 0);
			sd.Vertices[0].Set(-8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-8, 5);
			sd.Vertices[1].Set(-7, 4);
			sd.Vertices[0].Set(-8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-9, 7);
			sd.Vertices[1].Set(-8, 5);
			sd.Vertices[0].Set(-8, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-9, 7);
			sd.Vertices[1].Set(-8, 0);
			sd.Vertices[0].Set(-10, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.Vertices[2].Set(-10, 10);
			sd.Vertices[1].Set(-9, 7);
			sd.Vertices[0].Set(-10, 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.SetAsBox(.5f, 6, new Vec2(10.5f, 6), 0);
			_world.GetGroundBody().CreateShape(sd);

			sd.SetAsBox(.5f, 6, new Vec2(-10.5f, 6), 0);
			_world.GetGroundBody().CreateShape(sd);

			BodyDef bd = new BodyDef();
			bd.Position.Set(9.5f, 60);
			Body _ball = _world.CreateBody(bd);

			PolygonDef cd = new PolygonDef();
			cd.VertexCount = 8;
			float w = 1.0f;
			float b = w / (2.0f + (float)System.Math.Sqrt(2.0f));
			float s = (float)System.Math.Sqrt(2.0f) * b;
			cd.Vertices[0].Set(0.5f * s, 0.0f);
			cd.Vertices[1].Set(0.5f * w, b);
			cd.Vertices[2].Set(0.5f * w, b + s);
			cd.Vertices[3].Set(0.5f * s, w);
			cd.Vertices[4].Set(-0.5f * s, w);
			cd.Vertices[5].Set(-0.5f * w, b + s);
			cd.Vertices[6].Set(-0.5f * w, b);
			cd.Vertices[7].Set(-0.5f * s, 0.0f);
			cd.Density = 1.0f;

			_ball_shape = _ball.CreateShape(cd);
			_ball.SetMassFromShapes();
		}
Beispiel #25
0
		private static void Collide(ref Manifold manifold, Shape shape1, XForm xf1, Shape shape2, XForm xf2) { }
Beispiel #26
0
 public void OnContactRemove(Box2DX.Collision.Shape other, ContactPoint point)
 {
 }
Beispiel #27
0
		new public static Contact Create(Shape shape1, Shape shape2)
		{
			return new PolygonContact(shape1, shape2);
		}
Beispiel #28
0
 public static new Contact Create(Shape shape1, Shape shape2)
 {
     return new CircleContact(shape1, shape2);
 }
 /// <summary>
 /// Called when any shape is about to be destroyed due
 /// to the destruction of its parent body.
 /// </summary>
 public abstract void SayGoodbye(Shape shape);
Beispiel #30
0
 internal static void Destroy(Shape s)
 {
     switch (s.GetType())
     {
         case ShapeType.CircleShape:
         {
             if (s != null)
             {
                 ((IDisposable)s).Dispose();
             }
             s = null;
             break;
         }
         case ShapeType.PolygonShape:
         {
             if (s != null)
             {
                 ((IDisposable)s).Dispose();
             }
             s = null;
             break;
         }
         default:
         {
             Box2DXDebug.Assert(false);
             break;
         }
     }
 }
Beispiel #31
0
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        public void Create(BroadPhase broadPhase, Body body, Transform xf, FixtureDef def)
        {
            UserData = def.UserData;
            Friction = def.Friction;
            Restitution = def.Restitution;

            Body = body;
            _next = null;

            Filter = def.Filter;

            IsSensor = def.IsSensor;

            Shape = def.Shape.Clone();

            Shape.ComputeMass(out _massData, def.Density);

            // Create proxy in the broad-phase.
            Shape.ComputeAABB(out Aabb, ref xf);

            ProxyId = broadPhase.CreateProxy(Aabb, this);
        }
Beispiel #32
0
 /// The constructor sets the default fixture definition values.
 public FixtureDef()
 {
     Shape = null;
     UserData = null;
     Friction = 0.2f;
     Restitution = 0.0f;
     Density = 0.0f;
     Filter.CategoryBits = 0x0001;
     Filter.MaskBits = 0xFFFF;
     Filter.GroupIndex = 0;
     IsSensor = false;
 }