use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class WorldRayCastWrapper method drawJoint.
private void drawJoint(Joint joint) {
Body bodyA = joint.getBodyA();
Body bodyB = joint.getBodyB();
Transform xf1 = bodyA.getTransform();
Transform xf2 = bodyB.getTransform();
Vec2 x1 = xf1.p;
Vec2 x2 = xf2.p;
Vec2 p1 = pool.popVec2();
Vec2 p2 = pool.popVec2();
joint.getAnchorA(p1);
joint.getAnchorB(p2);
color.set(0.5f, 0.8f, 0.8f);
switch(joint.getType()) {
// TODO djm write after writing joints
case DISTANCE:
m_debugDraw.drawSegment(p1, p2, color);
break;
case PULLEY:
{
PulleyJoint pulley = (PulleyJoint) joint;
Vec2 s1 = pulley.getGroundAnchorA();
Vec2 s2 = pulley.getGroundAnchorB();
m_debugDraw.drawSegment(s1, p1, color);
m_debugDraw.drawSegment(s2, p2, color);
m_debugDraw.drawSegment(s1, s2, color);
}
break;
case CONSTANT_VOLUME:
case MOUSE:
// don't draw this
break;
default:
m_debugDraw.drawSegment(x1, p1, color);
m_debugDraw.drawSegment(p1, p2, color);
m_debugDraw.drawSegment(x2, p2, color);
}
pool.pushVec2(2);
}
use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class Body method setMassData.
/**
* Set the mass properties to override the mass properties of the fixtures. Note that this changes
* the center of mass position. Note that creating or destroying fixtures can also alter the mass.
* This function has no effect if the body isn't dynamic.
*
* @param massData the mass properties.
*/
public final void setMassData(MassData massData) {
// TODO_ERIN adjust linear velocity and torque to account for movement of center.
assert (m_world.isLocked() == false);
if (m_world.isLocked() == true) {
return;
}
if (m_type != BodyType.DYNAMIC) {
return;
}
m_invMass = 0.0f;
m_I = 0.0f;
m_invI = 0.0f;
m_mass = massData.mass;
if (m_mass <= 0.0f) {
m_mass = 1f;
}
m_invMass = 1.0f / m_mass;
if (massData.I > 0.0f && (m_flags & e_fixedRotationFlag) == 0) {
m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center);
assert (m_I > 0.0f);
m_invI = 1.0f / m_I;
}
final Vec2 oldCenter = m_world.getPool().popVec2();
// Move center of mass.
oldCenter.set(m_sweep.c);
m_sweep.localCenter.set(massData.center);
// m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
m_sweep.c.set(m_sweep.c0);
// Update center of mass velocity.
// m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
final Vec2 temp = m_world.getPool().popVec2();
temp.set(m_sweep.c).subLocal(oldCenter);
Vec2.crossToOut(m_angularVelocity, temp, temp);
m_linearVelocity.addLocal(temp);
m_world.getPool().pushVec2(2);
}
use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class Body method getLinearVelocityFromLocalPoint.
/**
* Get the world velocity of a local point.
*
* @param a point in local coordinates.
* @return the world velocity of a point.
*/
public final Vec2 getLinearVelocityFromLocalPoint(Vec2 localPoint) {
Vec2 out = new Vec2();
getLinearVelocityFromLocalPointToOut(localPoint, out);
return out;
}
use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class Body method getLocalPoint.
/**
* Gets a local point relative to the body's origin given a world point.
*
* @param a point in world coordinates.
* @return the corresponding local point relative to the body's origin.
*/
public final Vec2 getLocalPoint(Vec2 worldPoint) {
Vec2 out = new Vec2();
getLocalPointToOut(worldPoint, out);
return out;
}
use of org.jbox2d.common.Vec2 in project libgdx by libgdx.
the class Body method getWorldPoint.
/**
* Get the world coordinates of a point given the local coordinates.
*
* @param localPoint a point on the body measured relative the the body's origin.
* @return the same point expressed in world coordinates.
*/
public final Vec2 getWorldPoint(Vec2 localPoint) {
Vec2 v = new Vec2();
getWorldPointToOut(localPoint, v);
return v;
}
Aggregations