public CCPhysicsWorld(CCScene scene) { _gravity = new CCPoint(0.0f, -98.0f); _speed = 1.0f; _updateRate = 1; _updateRateCount = 0; _updateTime = 0.0f; _info = null; _scene = null; _delayDirty = false; _info = new CCPhysicsWorldInfo(); _scene = scene; _info.SetGravity(PhysicsHelper.CCPointToCpVect(_gravity)); var spc = _info.getSpace(); spc.defaultHandler = new cpCollisionHandler() { beginFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionBeginCallbackFunc(a as cpArbiter, s, this), preSolveFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionPreSolveCallbackFunc(a as cpArbiter, s, this), postSolveFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionPostSolveCallbackFunc(a as cpArbiter, s, this), separateFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionSeparateCallbackFunc(a as cpArbiter, s, this) }; }
public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset) { // TODO: Complete member initialization this.radius = radius; this.material = material; this.offset = PhysicsHelper.CCPointToCpVect(offset); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float stiffness, float damping) { if (!base.Init(a, b)) { return(false); } var anch1 = PhysicsHelper.CCPointToCpVect(anchr1); var anch2 = PhysicsHelper.CCPointToCpVect(anchr2); cpConstraint joint = new cpDampedSpring(GetBodyInfo(a).Body, GetBodyInfo(b).Body, anch1, anch2, cpVect.cpvdist( _bodyB.Local2World(anch1), _bodyA.Local2World(anch2)), stiffness, damping); if (joint == null) { return(false); } _info.Add(joint); return(true); }
public CCPhysicsWorld(CCScene scene) { DelayAddBodies = new List <CCPhysicsBody>(); DelayRemoveBodies = new List <CCPhysicsBody>(); DelayAddJoints = new List <CCPhysicsJoint>(); DelayRemoveJoints = new List <CCPhysicsJoint>(); Bodies = new List <CCPhysicsBody>(); Joints = new List <CCPhysicsJoint>(); _gravity = new CCPoint(0.0f, -98.0f); _speed = 1.0f; _updateRate = 1; _updateRateCount = 0; _updateTime = 0.0f; Info = null; Scene = null; DelayDirty = false; Info = new CCPhysicsWorldInfo(); Scene = scene; Info.Gravity = PhysicsHelper.CCPointToCpVect(_gravity); var spc = Info.Space; spc.defaultHandler = new cpCollisionHandler() { beginFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionBeginCallbackFunc(a as cpArbiter, s, this), preSolveFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionPreSolveCallbackFunc(a as cpArbiter, s, this), postSolveFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionPostSolveCallbackFunc(a as cpArbiter, s, this), separateFunc = (a, s, o) => CCPhysicsWorldCallback.CollisionSeparateCallbackFunc(a as cpArbiter, s, this) }; }
public void SetSurfaceVelocity(CCPoint surfaceVelocity) { var vel = PhysicsHelper.CCPointToCpVect(surfaceVelocity); foreach (cpShape shape in _info.getShapes()) { shape.SetSurfaceVelocity(vel); } }
public static CCPhysicsJointDistance Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2) { CCPhysicsJointDistance joint = new CCPhysicsJointDistance(); if (joint != null && joint.Init(a, b, PhysicsHelper.CCPointToCpVect(anchr1), PhysicsHelper.CCPointToCpVect(anchr2))) { return(joint); } return(null); }
/** Get phsyics shapes that contains the point. */ public List <CCPhysicsShape> GetShapes(CCPoint point) { List <CCPhysicsShape> arr = new List <CCPhysicsShape>(); this._info.getSpace().PointQuery( PhysicsHelper.CCPointToCpVect(point), 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS), (s, v1, f, v2, o) => CCPhysicsWorldCallback.GetShapesAtPointFunc(s, f, PhysicsHelper.cpVectToCCPoint(v1), ref arr), null ); return(arr); }
/** Test point is in shape or not */ public bool ContainsPoint(CCPoint point) { foreach (var shape in _info.GetShapes()) { cpPointQueryInfo info = null; shape.PointQuery(PhysicsHelper.CCPointToCpVect(point), ref info); if (info != null) { return(true); } } return(false); }
public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset) { _type = PhysicsType.CIRCLE; cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.SharedBody, radius, PhysicsHelper.CCPointToCpVect(offset)); _info.Add(shape); _area = CalculateArea(); _mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area; _moment = CalculateDefaultMoment(); Material = material; }
/** set the gravity value */ public void SetGravity(CCPoint gravity) { if (_bodies.Count > 0) { foreach (var body in _bodies) { // reset gravity for body if (!body.IsGravityEnabled()) { body.ApplyForce(PhysicsHelper.CCPointToCpVect((_gravity - gravity)) * body.GetMass()); } } } }
public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1) { cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, PhysicsHelper.CCPointToCpVect(a), PhysicsHelper.CCPointToCpVect(b), border); _type = PhysicsType.EDGESEGMENT; _info.Add(shape); _mass = cp.Infinity; _moment = cp.Infinity; Material = material; }
public override void Update(float delta) { if (_dirty) { float factor = cp.cpfabs(_newScaleX / _scaleX); cpCircleShape shape = (cpCircleShape)_info.GetShapes().FirstOrDefault(); //->getShapes().front(); cpVect v = PhysicsHelper.CCPointToCpVect(Offset); // cpCircleShapeGetOffset(); v = cpVect.cpvmult(v, factor); shape.c = v; shape.SetRadius(shape.GetRadius() * factor); } base.Update(delta); }
/** Searches for physics shapes that intersects the ray. */ public void RayCast(Func <CCPhysicsWorld, CCPhysicsRayCastInfo, object, bool> func, CCPoint point1, CCPoint point2, object data) { cp.AssertWarn(func != null, "func shouldn't be nullptr"); if (func != null) { CCRayCastCallbackInfo info = new CCRayCastCallbackInfo(this, func, point1, point2, data); //Action<cpShape, cpVect, cpVect, float, object> func CCPhysicsWorldCallback.continues = true; this._info.getSpace().SegmentQuery( PhysicsHelper.CCPointToCpVect(point1), PhysicsHelper.CCPointToCpVect(point2), 1f, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS), (shape, v1, v2, f, o) => CCPhysicsWorldCallback.RayCastCallbackFunc(shape, f, PhysicsHelper.cpVectToCCPoint(v1), ref info), data ); } }
/** Searches for physics shapes that contains the point. */ public void QueryPoint(Func <CCPhysicsWorld, CCPhysicsShape, object, bool> func, CCPoint point, object data) { cp.AssertWarn(func != null, "func shouldn't be nullptr"); if (func != null) { //CCPointQueryCallbackInfo info = new CCPointQueryCallbackInfo(this, func, data); CCPointQueryCallbackInfo info = new CCPointQueryCallbackInfo(this, func, data); CCPhysicsWorldCallback.continues = true; this._info.getSpace().PointQuery( PhysicsHelper.CCPointToCpVect(point), 0f, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS), (s, v, f1, f2, o) => CCPhysicsWorldCallback.QueryPointFunc(s, 0f, point, ref info), data ); } }
//static PhysicsJointPin* ruct(PhysicsBody* a, PhysicsBody* b, cpVect anchr); #region PROTECTED FUNC protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, PhysicsHelper.CCPointToCpVect(anchr)); if (joint == null) { return(false); } _info.Add(joint); return(true); }
/** return physics shape that contains the point. */ public CCPhysicsShape GetShape(CCPoint point) { cpShape shape = null; this._info.getSpace().PointQuery( PhysicsHelper.CCPointToCpVect(point), 0, new cpShapeFilter(cp.NO_GROUP, cp.ALL_LAYERS, cp.ALL_LAYERS), (s, v1, f, v2, o) => { shape = s; }, null); if (shape == null) { return(null); } CCPhysicsShapeInfo dev; if (CCPhysicsShapeInfo.Map.TryGetValue(shape, out dev)) { return(dev.getShape()); } return(null); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float min, float max) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpSlideJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, PhysicsHelper.CCPointToCpVect(anchr1), PhysicsHelper.CCPointToCpVect(anchr2), min, max); if (joint == null) { return(false); } _info.Add(joint); return(true); }
public static float CalculateMoment(float mass, CCPoint[] vecs, int count, CCPoint offset) { float moment = mass == cp.Infinity ? cp.Infinity : cp.MomentForPoly(mass, count, PhysicsHelper.CCPointsTocpVects(vecs), PhysicsHelper.CCPointToCpVect(offset), 0.0f); return(moment); }
public static float CalculateMoment(float mass, float radius, CCPoint offset) { return(mass == cp.Infinity ? cp.Infinity : (cp.MomentForCircle(mass, 0, radius, PhysicsHelper.CCPointToCpVect(offset)))); }
/** set the surface velocity*/ public void SetSurfaceVelocity(CCPoint velocity) { (_contactInfo as cpArbiter).surface_vr = PhysicsHelper.CCPointToCpVect(velocity); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr) { if (!base.Init(a, b)) { return(false); } GetBodyNode(a).Position = anchr; GetBodyNode(b).Position = anchr; // add a pivot joint to fixed two body together //cpConstraint joint = cpPivotJoint.cpPivotJointNew(getBodyInfo(a).getBody(), // getBodyInfo(b).getBody(), // anchr); cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, PhysicsHelper.CCPointToCpVect(anchr)); if (joint == null) { return(false); } _info.Add(joint); // add a gear joint to make two body have the same rotation. joint = new cpGearJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, 0, 1); if (joint == null) { return(false); } _info.Add(joint); SetCollisionEnable(false); return(true); }
public static CCPhysicsJointLimit Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2) { return(Construct(a, b, anchr1, anchr2, 0, cpVect.cpvdist(b.Local2World(PhysicsHelper.CCPointToCpVect(anchr1)), a.Local2World(PhysicsHelper.CCPointToCpVect(anchr2))))); }
public void SetAnchr2(CCPoint anchr2) { _info.getJoints().FirstOrDefault().SetAnchorB(PhysicsHelper.CCPointToCpVect(anchr2)); }
public void SetGrooveB(CCPoint grooveB) { _info.getJoints().FirstOrDefault().SetGrooveB(PhysicsHelper.CCPointToCpVect(grooveB)); }