p = attached point, m = mouse point C = p - m Cdot = v = v + cross(w, r) J = [I r_skew] Identity used: w k % (rx i + ry j) = w * (-ry i + rx j)
(def *B2MouseJointDef)
| 85 | // w k % (rx i + ry j) = w * (-ry i + rx j) |
| 86 | |
| 87 | func MakeB2MouseJoint(def *B2MouseJointDef) *B2MouseJoint { |
| 88 | res := B2MouseJoint{ |
| 89 | B2Joint: MakeB2Joint(def), |
| 90 | } |
| 91 | |
| 92 | B2Assert(def.Target.IsValid()) |
| 93 | B2Assert(B2IsValid(def.MaxForce) && def.MaxForce >= 0.0) |
| 94 | B2Assert(B2IsValid(def.FrequencyHz) && def.FrequencyHz >= 0.0) |
| 95 | B2Assert(B2IsValid(def.DampingRatio) && def.DampingRatio >= 0.0) |
| 96 | |
| 97 | res.M_targetA = def.Target |
| 98 | res.M_localAnchorB = B2TransformVec2MulT(res.M_bodyB.GetTransform(), res.M_targetA) |
| 99 | |
| 100 | res.M_maxForce = def.MaxForce |
| 101 | res.M_impulse.SetZero() |
| 102 | |
| 103 | res.M_frequencyHz = def.FrequencyHz |
| 104 | res.M_dampingRatio = def.DampingRatio |
| 105 | |
| 106 | res.M_beta = 0.0 |
| 107 | res.M_gamma = 0.0 |
| 108 | |
| 109 | return &res |
| 110 | } |
| 111 | |
| 112 | func (joint *B2MouseJoint) SetTarget(target B2Vec2) { |
| 113 | if target != joint.M_targetA { |
no test coverage detected