@Override public void computeMass(MassData massData, float density) { massData.mass = 0.0f; massData.center.setZero(); massData.I = 0.0f; }
/** * Set the sleep state of the body. A sleeping body has very low CPU cost. * * @param flag set to true to put body to sleep, false to wake it. * @param flag */ public void setAwake(boolean flag) { if (flag) { if ((m_flags & e_awakeFlag) == 0) { m_flags |= e_awakeFlag; m_sleepTime = 0.0f; } } else { m_flags &= ~e_awakeFlag; m_sleepTime = 0.0f; m_linearVelocity.setZero(); m_angularVelocity = 0.0f; m_force.setZero(); m_torque = 0.0f; } }
/** Set this to the identity transform. */ public final void setIdentity() { p.setZero(); q.setIdentity(); }
/** * Call this after you are done with time steps to clear the forces. You normally call this after * each call to Step, unless you are performing sub-steps. By default, forces will be * automatically cleared, so you don't need to call this function. * * @see setAutoClearForces */ public void clearForces() { for (Body body = m_bodyList; body != null; body = body.getNext()) { body.m_force.setZero(); body.m_torque = 0.0f; } }
/** * Create a chain with isolated end vertices. * * @param vertices an array of vertices, these are copied * @param count the vertex count */ public void createChain(final Vec2 vertices[], int count) { assert (m_vertices == null && m_count == 0); assert (count >= 2); m_count = count; m_vertices = new Vec2[m_count]; for (int i = 1; i < m_count; i++) { Vec2 v1 = vertices[i - 1]; Vec2 v2 = vertices[i]; // If the code crashes here, it means your vertices are too close together. if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) { throw new RuntimeException("Vertices of chain shape are too close together"); } } for (int i = 0; i < m_count; i++) { m_vertices[i] = new Vec2(vertices[i]); } m_hasPrevVertex = false; m_hasNextVertex = false; m_prevVertex.setZero(); m_nextVertex.setZero(); }
public PolygonShape() { super(ShapeType.POLYGON); m_count = 0; m_vertices = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_vertices.length; i++) { m_vertices[i] = new Vec2(); } m_normals = new Vec2[Settings.maxPolygonVertices]; for (int i = 0; i < m_normals.length; i++) { m_normals[i] = new Vec2(); } setRadius(Settings.polygonRadius); m_centroid.setZero(); }
/** * this returns pooled objects. don't keep or modify them * * @return */ public void getClosestPoint(final Vec2 out) { switch (m_count) { case 0: assert (false); out.setZero(); return; case 1: out.set(m_v1.w); return; case 2: case22.set(m_v2.w).mulLocal(m_v2.a); case2.set(m_v1.w).mulLocal(m_v1.a).addLocal(case22); out.set(case2); return; case 3: out.setZero(); return; default: assert (false); out.setZero(); return; } }
protected MouseJoint(IWorldPool argWorld, MouseJointDef def) { super(argWorld, def); assert (def.target.isValid()); assert (def.maxForce >= 0); assert (def.frequencyHz >= 0); assert (def.dampingRatio >= 0); m_targetA.set(def.target); Transform.mulTransToOutUnsafe(m_bodyB.getTransform(), m_targetA, m_localAnchorB); m_maxForce = def.maxForce; m_impulse.setZero(); m_frequencyHz = def.frequencyHz; m_dampingRatio = def.dampingRatio; m_beta = 0; m_gamma = 0; }
manifold.localNormal.setZero(); manifold.pointCount = 1;
for (int i = 0; i < m_count; i++) { m_accumulationBuffer[i] = 0; m_accumulation2Buffer[i].setZero();
/** * Build vertices to represent an axis-aligned box. * * @param hx the half-width. * @param hy the half-height. */ public final void setAsBox(final float hx, final float hy) { m_count = 4; m_vertices[0].set(-hx, -hy); m_vertices[1].set(hx, -hy); m_vertices[2].set(hx, hy); m_vertices[3].set(-hx, hy); m_normals[0].set(0.0f, -1.0f); m_normals[1].set(1.0f, 0.0f); m_normals[2].set(0.0f, 1.0f); m_normals[3].set(-1.0f, 0.0f); m_centroid.setZero(); }
public final void getSearchDirection(final Vec2 out) { switch (m_count) { case 1: out.set(m_v1.w).negateLocal(); return; case 2: e12.set(m_v2.w).subLocal(m_v1.w); // use out for a temp variable real quick out.set(m_v1.w).negateLocal(); float sgn = Vec2.cross(e12, out); if (sgn > 0f) { // Origin is left of e12. Vec2.crossToOutUnsafe(1f, e12, out); return; } else { // Origin is right of e12. Vec2.crossToOutUnsafe(e12, 1f, out); return; } default: assert (false); out.setZero(); return; } }
public final void computeCentroidToOut(final Vec2[] vs, final int count, final Vec2 out) { assert (count >= 3); out.set(0.0f, 0.0f); float area = 0.0f; // pRef is the reference point for forming triangles. // It's location doesn't change the result (except for rounding error). final Vec2 pRef = pool1; pRef.setZero(); final Vec2 e1 = pool2; final Vec2 e2 = pool3; final float inv3 = 1.0f / 3.0f; for (int i = 0; i < count; ++i) { // Triangle vertices. final Vec2 p1 = pRef; final Vec2 p2 = vs[i]; final Vec2 p3 = i + 1 < count ? vs[i + 1] : vs[0]; e1.set(p2).subLocal(p1); e2.set(p3).subLocal(p1); final float D = Vec2.cross(e1, e2); final float triangleArea = 0.5f * D; area += triangleArea; // Area weighted centroid e1.set(p1).addLocal(p2).addLocal(p3).mulLocal(triangleArea * inv3); out.addLocal(e1); } // Centroid assert (area > Settings.EPSILON); out.mulLocal(1.0f / area); }
wB += m_invIB * Vec2.cross(m_rB, m_impulse); } else { m_impulse.setZero();