예제 #1
0
		/// Creates a fixture from a shape and attach it to this body.
		/// This is a convenience function. Use FixtureDef if you need to set parameters
		/// like friction, restitution, user data, or filtering.
		/// If the Density is non-zero, 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){
			FixtureDef def = new FixtureDef();
			def.shape = shape.Clone();
			def.Density = shape.Density;
			def.Filter = shape.Filter;

			return CreateFixture(def);
		}
예제 #2
0
		/// Initialize the proxy using the given shape. The shape
		/// must remain in scope while the proxy is in use.
		public void Set(Shape shape, int index){
			switch (shape.GetShapeType())
			{
			case ShapeType.Circle:
			    {
			        CircleShape circle = (CircleShape)shape;
					m_vertices = new List<Vec2>();
			        m_vertices.Add(circle.m_p);
			        m_radius = circle.m_radius;
			    }
			    break;

			case ShapeType.Polygon:
			    {
			        PolygonShape polygon = (PolygonShape)shape;
					m_vertices = new List<Vec2>();
			        m_vertices.AddRange(polygon.m_vertices);
			        m_radius = polygon.m_radius;
			    }
			    break;

			case ShapeType.Chain:
			    {
			        ChainShape chain = (ChainShape)shape;
			        Utilities.Assert(0 <= index && index < chain.m_count);

			        m_buffer[0] = chain.m_vertices[index];
			        if (index + 1 < chain.m_count)
			        {
			            m_buffer[1] = chain.m_vertices[index + 1];
			        }
			        else
			        {
			            m_buffer[1] = chain.m_vertices[0];
			        }

					m_vertices = new List<Vec2>();
			        m_vertices.AddRange(m_buffer);
			        m_radius = chain.m_radius;
			    }
			    break;

			case ShapeType.Edge:
			    {
			        EdgeShape edge = (EdgeShape)shape;
					m_vertices = new List<Vec2>();
					m_vertices.AddRange(new Vec2[]{edge.m_vertex1, edge.m_vertex2});
			        m_radius = edge.m_radius;
			    }
			    break;

			default:
			    Utilities.Assert(false);
				break;
			}
		}
예제 #3
0
		/// The constructor sets the default fixture definition values.
		public FixtureDef()
		{
			shape = null;
			UserData = null;
			friction = 0.2f;
			restitution = 0.0f;
			Density = 0.0f;
			IsSensor = false;
			Filter = new Filter();
		}
예제 #4
0
		/// Determine if two generic shapes overlap.
		public static bool TestOverlap(Shape shapeA, int indexA,
							Shape shapeB, int indexB,
							Transform xfA, Transform xfB){

			DistanceInput input = new DistanceInput();
			input.proxyA.Set(shapeA, indexA);
			input.proxyB.Set(shapeB, indexB);
			input.transformA = xfA;
			input.transformB = xfB;
			input.useRadii = true;

			SimplexCache cache = new SimplexCache();
			cache.count = 0;

			DistanceOutput output;

			Utilities.Distance(out output, cache, input);

			return output.distance < 10.0f * Single.Epsilon;
		}
예제 #5
0
		// We need separation create/destroy functions from the constructor/destructor because
		// the destructor cannot access the allocator (no destructor arguments allowed by C++).
		internal void Create(Body body, FixtureDef def){
			m_userData = def.UserData;
			m_friction = def.friction;
			m_restitution = def.restitution;

			m_body = body;
			m_next = null;

			m_filter = def.Filter;

			m_isSensor = def.IsSensor;

			m_shape = def.shape.Clone();

			// Reserve proxy space
			int childCount = m_shape.GetChildCount();
			m_proxies = new List<FixtureProxy>();

			m_Density = def.Density;
		}
예제 #6
0
		internal Fixture(){
			m_userData = null;
			m_body = null;
			m_next = null;
			m_proxies = new List<FixtureProxy>();
			m_shape = null;
			m_Density = 0.0f;
		}