public void dJointAttach(DBody b1, DBody b2) { DxBody body1 = (DxBody) b1; DxBody body2 = (DxBody) b2; // check arguments // dUASSERT (joint,"bad joint argument"); dUASSERT(body1 == null || body1 != body2, "can't have body1==body2"); DxWorld world = this.world; dUASSERT( (body1 == null || body1.getWorld() == world) && (body2 == null || body2.getWorld() == world), "joint and bodies must be in same world"); // check if the joint can not be attached to just one body dUASSERT( !((flags & dJOINT_TWOBODIES) != 0 && ((body1 != null) ^ (body2 != null))), "joint can not be attached to just one body"); // remove any existing body attachments if (node[0].body != null || node[1].body != null) { removeJointReferencesFromAttachedBodies(); } // if a body is zero, make sure that it is body2, so 0 --> node[1].body if (body1 == null) { body1 = body2; body2 = null; flags |= dJOINT_REVERSE; } else { flags &= (~dJOINT_REVERSE); } // attach to new bodies node[0].body = body1; node[1].body = body2; if (body1 != null) { node[1].next = body1.firstjoint.get(); body1.firstjoint.set(node[1]); } else node[1].next = null; if (body2 != null) { node[0].next = body2.firstjoint.get(); body2.firstjoint.set(node[0]); } else { node[0].next = null; } // Since the bodies are now set. // Calculate the values depending on the bodies. // Only need to calculate relative value if a body exist if (body1 != null || body2 != null) setRelativeValues(); }