cpPulleyJoint * cpPulleyJointInit(cpPulleyJoint *joint, cpBody* a, cpBody* b, cpBody* c, cpVect anchor1, cpVect anchor2, cpVect anchor3a, cpVect anchor3b, cpFloat ratio) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->c = c; joint->anchr3a = anchor3a; joint->anchr3b = anchor3b; joint->anchr1 = anchor1; joint->anchr2 = anchor2; cpVect d1 = cpvsub(cpBodyLocal2World(a, anchor1), cpBodyLocal2World(c, anchor3a)); cpVect d2 = cpvsub(cpBodyLocal2World(b, anchor2), cpBodyLocal2World(c, anchor3b)); joint->dist1 = cpvlength(d1); joint->dist2 = cpvlength(d2); joint->ratio = ratio; cpAssert(ratio != 0.0f, "Pulley Ratio is Zero"); // Calculate max and constant joint->constant = joint->dist1 + ratio * joint->dist2; joint->max1 = joint->constant - ratio * cp_min_pulley_len; joint->max2 = (joint->constant - cp_min_pulley_len) / joint->ratio; // Initialize joint->jnAcc = 0.0f; joint->jnAccLim1 = 0.0f; joint->jnAccLim2 = 0.0f; return joint; }
cpSimpleMotor * cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->rate = rate; joint->jAcc = 0.0f; return joint; }
cpDampedRotarySpring * cpDampedRotarySpringInit(cpDampedRotarySpring *spring, cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping) { cpConstraintInit((cpConstraint *)spring, &cpDampedRotarySpringClass, a, b); spring->restAngle = restAngle; spring->stiffness = stiffness; spring->damping = damping; return spring; }
cpRotaryLimitJoint * cpRotaryLimitJointInit(cpRotaryLimitJoint *joint, cpBody *a, cpBody *b, cpFloat min, cpFloat max) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->min = min; joint->max = max; joint->jAcc = 0.0f; return joint; }
cpPivotJoint * cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->anchr1 = anchr1; joint->anchr2 = anchr2; joint->jAcc = cpvzero; return joint; }
cpDampedRotarySpring * cpDampedRotarySpringInit(cpDampedRotarySpring *spring, cpBody *a, cpBody *b, cpFloat restAngle, cpFloat stiffness, cpFloat damping) { cpConstraintInit((cpConstraint *)spring, &klass, a, b); spring->restAngle = restAngle; spring->stiffness = stiffness; spring->damping = damping; spring->springTorqueFunc = (cpDampedRotarySpringTorqueFunc)defaultSpringTorque; return spring; }
cpPivotJoint * cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->anchorA = anchorA; joint->anchorB = anchorB; joint->jAcc = cpvzero; return joint; }
cpGearJoint * cpGearJointInit(cpGearJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratio) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->phase = phase; joint->ratio = ratio; joint->ratio_inv = 1.0f/ratio; joint->jAcc = 0.0f; return joint; }
cpOscillatingMotor * cpOscillatingMotorInit(cpOscillatingMotor *joint, cpBody *a, cpBody *b, cpFloat frequency, cpFloat amplitude, cpFloat phaseShift) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->frequency = frequency; joint->amplitude = amplitude; joint->phaseShift = phaseShift; joint->t = 0.0f; joint->jAcc = 0.0f; return joint; }
cpRatchetJoint * cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->angle = 0.0f; joint->phase = phase; joint->ratchet = ratchet; joint->angle = b->a - a->a; return joint; }
cpSlideJoint * cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat 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; }
cpPivotJoint * cpPivotJointInit(cpPivotJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); // joint->anchr1 = cpvunrotate(cpvsub(pivot, a->p), a->rot); // joint->anchr2 = cpvunrotate(cpvsub(pivot, b->p), b->rot); joint->anchr1 = anchr1; joint->anchr2 = anchr2; joint->jAcc = cpvzero; return joint; }
cpRatchetJoint * cpRatchetJointInit(cpRatchetJoint *joint, cpBody *a, cpBody *b, cpFloat phase, cpFloat ratchet) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->angle = 0.0f; joint->phase = phase; joint->ratchet = ratchet; // STATIC_BODY_CHECK joint->angle = (b ? b->a : 0.0f) - (a ? a->a : 0.0f); return joint; }
cpGrooveJoint * cpGrooveJointInit(cpGrooveJoint *joint, cpBody *a, cpBody *b, cpVect groove_a, cpVect groove_b, cpVect anchorB) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->grv_a = groove_a; joint->grv_b = groove_b; joint->grv_n = cpvperp(cpvnormalize(cpvsub(groove_b, groove_a))); joint->anchorB = anchorB; joint->jAcc = cpvzero; return joint; }
cpDampedSpring * cpDampedSpringInit(cpDampedSpring *spring, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping) { cpConstraintInit((cpConstraint *)spring, cpDampedSpringGetClass(), a, b); spring->anchr1 = anchr1; spring->anchr2 = anchr2; spring->restLength = restLength; spring->stiffness = stiffness; spring->damping = damping; spring->springForceFunc = (cpDampedSpringForceFunc)defaultSpringForce; return spring; }
cpPinJoint * cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->anchr1 = anchr1; joint->anchr2 = anchr2; // STATIC_BODY_CHECK cpVect p1 = (a ? cpvadd(a->p, cpvrotate(anchr1, a->rot)) : anchr1); cpVect p2 = (b ? cpvadd(b->p, cpvrotate(anchr2, b->rot)) : anchr2); joint->dist = cpvlength(cpvsub(p2, p1)); joint->jnAcc = 0.0f; return joint; }
cpPinJoint * cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchorA, cpVect anchorB) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->anchorA = anchorA; joint->anchorB = anchorB; // STATIC_BODY_CHECK cpVect p1 = (a ? cpTransformPoint(a->transform, anchorA) : anchorA); cpVect p2 = (b ? cpTransformPoint(b->transform, anchorB) : anchorB); joint->dist = cpvlength(cpvsub(p2, p1)); cpAssertWarn(joint->dist > 0.0, "You created a 0 length pin joint. A pivot joint will be much more stable."); joint->jnAcc = 0.0f; return joint; }
cpPinJoint * cpPinJointInit(cpPinJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2) { cpConstraintInit((cpConstraint *)joint, &klass, a, b); joint->anchr1 = anchr1; joint->anchr2 = anchr2; // STATIC_BODY_CHECK cpVect p1 = (a ? cpvadd(a->p, cpvrotate(anchr1, a->rot)) : anchr1); cpVect p2 = (b ? cpvadd(b->p, cpvrotate(anchr2, b->rot)) : anchr2); joint->dist = cpvlength(cpvsub(p2, p1)); cpAssertWarn(joint->dist > 0.0, "You created a 0 length pin joint. A pivot joint will be much more stable."); joint->jnAcc = 0.0f; return joint; }