Search in sources :

Example 26 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class ChainShape method raycast.

@Override
public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
    assert (childIndex < m_count);
    final EdgeShape edgeShape = pool0;
    int i1 = childIndex;
    int i2 = childIndex + 1;
    if (i2 == m_count) {
        i2 = 0;
    }
    Vec2 v = m_vertices[i1];
    edgeShape.m_vertex1.x = v.x;
    edgeShape.m_vertex1.y = v.y;
    Vec2 v1 = m_vertices[i2];
    edgeShape.m_vertex2.x = v1.x;
    edgeShape.m_vertex2.y = v1.y;
    return edgeShape.raycast(output, input, xf, 0);
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 27 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class ChainShape method createLoop.

/**
   * Create a loop. This automatically adjusts connectivity.
   * 
   * @param vertices an array of vertices, these are copied
   * @param count the vertex count
   */
public void createLoop(final Vec2[] vertices, int count) {
    assert (m_vertices == null && m_count == 0);
    assert (count >= 3);
    m_count = count + 1;
    m_vertices = new Vec2[m_count];
    for (int i = 1; i < 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 < count; i++) {
        m_vertices[i] = new Vec2(vertices[i]);
    }
    m_vertices[count] = new Vec2(m_vertices[0]);
    m_prevVertex.set(m_vertices[m_count - 2]);
    m_nextVertex.set(m_vertices[1]);
    m_hasPrevVertex = true;
    m_hasNextVertex = true;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 28 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class ChainShape method getChildEdge.

/**
   * Get a child edge.
   */
public void getChildEdge(EdgeShape edge, int index) {
    assert (0 <= index && index < m_count - 1);
    edge.m_radius = m_radius;
    final Vec2 v0 = m_vertices[index + 0];
    final Vec2 v1 = m_vertices[index + 1];
    edge.m_vertex1.x = v0.x;
    edge.m_vertex1.y = v0.y;
    edge.m_vertex2.x = v1.x;
    edge.m_vertex2.y = v1.y;
    if (index > 0) {
        Vec2 v = m_vertices[index - 1];
        edge.m_vertex0.x = v.x;
        edge.m_vertex0.y = v.y;
        edge.m_hasVertex0 = true;
    } else {
        edge.m_vertex0.x = m_prevVertex.x;
        edge.m_vertex0.y = m_prevVertex.y;
        edge.m_hasVertex0 = m_hasPrevVertex;
    }
    if (index < m_count - 2) {
        Vec2 v = m_vertices[index + 2];
        edge.m_vertex3.x = v.x;
        edge.m_vertex3.y = v.y;
        edge.m_hasVertex3 = true;
    } else {
        edge.m_vertex3.x = m_nextVertex.x;
        edge.m_vertex3.y = m_nextVertex.y;
        edge.m_hasVertex3 = m_hasNextVertex;
    }
}
Also used : Vec2(org.jbox2d.common.Vec2)

Example 29 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class CircleShape method computeAABB.

@Override
public final void computeAABB(final AABB aabb, final Transform transform, int childIndex) {
    final Rot tq = transform.q;
    final Vec2 tp = transform.p;
    final float px = tq.c * m_p.x - tq.s * m_p.y + tp.x;
    final float py = tq.s * m_p.x + tq.c * m_p.y + tp.y;
    aabb.lowerBound.x = px - m_radius;
    aabb.lowerBound.y = py - m_radius;
    aabb.upperBound.x = px + m_radius;
    aabb.upperBound.y = py + m_radius;
}
Also used : Rot(org.jbox2d.common.Rot) Vec2(org.jbox2d.common.Vec2)

Example 30 with Vec2

use of org.jbox2d.common.Vec2 in project libgdx by libgdx.

the class WheelJoint method getLocalAxisA.

public Vector2 getLocalAxisA() {
    Vec2 localAxis = joint.getLocalAxisA();
    localAxisA.set(localAxis.x, localAxis.y);
    return localAxisA;
}
Also used : Vec2(org.jbox2d.common.Vec2)

Aggregations

Vec2 (org.jbox2d.common.Vec2)185 Rot (org.jbox2d.common.Rot)36 Body (org.jbox2d.dynamics.Body)11 World (org.jbox2d.dynamics.World)9 AABB (org.jbox2d.collision.AABB)8 Mat22 (org.jbox2d.common.Mat22)7 Joint (org.jbox2d.dynamics.joints.Joint)7 PulleyJoint (org.jbox2d.dynamics.joints.PulleyJoint)7 ManifoldPoint (org.jbox2d.collision.ManifoldPoint)6 Test (org.junit.jupiter.api.Test)6 PolygonShape (org.jbox2d.collision.shapes.PolygonShape)5 Transform (org.jbox2d.common.Transform)5 Vec3 (org.jbox2d.common.Vec3)5 BodyDef (org.jbox2d.dynamics.BodyDef)5 VelocityConstraintPoint (org.jbox2d.dynamics.contacts.ContactVelocityConstraint.VelocityConstraintPoint)5 CircleShape (org.jbox2d.collision.shapes.CircleShape)4 Test (org.junit.Test)4 AffineTransform (java.awt.geom.AffineTransform)3 Shape (org.jbox2d.collision.shapes.Shape)3 Mat33 (org.jbox2d.common.Mat33)3