Example #1
0
        public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, CCPoint offset, float border = 1)
        {
            _type = PhysicsType.EDGEBOX;

            List <cpVect> vec = new List <cpVect>()
            {
                new cpVect(-size.Width / 2 + offset.X, -size.Height / 2 + offset.Y),
                new cpVect(+size.Width / 2 + offset.X, -size.Height / 2 + offset.Y),
                new cpVect(+size.Width / 2 + offset.X, +size.Height / 2 + offset.Y),
                new cpVect(-size.Width / 2 + offset.X, +size.Height / 2 + offset.Y)
            };


            int i = 0;

            for (; i < 4; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[(i + 1) % 4],
                                                   border);
                _info.add(shape);
            }

            _offset = offset;
            _mass   = CCPhysicsBody.MASS_DEFAULT;
            _moment = CCPhysicsBody.MOMENT_DEFAULT;

            SetMaterial(material);
        }
Example #2
0
        public CCPhysicsShapeEdgePolygon(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
        {
            _type = PhysicsType.EDGEPOLYGEN;

            int i    = 0;
            var vecs = PhysicsHelper.CCPointsTocpVects(vec);

            for (; i < count; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vecs[i], vecs[(i + 1) % count],
                                                   border);

                if (shape == null)
                {
                    break;
                }

                shape.SetElasticity(1.0f);
                shape.SetFriction(1.0f);

                _info.add(shape);
            }

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            SetMaterial(material);
        }
Example #3
0
 public void AddShape(CCPhysicsShapeInfo shape)
 {
     foreach (var item in shape.GetShapes())
     {
         _space.AddShape(item);
     }
 }
Example #4
0
        //protected cpVect _offset;
        #endregion

        #region PUBLIC METHODS

        public CCPhysicsShapeBox(CCSize size, CCPhysicsMaterial material, float radius)
        {
            cpVect wh = PhysicsHelper.size2cpv(size);

            _type = PhysicsType.BOX;

            cpVect[] vec =
            {
                new cpVect(-wh.x / 2.0f, -wh.y / 2.0f),
                new cpVect(-wh.x / 2.0f, wh.y / 2.0f),
                new cpVect(wh.x / 2.0f,  wh.y / 2.0f),
                new cpVect(wh.x / 2.0f, -wh.y / 2.0f)
            };

            cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), 4, vec, radius);

            _info.add(shape);

            //_offset = offset;
            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            SetMaterial(material);
        }
		public void removeShape(CCPhysicsShapeInfo shapeInf)
		{
			foreach (var shape in shapeInf.getShapes())
			{
				if (_space.ContainsShape(shape))
					_space.RemoveShape(shape);
			}

		}
		public void addShape(CCPhysicsShapeInfo shape)
		{

			foreach (var item in shape.getShapes())
			{
				_space.AddShape(item);
			}

		}
Example #7
0
 public void RemoveShape(CCPhysicsShapeInfo shapeInf)
 {
     foreach (var shape in shapeInf.GetShapes())
     {
         if (_space.ContainsShape(shape))
         {
             _space.RemoveShape(shape);
         }
     }
 }
Example #8
0
        public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset)
        {
            _type = PhysicsType.CIRCLE;

            cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.getSharedBody(), radius, PhysicsHelper.CCPointToCpVect(offset));

            _info.add(shape);

            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            SetMaterial(material);
        }
Example #9
0
        public void Init(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
        {
            _type = PhysicsType.POLYGEN;

            cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), count, PhysicsHelper.CCPointsTocpVects(vecs), radius);


            _info.add(shape);

            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            SetMaterial(material);
        }
Example #10
0
        public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
        {
            cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(),
                                               PhysicsHelper.CCPointToCpVect(a),
                                               PhysicsHelper.CCPointToCpVect(b),
                                               border);

            _type = PhysicsType.EDGESEGMENT;


            _info.add(shape);

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            SetMaterial(material);
        }
Example #11
0
        public static bool CollisionBeginCallbackFunc(cpArbiter arb, cpSpace space, CCPhysicsWorld world)
        {
            cpShape a, b;

            arb.GetShapes(out a, out b);

            CCPhysicsShapeInfo ita = null, itb = null;

            cp.AssertWarn(CCPhysicsShapeInfo.Map.TryGetValue(a, out ita) && CCPhysicsShapeInfo.Map.TryGetValue(b, out itb));
            if (a != null || b != null)
            {
                return(false);
            }

            CCPhysicsContact contact = new CCPhysicsContact(ita.getShape(), itb.getShape());

            arb.data             = contact;
            contact._contactInfo = arb;

            return(world.CollisionBeginCallback(contact));
        }
Example #12
0
        public CCPhysicsShapeEdgeChain(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
        {
            _type = PhysicsType.EDGECHAIN;
            var vecs = PhysicsHelper.CCPointsTocpVects(vec);
            int i    = 0;

            for (; i < count; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody(), vecs[i], vecs[i + 1],
                                                   border);
                shape.SetElasticity(1.0f);
                shape.SetFriction(1.0f);

                _info.Add(shape);
            }

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            SetMaterial(material);
        }
Example #13
0
        public CCPhysicsShape()
        {
            _body               = null;
            _info               = null;
            _type               = PhysicsType.UNKNOWN;
            _area               = 0;
            _mass               = CCPhysicsBody.MASS_DEFAULT;
            _moment             = CCPhysicsBody.MOMENT_DEFAULT;
            _tag                = 0;
            _categoryBitmask    = int.MaxValue;
            _collisionBitmask   = int.MaxValue;
            _contactTestBitmask = 0;
            _group              = 0;

            _info = new CCPhysicsShapeInfo(this);

            _scaleX    = 1.0f;
            _scaleY    = 1.0f;
            _newScaleX = 1.0f;
            _newScaleY = 1.0f;
            _dirty     = false;
        }
Example #14
0
		public CCPhysicsShape()
		{
			_body = null;
			_info = null;
			_type = PhysicsType.UNKNOWN;
			_area = 0;
			_mass = CCPhysicsBody.MASS_DEFAULT;
			_moment = CCPhysicsBody.MOMENT_DEFAULT;
			_tag = 0;
			_categoryBitmask = int.MaxValue;
			_collisionBitmask = int.MaxValue;
			_contactTestBitmask = 0;
			_group = 0;

			_info = new CCPhysicsShapeInfo(this);

			_scaleX = 1.0f;
			_scaleY = 1.0f;
			_newScaleX = 1.0f;
			_newScaleY = 1.0f;
			_dirty = false;

		}