cpBBWrapVect(cpBB bb, cpVect v) { double ix = System.Math.Abs(bb.r - bb.l); double modx = System.Math.Mod(v.x - bb.l, ix); double x = (modx > 0.0f) ? modx : modx + ix; double iy = System.Math.Abs(bb.t - bb.b); double mody = System.Math.Mod(v.y - bb.b, iy); double y = (mody > 0.0f) ? mody : mody + iy; return cpv(x + bb.l, y + bb.b); }
cpContactInit(cpContact con, cpVect p, cpVect n, double dist, cpHashValue hash) { con.p = p; con.n = n; con.dist = dist; con.jnAcc = 0.0f; con.jtAcc = 0.0f; con.jBias = 0.0f; con.hash = hash; return con; }
public override void Update(float delta) { if (_dirty) { float factorX = _newScaleX / _scaleX; float factorY = _newScaleY / _scaleY; foreach (cpSegmentShape shape in _info.GetShapes()) { cpVect a = shape.GetA(); a.x *= factorX; a.y *= factorY; cpVect b = shape.GetB(); b.x *= factorX; b.y *= factorY; shape.SetEndpoints(a, b); } } base.Update(delta); }
public virtual void OnTouchesBegan(List <CCTouch> touches, CCEvent e) { var touch = touches.FirstOrDefault(); CCMouse.Instance.UpdatePositionLocation(touch.LocationOnScreen, this); //Update mouse mouse position CCMouse.Instance.UpdateBodyPosition(); CCMouse.Instance.OnTouchBegan(touch, this); if (!CCMouse.Instance.HasBodyJoined) { float radius = 5.0f; cpPointQueryInfo info = null; var shape = space.PointQueryNearest( CCMouse.Instance.Position, radius, GRAB_FILTER, ref info); if (shape != null) { cpVect nearest = (info.distance > 0.0d ? info.point : CCMouse.Instance.Position); CCMouse.Instance.mouseJoint = new cpPivotJoint(CCMouse.Instance.mouseBody, shape.body, cpVect.Zero, shape.body.WorldToLocal(nearest)); CCMouse.Instance.mouseJoint.SetMaxForce(50000); CCMouse.Instance.mouseJoint.SetErrorBias(cp.cpfpow(1f - 0.15f, 60f)); space.AddConstraint(CCMouse.Instance.mouseJoint); return; } } //Arrastramos el logo if (logo.BoundingBox.ContainsPoint(CCMouse.Instance.PositionParentSpace)) { logo.MoveOffset = touch.LocationOnScreen - logo.Position; CCMouse.Instance.IsDragBlocked = logo.IsMoving = true; return; } }
static public cpSpace BouncyTerrainHexagons_500(cpSpace space) { SetSubTitle("BouncyTerrainHexagons 500"); //cpSpace space = BENCH_SPACE_NEW(); space.SetIterations(10); cpVect offset = new cpVect(-320, -240); for (int i = 0; i < (bouncy_terrain_verts.Length - 1); i++) { cpVect a = bouncy_terrain_verts[i], b = bouncy_terrain_verts[i + 1]; cpShape shape = space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f)); shape.SetElasticity(1.0f); } float radius = 5.0f; cpVect[] hexagon = new cpVect[6]; for (int i = 0; i < 6; i++) { float angle = -(float)Math.PI * 2.0f * i / 6.0f; hexagon[i] = cpVect.cpvmult(cpVect.cpv(cp.cpfcos(angle), cp.cpfsin(angle)), radius - bevel); } for (int i = 0; i < 500; i++) { float mass = radius * radius; cpBody body = space.AddBody(new cpBody(mass, cp.MomentForPoly(mass, 6, hexagon, cpVect.Zero, 0.0f))); body.SetPosition(cpVect.cpvadd(cpVect.cpvmult(cp.frand_unit_circle(), 130.0f), cpVect.Zero)); body.SetVelocity(cpVect.cpvmult(cp.frand_unit_circle(), 50.0f)); cpShape shape = space.AddShape(new cpPolyShape(body, 6, hexagon, cpTransform.Identity, bevel)); shape.SetElasticity(1.0f); } return(space); }
public void Update(float delta) { if (_node != null) { CCNode parent = _node.Parent; CCScene scene = _world.Scene; var vec = new cpVect(Position.X, Position.Y); CCPoint parentPosition = new CCPoint((float)vec.x, (float)vec.y); //ConvertToNodeSpace(scene.ConvertToWorldSpace(new CCPoint((float)vec.x, (float)vec.y))); cpVect position = parent != scene ? new cpVect(parentPosition.X, parentPosition.Y) : vec; //->convertToNodeSpace(scene->convertToWorldSpace(getPosition())) : getPosition(); float rotation = Rotation; for (; parent != scene; parent = parent.Parent) { rotation -= parent.RotationX; } _positionResetTag = true; _rotationResetTag = true; _node.Position = new CCPoint(position.x, position.y); _node.Rotation = (float)rotation; _positionResetTag = false; _rotationResetTag = false; // damping compute if (_isDamping && _dynamic && !IsResting()) { _info.Body.v.x *= cp.cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f); _info.Body.v.y *= cp.cpfclamp(1.0f - delta * _linearDamping, 0.0f, 1.0f); _info.Body.w *= cp.cpfclamp(1.0f - delta * _angularDamping, 0.0f, 1.0f); } } }
public override void PreStep(float dt) { cpBody a = this.a; cpBody b = this.b; this.r1 = cpTransform.Vect(a.transform, cpVect.cpvsub(this.anchorA, a.cog)); this.r2 = cpTransform.Vect(b.transform, cpVect.cpvsub(this.anchorB, b.cog)); cpVect delta = cpVect.cpvsub(cpVect.cpvadd(b.p, this.r2), cpVect.cpvadd(a.p, this.r1)); float dist = cpVect.cpvlength(delta); float pdist = 0.0f; if (dist > this.max) { pdist = dist - this.max; this.n = cpVect.cpvnormalize(delta); } else if (dist < this.min) { pdist = this.min - dist; this.n = cpVect.cpvneg(cpVect.cpvnormalize(delta)); } else { this.n = cpVect.Zero; this.jnAcc = 0.0f; } // calculate mass normal this.nMass = 1.0f / cp.k_scalar(a, b, this.r1, this.r2, this.n); // calculate bias velocity float maxBias = this.maxBias; this.bias = cp.cpfclamp(-cp.bias_coef(this.errorBias, dt) * pdist / dt, -maxBias, maxBias); }
static public cpSpace ComplexTerrainHexagons_1000(cpSpace space) { SetSubTitle("ComplexTerrainHexagons_1000"); space.SetIterations(10); space.SetGravity(new cpVect(0, -100)); space.SetCollisionSlop(0.5f); cpVect offset = new cpVect(-320, -240); for (int i = 0; i < (complex_terrain_verts.Length - 1); i++) { cpVect a = complex_terrain_verts[i], b = complex_terrain_verts[i + 1]; space.AddShape(new cpSegmentShape(space.GetStaticBody(), cpVect.cpvadd(a, offset), cpVect.cpvadd(b, offset), 0.0f)); } float radius = 5.0f; cpVect[] hexagon = new cpVect[6]; for (int i = 0; i < 6; i++) { float angle = -(float)Math.PI * 2.0f * i / 6.0f; hexagon[i] = cpVect.cpvmult(cpVect.cpv(cp.cpfcos(angle), cp.cpfsin(angle)), radius - bevel); } for (int i = 0; i < 1000; i++) { float mass = radius * radius; cpBody body = space.AddBody(new cpBody(mass, cp.MomentForPoly(mass, 6, hexagon, cpVect.Zero, 0.0f))); body.SetPosition(cpVect.cpvadd(cpVect.cpvmult(cp.frand_unit_circle(), 180.0f), new cpVect(0.0f, 300.0f))); cpShape shape = space.AddShape(new cpPolyShape(body, 6, hexagon, cpTransform.Identity, bevel)); shape.SetElasticity(0.0f); shape.SetFriction(0.0f); } return(space); }
public override void Update(float dt) { base.Update(dt); space.Step(dt); bool lastClickState = false; sliceStart = cpVect.Zero; // Annoying state tracking code that you wouldn't need // in a real event driven system. if (CCMouse.Instance.rightclick != lastClickState) { if (CCMouse.Instance.rightclick) { // MouseDown sliceStart = CCMouse.Instance.Position; } else { // MouseUp SliceContext context = new SliceContext(sliceStart, CCMouse.Instance.Position, space); space.SegmentQuery(sliceStart, CCMouse.Instance.Position, 0, GRAB_FILTER, (shape, v1, v2, d, o) => SliceQuery(shape, d, v1, (SliceContext)o), context); } lastClickState = CCMouse.Instance.rightclick; } write = CCMouse.Instance.rightclick; }
public override void Update(float dt) { base.Update(dt); float coef = (2.0f + ChipmunkDemoKeyboard.y) / 3.0f; float rate = ChipmunkDemoKeyboard.x * 30.0f * coef; motor.SetRate(rate); motor.SetMaxForce(rate > 0 ? 1000000.0f : 0.0f); space.Step(dt); for (int i = 0; i < numBalls; i++) { cpBody ball = balls[i]; cpVect pos = ball.GetPosition(); if (pos.x > 320.0f) { ball.SetVelocity(cpVect.Zero); ball.SetPosition(new cpVect(-224.0f, 200.0f)); } } }
public ClosestPoints(cpVect a, cpVect b, cpVect n, float d, ulong id) { this.a = a; this.b = b; this.n = n; this.d = d; this.id = id; }
/** Applies a continuous force to body. */ internal void ApplyImpulse(cpVect impulse, cpVect offset) { // cpBodyApplyImpulse(_info->getBody(), PhysicsHelper::point2cpv(impulse), PhysicsHelper::point2cpv(offset)); _info.Body.ApplyImpulse(impulse, offset); }
/** Applies a immediate force to body. */ internal void ApplyForce(cpVect force) { ApplyForce(force, cpVect.Zero); }
public void SetCenterOfGravity(cpVect gravity) { _info.Body.SetCenterOfGravity(gravity); }
/** convert the world point to local */ internal cpVect World2Local(cpVect point) { return(_info.Body.WorldToLocal(point)); //return PhysicsHelper::cpv2point(cpBodyWorld2Local(_info->getBody(), PhysicsHelper::point2cpv(point))); }
public override void OnEnter() { base.OnEnter(); SetSubTitle("This unicycle is completely driven and balanced by a single cpSimpleMotor.\nMove the mouse to make the unicycle follow it."); space.SetIterations(30); space.SetGravity(new cpVect(0, -500)); { cpShape shape = null; cpBody staticBody = space.GetStaticBody(); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-3200, -240), new cpVect(3200, -240), 0.0f)); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(0, -200), new cpVect(240, -240), 0.0f)); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-240, -240), new cpVect(0, -200), 0.0f)); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); shape.SetFilter(NOT_GRABBABLE_FILTER); } { float radius = 20.0f; float mass = 1.0f; float moment = cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero); wheel_body = space.AddBody(new cpBody(mass, moment)); wheel_body.SetPosition(new cpVect(0.0f, -160.0f + radius)); cpShape shape = space.AddShape(new cpCircleShape(wheel_body, radius, cpVect.Zero)); shape.SetFriction(0.7f); shape.SetFilter(new cpShapeFilter(1, cp.ALL_CATEGORIES, cp.ALL_CATEGORIES)); } { float cog_offset = 30.0f; cpBB bb1 = new cpBB(-5.0f, 0.0f - cog_offset, 5.0f, cog_offset * 1.2f - cog_offset); cpBB bb2 = new cpBB(-25.0f, bb1.t, 25.0f, bb1.t + 10.0f); float mass = 3.0f; float moment = cp.MomentForBox2(mass, bb1) + cp.MomentForBox2(mass, bb2); balance_body = space.AddBody(new cpBody(mass, moment)); balance_body.SetPosition(new cpVect(0.0f, wheel_body.GetPosition().y + cog_offset)); cpShape shape = null; shape = space.AddShape(cpPolyShape.BoxShape2(balance_body, bb1, 0.0f)); shape.SetFriction(1.0f); shape.SetFilter(new cpShapeFilter(1, cp.ALL_CATEGORIES, cp.ALL_CATEGORIES)); shape = space.AddShape(cpPolyShape.BoxShape2(balance_body, bb2, 0.0f)); shape.SetFriction(1.0f); shape.SetFilter(new cpShapeFilter(1, cp.ALL_CATEGORIES, cp.ALL_CATEGORIES)); } cpVect anchorA = balance_body.WorldToLocal(wheel_body.GetPosition()); cpVect groove_a = cpVect.cpvadd(anchorA, new cpVect(0.0f, 30.0f)); cpVect groove_b = cpVect.cpvadd(anchorA, new cpVect(0.0f, -10.0f)); space.AddConstraint(new cpGrooveJoint(balance_body, wheel_body, groove_a, groove_b, cpVect.Zero)); space.AddConstraint(new cpDampedSpring(balance_body, wheel_body, anchorA, cpVect.Zero, 0.0f, 6.0e2f, 30.0f)); motor = space.AddConstraint(new cpSimpleMotor(wheel_body, balance_body, 0.0f)); motor.SetPreSolveFunc((s) => motor_preSolve(motor, s)); { float width = 100.0f; float height = 20.0f; float mass = 3.0f; cpBody boxBody = space.AddBody(new cpBody(mass, cp.MomentForBox(mass, width, height))); boxBody.SetPosition(new cpVect(200, -100)); cpShape shape = space.AddShape(cpPolyShape.BoxShape(boxBody, width, height, 0.0f)); shape.SetFriction(0.7f); } Schedule(); }
public MinkowskiPoint(cpVect a, cpVect b, cpVect ab, ulong id) { this.a = a; this.b = b; this.ab = ab; this.id = id; }
public static Edge SupportEdgeForSegment(cpSegmentShape seg, cpVect n) { ulong hashid = seg.hashid; Edge edge; if (cpVect.cpvdot(seg.tn, n) > 0.0f) { edge = new Edge( new EdgePoint(seg.ta, cp.CP_HASH_PAIR(seg.hashid, 0)), new EdgePoint(seg.tb, cp.CP_HASH_PAIR(seg.hashid, 1)), seg.r, seg.tn); } else { edge = new Edge( new EdgePoint(seg.tb, cp.CP_HASH_PAIR(seg.hashid, 1)), new EdgePoint(seg.ta, cp.CP_HASH_PAIR(seg.hashid, 0)), seg.r, cpVect.cpvneg(seg.tn) ); } return edge; }
public static SupportPoint SegmentSupportPoint(cpSegmentShape seg, cpVect n) { if (cpVect.cpvdot(seg.ta, n) > cpVect.cpvdot(seg.tb, n)) return new SupportPoint(seg.ta, 0); else return new SupportPoint(seg.tb, 1); }
public static SupportPoint PolySupportPoint(cpPolyShape poly, cpVect n) { ulong i = PolySupportPointIndex(poly.Count, poly.planes, n); return new SupportPoint(poly.planes[i].v0, i); }
public static SupportPoint CircleSupportPoint(cpCircleShape circle, cpVect n) { return new SupportPoint(circle.tc, 0); }
public SupportPoint(cpVect p, ulong id) { this.p = p; this.id = id; }
public static MinkowskiPoint Support(ref SupportContext ctx, cpVect n) { SupportPoint a = ctx.func1(ctx.shape1, cpVect.cpvneg(n)); SupportPoint b = ctx.func2(ctx.shape2, n); return MinkowskiPointNew(a, b); }
cpSlideJointNew(cpBody a, cpBody b, cpVect anchr1, cpVect anchr2, double min, double max) { return (cpConstraint )cpSlideJointInit(cpSlideJointAlloc(), a, b, anchr1, anchr2, min, max); }
public override void SetAnchorB(cpVect anchorB) { ActivateBodies(); this.anchorB = anchorB; }
public cpBall(cpBody body, float radius, cpVect offset) : base(body, radius, offset) { }
public cpPivotJoint(cpBody a, cpBody b, cpVect pivot) : this(a, b, (a != null ? a.WorldToLocal(pivot) : pivot), (b != null ? b.WorldToLocal(pivot) : pivot)) { }
public override void OnEnter() { base.OnEnter(); SetSubTitle("Right click to make pentagons static/dynamic."); space.SetIterations(5); space.SetGravity(new cpVect(0, -100)); cpBody body, staticBody = space.GetStaticBody(); cpShape shape; // Vertexes for a triangle shape. cpVect[] tris = new cpVect[] { new cpVect(-15, -15), new cpVect(0, 10), new cpVect(15, -15), }; // Create the static triangles. for (int i = 0; i < 9; i++) { for (int j = 0; j < 6; j++) { float stagger = (j % 2) * 40; cpVect offset = new cpVect(i * 80 - 320 + stagger, j * 70 - 240); shape = space.AddShape(new cpPolyShape(staticBody, 3, tris, cpTransform.Translate(offset), 0)); shape.SetElasticity(1.0f); shape.SetFriction(1.0f); shape.SetFilter(NOT_GRABBABLE_FILTER); } } cpVect[] verts = new cpVect[NUM_VERTS]; for (int i = 0; i < NUM_VERTS; i++) { float angle = -2 * cp.M_PI * i / NUM_VERTS; verts[i] = cpVect.cpv(10 * cp.cpfcos(angle), 10 * cp.cpfsin(angle)); } pentagon_mass = 1; pentagon_moment = cp.MomentForPoly(1.0f, NUM_VERTS, verts, cpVect.Zero, 0.0f); // Add lots of pentagons. for (int i = 0; i < 100; i++) { body = space.AddBody(new cpBody(pentagon_mass, pentagon_moment)); body.SetPosition( new cpVect( RandomHelper.next(-300, 300), RandomHelper.next(350, 1000))); shape = space.AddShape(new cpPolyShape(body, NUM_VERTS, verts, cpTransform.Identity, 0.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.4f); } Schedule(); }
protected override void OnAwake() { base.OnAwake(); Vector2 pos = this.transform.position;//static body(0,0) should add postion , Dynamic use Rigidbody position as parent XRigidbody2D xRigidbody2D = this.GetComponent <XRigidbody2D>(); if (xRigidbody2D != null) { if (xRigidbody2D.mBodyType != cpBodyType.STATIC) { xRigidbody2D.Init(); mRigidbody2D = xRigidbody2D.Rigidbody2D; pos = Vector2.zero; } else { mRigidbody2D = XSpaceManager.Instance.Space.GetStaticBody(); } } else { //静态的,不能移动 mRigidbody2D = XSpaceManager.Instance.Space.GetStaticBody(); } //local Vector2 left, bottom, right, top; Quaternion rotation; switch (mShapeType) { case ColliderType.Segment: float angle = Vector2.Angle(this.mEnd - this.mStart, Vector2.right); rotation = Quaternion.AngleAxis(angle + this.transform.eulerAngles.z, Vector3.forward); left = rotation * new Vector2(this.mStart.x, this.mStart.y - this.mRadius); bottom = rotation * new Vector2(this.mEnd.x, this.mEnd.y - this.mRadius); right = rotation * new Vector2(this.mEnd.x, this.mEnd.y + this.mRadius); top = rotation * new Vector2(this.mStart.x, this.mStart.y + this.mRadius); Vector2 start = (Vector2)pos + (left + top) / 2; Vector2 end = (Vector2)pos + (bottom + right) / 2; mCollider2D = new cpSegmentShape(mRigidbody2D, new cpVect(start.x, start.y) * XSpaceManager.PixelsPerUnit, new cpVect(end.x, end.y) * XSpaceManager.PixelsPerUnit, mRadius * XSpaceManager.PixelsPerUnit); break; case ColliderType.Circle: mCollider2D = new cpCircleShape(mRigidbody2D, mRadius * XSpaceManager.PixelsPerUnit, new cpVect(pos.x + mCenter.x, pos.y + mCenter.y) * XSpaceManager.PixelsPerUnit); break; case ColliderType.Box: mCollider2D = cpPolyShape.BoxShape2(mRigidbody2D, new cpBB((pos.x + mCenter.x - mSize.x * this.transform.localScale.x / 2) * XSpaceManager.PixelsPerUnit, (pos.y + mCenter.y - mSize.y * this.transform.localScale.y / 2) * XSpaceManager.PixelsPerUnit, (pos.x + mCenter.x + mSize.x * this.transform.localScale.x / 2) * XSpaceManager.PixelsPerUnit, (pos.y + mCenter.y + mSize.y * this.transform.localScale.y / 2) * XSpaceManager.PixelsPerUnit), mRadius * XSpaceManager.PixelsPerUnit); break; case ColliderType.Polygon: int count = mVects.Length; cpVect [] vts = new cpVect [mVects.Length]; for (int i = 0; i < count; i++) { vts[i] = cpVect.Zero; vts[i].x = (pos.x + mVects[i].x) * XSpaceManager.PixelsPerUnit; vts[i].y = (pos.y + mVects[i].y) * XSpaceManager.PixelsPerUnit; } mCollider2D = new cpPolyShape(mRigidbody2D, mVects.Length, vts, mRadius * XSpaceManager.PixelsPerUnit); break; //case cpShapeType.NumShapes: // break; } mCollider2D.SetSensor(mTrigger); mCollider2D.SetElasticity(mElasticity); mCollider2D.SetFriction(mFriction); cpShapeFilter filter = new cpShapeFilter(mGroup, (int)mCategory, (int)mMask); mCollider2D.SetFilter(filter); }
public override void OnEnter() { base.OnEnter(); SetSubTitle("Use the arrow keys to control the machine."); space.SetGravity(new cpVect(0, -600)); cpBody staticBody = space.GetStaticBody(); cpShape shape; // beveling all of the line segments slightly helps prevent things from getting stuck on cracks shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-256, 16), new cpVect(-256, 300), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-256, 16), new cpVect(-192, 0), 2.0f)); shape.SetElasticity(0.0f); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-192, 0), new cpVect(-192, -64), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-128, -64), new cpVect(-128, 144), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-192, 80), new cpVect(-192, 176), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-192, 176), new cpVect(-128, 240), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); shape = space.AddShape(new cpSegmentShape(staticBody, new cpVect(-128, 144), new cpVect(192, 64), 2.0f)); shape.SetElasticity(0.0f); shape.SetFriction(0.5f); shape.SetFilter(NOT_GRABBABLE_FILTER); cpVect[] verts = new cpVect[] { new cpVect(-30, -80), new cpVect(-30, 80), new cpVect(30, 64), new cpVect(30, -80), }; cpBody plunger = space.AddBody(new cpBody(1.0f, cp.Infinity)); plunger.SetPosition(new cpVect(-160, -80)); shape = space.AddShape(new cpPolyShape(plunger, 4, verts, cpTransform.Identity, 0)); shape.SetElasticity(1.0f); shape.SetFriction(0.5f); shape.SetFilter(new cpShapeFilter(cp.NO_GROUP, 1, 1)); balls = new cpBody[numBalls]; // add balls to hopper for (int i = 0; i < numBalls; i++) { balls[i] = add_ball(space, new cpVect(-224 + i, 80 + 64 * i)); } // add small gear cpBody smallGear = space.AddBody(new cpBody(10.0f, cp.MomentForCircle(10.0f, 80, 0, cpVect.Zero))); smallGear.SetPosition(new cpVect(-160, -160)); smallGear.SetAngle(-cp.M_PI_2); shape = space.AddShape(new cpCircleShape(smallGear, 80.0f, cpVect.Zero)); shape.SetFilter(cpShape.FILTER_NONE); space.AddConstraint(new cpPivotJoint(staticBody, smallGear, new cpVect(-160, -160), cpVect.Zero)); // add big gear cpBody bigGear = space.AddBody(new cpBody(40.0f, cp.MomentForCircle(40.0f, 160, 0, cpVect.Zero))); bigGear.SetPosition(new cpVect(80, -160)); bigGear.SetAngle(cp.M_PI_2); shape = space.AddShape(new cpCircleShape(bigGear, 160.0f, cpVect.Zero)); shape.SetFilter(cpShape.FILTER_NONE); space.AddConstraint(new cpPivotJoint(staticBody, bigGear, new cpVect(80, -160), cpVect.Zero)); // connect the plunger to the small gear. space.AddConstraint(new cpPinJoint(smallGear, plunger, new cpVect(80, 0), new cpVect(0, 0))); // connect the gears. space.AddConstraint(new cpGearJoint(smallGear, bigGear, -cp.M_PI_2, -2.0f)); // feeder mechanism float bottom = -300.0f; float top = 32.0f; cpBody feeder = space.AddBody(new cpBody(1.0f, cp.MomentForSegment(1.0f, new cpVect(-224.0f, bottom), new cpVect(-224.0f, top), 0.0f))); feeder.SetPosition(new cpVect(-224, (bottom + top) / 2.0f)); float len = top - bottom; shape = space.AddShape(new cpSegmentShape(feeder, new cpVect(0.0f, len / 2.0f), new cpVect(0.0f, -len / 2.0f), 20.0f)); shape.SetFilter(GRAB_FILTER); space.AddConstraint(new cpPivotJoint(staticBody, feeder, new cpVect(-224.0f, bottom), new cpVect(0.0f, -len / 2.0f))); cpVect anchr = feeder.WorldToLocal(new cpVect(-224.0f, -160.0f)); space.AddConstraint(new cpPinJoint(feeder, smallGear, anchr, new cpVect(0.0f, 80.0f))); // motorize the second gear motor = space.AddConstraint(new cpSimpleMotor(staticBody, bigGear, 3.0f)); Schedule(); }
/** convert the local point to world */ internal cpVect Local2World(cpVect point) { return(_info.Body.LocalToWorld(point)); }
public WorleyContex(int seed, float cellSize, int width, int height, cpBB bb, cpVect focus) { // TODO: Complete member initialization this.seed = seed; this.cellSize = cellSize; this.width = width; this.height = height; this.bb = bb; this.focus = focus; }
public Edge(EdgePoint a, EdgePoint b, float r, cpVect n) { this.a = a; this.b = b; this.r = r; this.n = n; }
//TODO: This conversion methods don't be necesary, Cocosharp works with cpVect //Because there are 2 physics engine Vec2 is a intermedial class to use cpVect and b2Vect or any other engine //public static cpVect cpv2point(cpVect vec) { return new cpVect(vec.x, vec.y); } // public static cpVect point2cpv(cpVect point) { return new cpVect(point.x, point.y); } public static CCSize cpv2size(cpVect vec) { return(new CCSize((float)vec.x, (float)vec.y)); }
/** Applies a continuous force to body. */ internal void ApplyImpulse(cpVect impulse) { ApplyImpulse(impulse, cpVect.Zero); }
public static Edge SupportEdgeForPoly(cpPolyShape poly, cpVect n) { ulong count = (ulong)poly.Count; ulong i1 = cpCollision.PolySupportPointIndex(poly.Count, poly.planes, n); // TODO get rid of mod eventually, very expensive on ARM ulong i0 = (ulong)((i1 - 1 + count) % count); ulong i2 = (ulong)((i1 + 1) % count); cpSplittingPlane[] planes = poly.planes; ulong hashid = poly.hashid; if (cpVect.cpvdot(n, planes[i1].n) > cpVect.cpvdot(n, planes[i2].n)) { Edge edge = new Edge( new EdgePoint(planes[i0].v0, cp.CP_HASH_PAIR(hashid, i0)), new EdgePoint(planes[i1].v0, cp.CP_HASH_PAIR(hashid, i1)), poly.r, poly.planes[i1].n); return edge; } else { Edge edge = new Edge( new EdgePoint(planes[i1].v0, cp.CP_HASH_PAIR(hashid, i1)), new EdgePoint(planes[i2].v0, cp.CP_HASH_PAIR(hashid, i2)), poly.r, poly.planes[i2].n); return edge; } }
/** get the angular velocity of a body at a world point */ internal cpVect GetVelocityAtWorldPoint(cpVect point) { return(_info.Body.GetVelocityAtWorldPoint(point)); }
public void ScaleIterator(cpBody body, cpArbiter arb, ref cpVect sum) { sum = cpVect.cpvadd(sum, arb.TotalImpulse()); }
cpSlideJointInit(cpSlideJoint *joint, cpBody a, cpBody b, cpVect anchr1, cpVect anchr2, double min, double max) { cpConstraintInit((cpConstraint )joint, &klass, a, b); joint.anchr1 = anchr1; joint.anchr2 = anchr2; joint.min = min; joint.max = max; joint.jnAcc = 0.0f; return joint; }
public cpContact(cpVect r1, cpVect r2, ulong hash) { Init(r1, r2, hash); }
public override void SetAnchorA(cpVect anchorA) { ActivateBodies(); this.anchorA = anchorA; }
public static Edge EdgeNew(cpVect va, cpVect vb, ulong ha, ulong hb, float r) { return new Edge( new EdgePoint(va, ha), new EdgePoint(vb, hb), r, cpVect.cpvnormalize(cpVect.cpvperp(cpVect.cpvsub(vb, va)))); }
public CCMouse() { mouseBody = cpBody.NewKinematic(); Position = cpVect.Zero; }
public EdgePoint(cpVect p, ulong hash) { this.p = p; this.hash = hash; }
internal static CCPoint cpVectToCCPoint(cpVect vec) { return(new CCPoint((float)vec.x, (float)vec.y)); }
public CrushingContext(float magnitudeSum, cpVect vectorSum) { // TODO: Complete member initialization this.magnitudeSum = magnitudeSum; this.vectorSum = vectorSum; }