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.collision; 25 26 import org.jbox2d.common.Settings; 27 import org.jbox2d.common.Vec2; 28 29 /** 30 * A manifold for two touching convex shapes. Box2D supports multiple types of contact: 31 * <ul> 32 * <li>clip point versus plane with radius</li> 33 * <li>point versus point with radius (circles)</li> 34 * </ul> 35 * The local point usage depends on the manifold type: 36 * <ul> 37 * <li>e_circles: the local center of circleA</li> 38 * <li>e_faceA: the center of faceA</li> 39 * <li>e_faceB: the center of faceB</li> 40 * </ul> 41 * Similarly the local normal usage: 42 * <ul> 43 * <li>e_circles: not used</li> 44 * <li>e_faceA: the normal on polygonA</li> 45 * <li>e_faceB: the normal on polygonB</li> 46 * </ul> 47 * We store contacts in this way so that position correction can account for movement, which is 48 * critical for continuous physics. All contact scenarios must be expressed in one of these types. 49 * This structure is stored across time steps, so we keep it small. 50 */ 51 public class Manifold { 52 53 public static enum ManifoldType { 54 CIRCLES, FACE_A, FACE_B 55 } 56 57 /** The points of contact. */ 58 public final ManifoldPoint[] points; 59 60 /** not use for Type::e_points */ 61 public final Vec2 localNormal; 62 63 /** usage depends on manifold type */ 64 public final Vec2 localPoint; 65 66 public ManifoldType type; 67 68 /** The number of manifold points. */ 69 public int pointCount; 70 71 /** 72 * creates a manifold with 0 points, with it's points array full of instantiated ManifoldPoints. 73 */ 74 public Manifold() { 75 points = new ManifoldPoint[Settings.maxManifoldPoints]; 76 for (int i = 0; i < Settings.maxManifoldPoints; i++) { 77 points[i] = new ManifoldPoint(); 78 } 79 localNormal = new Vec2(); 80 localPoint = new Vec2(); 81 pointCount = 0; 82 } 83 84 /** 85 * Creates this manifold as a copy of the other 86 * 87 * @param other 88 */ 89 public Manifold(Manifold other) { 90 points = new ManifoldPoint[Settings.maxManifoldPoints]; 91 localNormal = other.localNormal.clone(); 92 localPoint = other.localPoint.clone(); 93 pointCount = other.pointCount; 94 type = other.type; 95 // djm: this is correct now 96 for (int i = 0; i < Settings.maxManifoldPoints; i++) { 97 points[i] = new ManifoldPoint(other.points[i]); 98 } 99 } 100 101 /** 102 * copies this manifold from the given one 103 * 104 * @param cp manifold to copy from 105 */ 106 public void set(Manifold cp) { 107 for (int i = 0; i < cp.pointCount; i++) { 108 points[i].set(cp.points[i]); 109 } 110 111 type = cp.type; 112 localNormal.set(cp.localNormal); 113 localPoint.set(cp.localPoint); 114 pointCount = cp.pointCount; 115 } 116 } 117