Search in sources :

Example 31 with Vec2

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 );
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) Body(spacegraph.space2d.phys.dynamics.Body)

Example 32 with Vec2

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));
                }
            }
        }
    };
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2) Color3f(spacegraph.space2d.phys.common.Color3f) Body(spacegraph.space2d.phys.dynamics.Body) JoglAbstractDraw(nars.rover.physics.gl.JoglAbstractDraw)

Example 33 with Vec2

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);
}
Also used : Vec2(spacegraph.space2d.phys.common.Vec2)

Example 34 with Vec2

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;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Vec2(spacegraph.space2d.phys.common.Vec2)

Example 35 with Vec2

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;
}
Also used : Tuple2f(spacegraph.util.math.Tuple2f) Vec2(spacegraph.space2d.phys.common.Vec2)

Aggregations

Vec2 (spacegraph.space2d.phys.common.Vec2)41 Body (spacegraph.space2d.phys.dynamics.Body)9 PolygonShape (spacegraph.space2d.phys.collision.shapes.PolygonShape)6 Tuple2f (spacegraph.util.math.Tuple2f)6 MouseJoint (spacegraph.space2d.phys.dynamics.joints.MouseJoint)4 JoglAbstractDraw (nars.rover.physics.gl.JoglAbstractDraw)3 ArrayRealVector (org.apache.commons.math3.linear.ArrayRealVector)3 Color3f (spacegraph.space2d.phys.common.Color3f)3 BodyDef (spacegraph.space2d.phys.dynamics.BodyDef)3 Fixture (spacegraph.space2d.phys.dynamics.Fixture)3 VisionRay (nars.rover.obj.VisionRay)2 Physics2dBody (ptrman.difficultyEnvironment.physics.Physics2dBody)2 CircleShape (spacegraph.space2d.phys.collision.shapes.CircleShape)2 DistanceJoint (spacegraph.space2d.phys.dynamics.joints.DistanceJoint)2 GLCapabilities (com.jogamp.opengl.GLCapabilities)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Material (nars.rover.Material)1 PhysicsModel (nars.rover.PhysicsModel)1 Sim (nars.rover.Sim)1