1 /******************************************************************************* 2 * Copyright (c) 2013, Daniel Murphy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * * Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 * POSSIBILITY OF SUCH DAMAGE. 23 ******************************************************************************/ 24 package org.jbox2d.dynamics.joints; 25 26 import java.util.ArrayList; 27 28 import org.jbox2d.dynamics.Body; 29 30 /** 31 * Definition for a {@link ConstantVolumeJoint}, which connects a group a bodies together so they 32 * maintain a constant volume within them. 33 */ 34 public class ConstantVolumeJointDef extends JointDef { 35 public float frequencyHz; 36 public float dampingRatio; 37 38 ArrayList<Body> bodies; 39 ArrayList<DistanceJoint> joints; 40 41 public ConstantVolumeJointDef() { 42 super(JointType.CONSTANT_VOLUME); 43 bodies = new ArrayList<Body>(); 44 joints = null; 45 collideConnected = false; 46 frequencyHz = 0.0f; 47 dampingRatio = 0.0f; 48 } 49 50 /** 51 * Adds a body to the group 52 * 53 * @param argBody 54 */ 55 public void addBody(Body argBody) { 56 bodies.add(argBody); 57 if (bodies.size() == 1) { 58 bodyA = argBody; 59 } 60 if (bodies.size() == 2) { 61 bodyB = argBody; 62 } 63 } 64 65 /** 66 * Adds a body and the pre-made distance joint. Should only be used for deserialization. 67 */ 68 public void addBodyAndJoint(Body argBody, DistanceJoint argJoint) { 69 addBody(argBody); 70 if (joints == null) { 71 joints = new ArrayList<DistanceJoint>(); 72 } 73 joints.add(argJoint); 74 } 75 } 76