public PDragJoint(PBody b_0, float px, float py) { this.b = b_0; dragPoint = new Vector2f(px, py); localAnchor = new Vector2f(px - b_0.pos.x, py - b_0.pos.y); b_0.mAng.Transpose().MulEqual(localAnchor); anchor = b_0.mAng.Mul(localAnchor); anchor.AddLocal(b_0.pos); type = Physics.PJointType.DRAG_JOINT; mass = new PTransformer(); }
public PHingeJoint(PBody b1_0, PBody b2_1, float rel1x, float rel1y, float rel2x, float rel2y) { this.b1 = b1_0; this.b2 = b2_1; localAngle = b2_1.ang - b1_0.ang; localAnchor1 = new Vector2f(rel1x, rel1y); localAnchor2 = new Vector2f(rel2x, rel2y); b1_0.mAng.Transpose().MulEqual(localAnchor1); b2_1.mAng.Transpose().MulEqual(localAnchor2); anchor1 = b1_0.mAng.Mul(localAnchor1); anchor1.AddLocal(b1_0.pos); anchor2 = b2_1.mAng.Mul(localAnchor2); anchor2.AddLocal(b2_1.pos); type = Physics.PJointType.HINGE_JOINT; mass = new PTransformer(); impulse = new Vector2f(); }
internal override void SolveVelocity(float dt) { Vector2f relVel = PTransformer.CalcRelativeVelocity(b1, b2, relAnchor1, relAnchor2); Vector2f force = mass.Mul(relVel).Negate(); impulse.AddLocal(force); b1.ApplyImpulse(force.x, force.y, anchor1.x, anchor1.y); b2.ApplyImpulse(-force.x, -force.y, anchor2.x, anchor2.y); if (enableMotor) { float angRelVel = b2.angVel - b1.angVel - motorSpeed; float torque = angM * angRelVel; float subMotorI = motI; motI = MathUtils.Clamp(motI + torque, -motorTorque * dt, motorTorque * dt); torque = motI - subMotorI; b1.ApplyTorque(torque); b2.ApplyTorque(-torque); } if (enableLimit && limitState != 0) { float angRelVel_0 = b2.angVel - b1.angVel - targetAngleSpeed; float torque_1 = angM * angRelVel_0; float subLimitI = limI; if (limitState == -1) { limI = MathUtils.Min(limI + torque_1, 0.0F); } else { if (limitState == 1) { limI = MathUtils.Max(limI + torque_1, 0.0F); } } torque_1 = limI - subLimitI; b1.ApplyTorque(torque_1); b2.ApplyTorque(-torque_1); } }
protected internal void DrawString(SpriteBatch batch, string cs, Vector2f local, LColor color, float rotation, Vector2f origin, Vector2f scale, SpriteEffects spriteEffects) { pos.Set(0, 0); int flip = 1; float beginningofline = 0f; bool flag = true; if (spriteEffects == SpriteEffects.FlipHorizontally) { beginningofline = this.Measure(cs).x *scale.x; flip = -1; } if (spriteEffects == SpriteEffects.FlipVertically) { pos.y = (this.Measure(cs).y - this.lineSpacing) * scale.y; } else { pos.y = 0f; } pos.x = beginningofline; for (int i = 0; i < cs.Length; i++) { char character = cs[i]; switch ((int)character) { case '\r': break; case '\n': flag = true; pos.x = beginningofline; if (spriteEffects == SpriteEffects.FlipVertically) { pos.y -= this.lineSpacing * scale.y; } else { pos.y += this.lineSpacing * scale.y; } break; default: { int indexForCharacter = this.CharacterIndex(character); float[] charkerning = this.kerning[indexForCharacter]; if (flag) { charkerning[0] = Math.Max(charkerning[0], 0f); } else { pos.x += (this.spacing * scale.x) * flip; } pos.x += (charkerning[0] * scale.x) * flip; RectBox rectangle = this.glyphs[indexForCharacter]; RectBox rectangle2 = this.cropping[indexForCharacter]; Vector2f position = pos.Cpy(); position.x += rectangle2.x * scale.x; position.y += rectangle2.y * scale.y; position.AddLocal(local); batch.Draw(this.texture, position, rectangle, color, rotation, origin, scale, spriteEffects); flag = false; pos.x += ((charkerning[1] + charkerning[2]) * scale.x) * flip; break; } } } }