use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class Jetpack method updateSettings.
private void updateSettings() {
EmitterSettings settings = jetpackEmitter.settings;
// set offset
settings.offset = new Vec2(rng.nextFloat() * settings.xLocationVariance * -0.2f, rng.nextFloat() * settings.yLocationVariance * 0.02f);
// set particle lifetime
if (rng.nextFloat() > 0.9f) {
float low = 0.8f, high = 1.0f;
float liveLong = rng.nextFloat();
if (liveLong < low)
settings.particleLifetime = low * 2.0f;
else if (liveLong > high)
settings.particleLifetime = high * 2.0f;
else
settings.particleLifetime = liveLong * 2.0f;
} else {
settings.particleLifetime = rng.nextFloat() * 0.75f;
}
// set particle force
settings.particleForce = new Vec2(rng.nextBoolean() ? rng.nextFloat() * -5.0f : rng.nextFloat() * -5.0f, rng.nextFloat() * -50.0f);
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class Jetpack method applyForce.
/**
* Activates the player's jetpack
* @param timeStep Amount of time passed, in seconds
*/
private void applyForce(float timeStep) {
Vec2 linVec = player.body.getLinearVelocity();
if (linVec.y <= maxVelocityY) {
if (isHovering)
linVec.y += timeStep * hoverForce;
else
linVec.y += timeStep * upwardForce;
player.body.setLinearVelocity(linVec);
jetpackEmitter.activate();
}
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class ParticleEmitter method update.
@Override
public void update(float timeStep) {
super.update(timeStep);
// follow the entity that the emitter is attached to
this.setLocation(new Vec2(settings.offset.x + settings.attached.getLocation().x, settings.offset.y + settings.attached.getLocation().y));
if (this.active) {
timeSinceLastEmission += timeStep;
// only emit particles if we're past the emission rate
if (timeSinceLastEmission >= settings.particleEmissionRate && numParticlesOut < settings.maxParticles) {
settings.onCreateParticle();
// release number of specified particles
for (int i = 0; i < settings.particlesPerEmission; i++) {
this.create(new Particle((float) Math.random() * settings.particleLifetime, this, settings.particleRenderer, this.getLayer(), getParticleBodyDef(), settings.particleWidth, settings.particleHeight, getParticleFixtureDef()), false);
numParticlesOut++;
if (numParticlesOut >= settings.maxParticles)
break;
}
// reset counter
timeSinceLastEmission = 0.0f;
}
}
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class ReactorWorld method fireDebris.
/**
* fuel rod components mixed with plutonium ash mutated into a supernatural buckyball atomic compound
*/
protected void fireDebris(float w, float h) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 4.0f);
PolygonShape box = new PolygonShape();
box.setAsBox(w, h);
Body m_body = p.getWorld().createBody(bd);
m_body.createFixture(box, 1.0f);
box.setAsBox(0.25f, 0.25f);
// m_x = RandomFloat(-1.0f, 1.0f);
float m_x = -0.06530577f;
bd.position.set(m_x, 10.0f);
bd.bullet = true;
Body m_bullet = p.getWorld().createBody(bd);
m_bullet.createFixture(box, 100.0f);
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f);
m_body.setLinearVelocity(new Vec2());
m_body.setAngularVelocity(0.0f);
m_x = MathUtils.randomFloat(-1.0f, 1.0f);
m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
m_bullet.setAngularVelocity(0.0f);
}
use of spacegraph.space2d.phys.common.Vec2 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);
}
Aggregations