use of spacegraph.space2d.phys.dynamics.joints.MouseJoint in project narchy by automenta.
the class TestQueryCallback method drawNext.
public synchronized void drawNext() {
if (!panel.render())
return;
if (mouseTracing && mouseJoint == null) {
float delay = 0.1f;
acceleration.x = 2 / delay * (1 / delay * (mouseWorld.x - mouseTracerPosition.x) - mouseTracerVelocity.x);
acceleration.y = 2 / delay * (1 / delay * (mouseWorld.y - mouseTracerPosition.y) - mouseTracerVelocity.y);
mouseTracerVelocity.x += timeStep * acceleration.x;
mouseTracerVelocity.y += timeStep * acceleration.y;
mouseTracerPosition.x += timeStep * mouseTracerVelocity.x;
mouseTracerPosition.y += timeStep * mouseTracerVelocity.y;
pshape.m_p.set(mouseTracerPosition);
pshape.m_radius = 2;
pshape.computeAABB(paabb, identity, 0);
}
if (mouseJoint != null) {
mouseJoint.getAnchorB(p1);
Vec2 p2 = mouseJoint.getTarget();
draw().drawSegment(p1, p2, mouseColor);
}
if (settings.getSetting(TestbedSettings.DrawContactPoints).enabled) {
final float k_impulseScale = 0.1f;
final float axisScale = 0.3f;
for (int i = 0; i < pointCount; i++) {
ContactPoint point = points[i];
if (point.state == PointState.ADD_STATE) {
draw().drawPoint(point.position, 10f, color1);
} else if (point.state == PointState.PERSIST_STATE) {
draw().drawPoint(point.position, 5f, color2);
}
if (settings.getSetting(TestbedSettings.DrawContactNormals).enabled) {
p1.set(point.position);
p2.set(point.normal).mulLocal(axisScale).addLocal(p1);
draw().drawSegment(p1, p2, color3);
} else if (settings.getSetting(TestbedSettings.DrawContactImpulses).enabled) {
p1.set(point.position);
p2.set(point.normal).mulLocal(k_impulseScale).mulLocal(point.normalImpulse).addLocal(p1);
draw().drawSegment(p1, p2, color5);
}
if (settings.getSetting(TestbedSettings.DrawFrictionImpulses).enabled) {
Vec2.crossToOutUnsafe(point.normal, 1, tangent);
p1.set(point.position);
p2.set(tangent).mulLocal(k_impulseScale).mulLocal(point.tangentImpulse).addLocal(p1);
draw().drawSegment(p1, p2, color5);
}
}
}
panel.paintScreen();
drawingQueued.set(false);
}
use of spacegraph.space2d.phys.dynamics.joints.MouseJoint in project narchy by automenta.
the class Box2DTests method drawJoint.
private void drawJoint(Joint joint) {
g.setColor(Color.GREEN);
Tuple2f v1 = new Vec2();
Tuple2f v2 = new Vec2();
switch(joint.getType()) {
case DISTANCE:
DistanceJoint dj = (DistanceJoint) joint;
v1 = joint.getBodyA().getWorldPoint(dj.getLocalAnchorA());
v2 = joint.getBodyB().getWorldPoint(dj.getLocalAnchorB());
break;
case MOUSE:
MouseJoint localMj = (MouseJoint) joint;
localMj.getAnchorA(v1);
localMj.getAnchorB(v2);
break;
}
Point p1 = getPoint(v1);
Point p2 = getPoint(v2);
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
use of spacegraph.space2d.phys.dynamics.joints.MouseJoint in project narchy by automenta.
the class DrawerRunnable method run.
@Override
public void run() {
// TODO< need to be set from outside >
float timeStep = 0.0f;
if (!panel.render()) {
return;
}
if (mouseTracing && mouseJoint == null) {
final float delay = 0.1f;
acceleration.x = 2 / delay * (1 / delay * (mouseWorld.x - mouseTracerPosition.x) - mouseTracerVelocity.x);
acceleration.y = 2 / delay * (1 / delay * (mouseWorld.y - mouseTracerPosition.y) - mouseTracerVelocity.y);
mouseTracerVelocity.x += timeStep * acceleration.x;
mouseTracerVelocity.y += timeStep * acceleration.y;
mouseTracerPosition.x += timeStep * mouseTracerVelocity.x;
mouseTracerPosition.y += timeStep * mouseTracerVelocity.y;
pshape.m_p.set(mouseTracerPosition);
pshape.m_radius = 2;
pshape.computeAABB(paabb, identity, 0);
}
if (mouseJoint != null) {
mouseJoint.getAnchorB(p1);
Vec2 p2 = mouseJoint.getTarget();
draw.drawSegment(p1, p2, mouseColor);
}
if (false) /*settings.getSetting(TestbedSettings.DrawContactPoints).enabled*/
{
final float k_impulseScale = 0.1f;
final float axisScale = 0.3f;
// TODO< need to be get from DrawingContactListener >
int pointCount = 0;
for (int i = 0; i < pointCount; i++) {
ContactPoint point = points[i];
if (point.state == Collision.PointState.ADD_STATE) {
draw.drawPoint(point.position, 10f, color1);
} else if (point.state == Collision.PointState.PERSIST_STATE) {
draw.drawPoint(point.position, 5f, color2);
}
if (settings.getSetting(TestbedSettings.DrawContactNormals).enabled) {
p1.set(point.position);
p2.set(point.normal).mulLocal(axisScale).addLocal(p1);
draw.drawSegment(p1, p2, color3);
} else if (settings.getSetting(TestbedSettings.DrawContactImpulses).enabled) {
p1.set(point.position);
p2.set(point.normal).mulLocal(k_impulseScale).mulLocal(point.normalImpulse).addLocal(p1);
draw.drawSegment(p1, p2, color5);
}
if (settings.getSetting(TestbedSettings.DrawFrictionImpulses).enabled) {
Vec2.crossToOutUnsafe(point.normal, 1, tangent);
p1.set(point.position);
p2.set(tangent).mulLocal(k_impulseScale).mulLocal(point.tangentImpulse).addLocal(p1);
draw.drawSegment(p1, p2, color5);
}
}
}
panel.paintScreen();
drawingQueued.set(false);
}
Aggregations