Home | History | Annotate | Download | only in joints
      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 /**
     25  * Created at 7:27:31 AM Jan 21, 2011
     26  */
     27 package org.jbox2d.dynamics.joints;
     28 
     29 import org.jbox2d.common.Vec2;
     30 import org.jbox2d.dynamics.Body;
     31 
     32 /**
     33  * Wheel joint definition. This requires defining a line of motion using an axis and an anchor
     34  * point. The definition uses local anchor points and a local axis so that the initial configuration
     35  * can violate the constraint slightly. The joint translation is zero when the local anchor points
     36  * coincide in world space. Using local anchors and a local axis helps when saving and loading a
     37  * game.
     38  *
     39  * @author Daniel Murphy
     40  */
     41 public class WheelJointDef extends JointDef {
     42 
     43   /**
     44    * The local anchor point relative to body1's origin.
     45    */
     46   public final Vec2 localAnchorA = new Vec2();
     47 
     48   /**
     49    * The local anchor point relative to body2's origin.
     50    */
     51   public final Vec2 localAnchorB = new Vec2();
     52 
     53   /**
     54    * The local translation axis in body1.
     55    */
     56   public final Vec2 localAxisA = new Vec2();
     57 
     58   /**
     59    * Enable/disable the joint motor.
     60    */
     61   public boolean enableMotor;
     62 
     63   /**
     64    * The maximum motor torque, usually in N-m.
     65    */
     66   public float maxMotorTorque;
     67 
     68   /**
     69    * The desired motor speed in radians per second.
     70    */
     71   public float motorSpeed;
     72 
     73   /**
     74    * Suspension frequency, zero indicates no suspension
     75    */
     76   public float frequencyHz;
     77 
     78   /**
     79    * Suspension damping ratio, one indicates critical damping
     80    */
     81   public float dampingRatio;
     82 
     83   public WheelJointDef() {
     84     super(JointType.WHEEL);
     85     localAxisA.set(1, 0);
     86     enableMotor = false;
     87     maxMotorTorque = 0f;
     88     motorSpeed = 0f;
     89   }
     90 
     91   public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) {
     92     bodyA = b1;
     93     bodyB = b2;
     94     b1.getLocalPointToOut(anchor, localAnchorA);
     95     b2.getLocalPointToOut(anchor, localAnchorB);
     96     bodyA.getLocalVectorToOut(axis, localAxisA);
     97   }
     98 }
     99