use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class Turret method fireBullet.
public void fireBullet() /*float ttl*/
{
// final float now = sim.getTime();
// Iterator<Body> ib = bullets.iterator();
// while (ib.hasNext()) {
// Body b = ib.next();
// ((BulletData)b.getUserData()).diesAt
//
// }
final float speed = 100f;
if (bullets.size() >= maxBullets) {
sim.remove(bullets.removeFirst());
}
Vec2 start = torso.getWorldPoint(new Vec2(6.5f, 0));
Body b = sim.create(start, Bodies.rectangle(0.4f, 0.6f), BodyType.DYNAMIC);
b.m_mass = 0.05f;
float angle = torso.getAngle();
Vec2 rayDir = new Vec2((float) Math.cos(angle), (float) Math.sin(angle));
rayDir.mulLocal(speed);
// float diesAt = now + ttl;
b.setUserData(new BulletData(b, 0));
bullets.add(b);
b.applyForce(rayDir, new Vec2(0, 0));
// float angle = (i / (float)numRays) * 360 * DEGTORAD;
// b2Vec2 rayDir( sinf(angle), cosf(angle) );
//
// b2BodyDef bd;
// bd.type = b2_dynamicBody;
// bd.fixedRotation = true; // rotation not necessary
// bd.bullet = true; // prevent tunneling at high speed
// bd.linearDamping = 10; // drag due to moving through air
// bd.gravityScale = 0; // ignore gravity
// bd.position = center; // start at blast center
// bd.linearVelocity = blastPower * rayDir;
// b2Body* body = m_world->CreateBody( &bd );
//
// b2CircleShape circleShape;
// circleShape.m_radius = 0.05; // very small
//
// b2FixtureDef fd;
// fd.shape = &circleShape;
// fd.density = 60 / (float)numRays; // very high - shared across all particles
// fd.friction = 0; // friction not necessary
// fd.restitution = 0.99f; // high restitution to reflect off obstacles
// fd.filter.groupIndex = -1; // particles should not collide with each other
// body->CreateFixture( &fd );
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class Turret method getMaterial.
@Override
public RoboticMaterial getMaterial() {
return new RoboticMaterial(this) {
@Override
public void before(Body b, JoglAbstractDraw d, float time) {
super.before(b, d, time);
if (!explosions.isEmpty()) {
Iterator<BulletData> ii = explosions.iterator();
while (ii.hasNext()) {
BulletData bd = ii.next();
if (bd.explosionTTL-- <= 0)
ii.remove();
d.drawSolidCircle(bd.getCenter(), bd.explosionTTL / 8 + rng.nextFloat() * 4, new Vec2(), new Color3f(1 - rng.nextFloat() / 3f, 0.8f - rng.nextFloat() / 3f, 0f));
}
}
}
};
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class Explosion method applyBlastImpulse.
public static void applyBlastImpulse(Body body, Vec2 blastCenter, Vec2 applyPoint, float blastPower) {
Vec2 blastDir = applyPoint.sub(blastCenter);
float distance = blastDir.normalize();
// ignore bodies exactly at the blast point - blast direction is undefined
if (distance == 0)
return;
float invDistance = 1 / distance;
float impulseMag = blastPower * invDistance * invDistance;
body.applyLinearImpulse(blastDir.mul(impulseMag), applyPoint);
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class DebugDraw method getWorldToScreen.
/**
* takes the world coordinate (argWorld) and returns the screen coordinates.
*
* @param argWorld
*/
public Tuple2f getWorldToScreen(Tuple2f argWorld) {
Tuple2f screen = new Vec2();
viewportTransform.getWorldToScreen(argWorld, screen);
return screen;
}
use of spacegraph.space2d.phys.common.Vec2 in project narchy by automenta.
the class DebugDraw method getScreenToWorld.
/**
* takes the screen coordinates (argScreen) and returns the world coordinates
*
* @param argScreen
*/
public Tuple2f getScreenToWorld(Tuple2f argScreen) {
Tuple2f world = new Vec2();
viewportTransform.getScreenToWorld(argScreen, world);
return world;
}
Aggregations