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);
}
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;
}
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;
}
}
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;
}
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;
}
Aggregations