Package aspect.physics

Examples of aspect.physics.RigidBody


            0, 0, 50, 0
        };
       
        //addComponent(new VBOModel2D(LINES, vertices, colors(color, 2)));
        addBehavior(ellipse(color, 16, 16, 10));
        addBehavior(new RigidBody());
       
        cohesion = new Cohesion(this, Boids.BOID_COHESION, IntensityModel.INVERSE);
        alignment = new Alignment(this, Boids.BOID_ALIGNMENT, IntensityModel.INVERSE);
        separation = new Cohesion(this, -Boids.BOID_SEPARATION, IntensityModel.INVERSE_SQUARE);
       
        pos.x = getCanvasWidth() * (float)Math.random();
        pos.y = getCanvasHeight() * (float)Math.random();
       
        RigidBody rb = rigidBody();
       
        rb.vel = Vector2.fromAngle((float)Math.random() * 360, 200).asXY();
       
       
        addBehavior(new Behavior() {
            @Override
            public void update() {
                RigidBody rb = ent.rigidBody();
                if (ent.pos.x > getCanvasWidth() || ent.pos.x < 0) {
                    rb.vel.x *= -1;
                }
               
                if (ent.pos.y > getCanvasHeight() || ent.pos.y < 0) {
View Full Code Here


            angle += 90 * Time.deltaTime();
        }
        ship.ang.roll = -ship.rigidBody().velocity.xy().dir() - angle;

        if (thrusters) {
            RigidBody rb = ship.rigidBody();
            rb.impel(Vector2.fromAngle(-ship.ang.roll, 60e3f).asXY());
        }

        if (Vector3.distance(ship.pos, earth.pos) < 90 || Vector3.distance(ship.pos, moon.pos) < 70) {
            //onAdd();
        }
View Full Code Here

        super.update();
        for (Entity entity : World.main) {
            if (entity != this && entity instanceof Planet) {
                Planet planet = (Planet) entity;
                if (Vector3.distance(transform.position, planet.transform.position) < radius + planet.radius) {
                    RigidBody rb1 = rigidBody();
                    RigidBody rb2 = planet.rigidBody();
                   
                    Vector3 momentum = rb1.velocity.times(rb1.mass).plus(rb2.velocity.times(rb2.mass));
                   
                    float mass = rb1.mass + rb2.mass;
                   
View Full Code Here

        earth.render();
        moon.render();
        ship.render();

        if (hud) {
            RigidBody rb = ship.rigidBody();
            Vector2 v = Vector2.fromAngle(-ship.ang.roll, 50 / viewpoint.scale);
            Vector2 a1 = Vector2.fromAngle(-ship.ang.roll + 140, 10 / viewpoint.scale);
            Vector2 a2 = Vector2.fromAngle(-ship.ang.roll - 140, 10 / viewpoint.scale);
            glColor3f(1, 0, 0);
            glBegin(GL_LINES);
            glVertex2f(ship.pos.x, ship.pos.y);
            glVertex2f(ship.pos.x + v.x, ship.pos.y + v.y);
            glVertex2f(ship.pos.x + v.x, ship.pos.y + v.y);
            glVertex2f(ship.pos.x + v.x + a1.x, ship.pos.y + v.y + a1.y);
            glVertex2f(ship.pos.x + v.x, ship.pos.y + v.y);
            glVertex2f(ship.pos.x + v.x + a2.x, ship.pos.y + v.y + a2.y);
            glEnd();

            Vector3 forceVector = rb.netForce();
            glColor3f(0, 0, 1);
            glBegin(GL_LINES);
            glVertex2f(ship.pos.x, ship.pos.y);
            glVertex2f(ship.pos.x + forceVector.x, ship.pos.y + forceVector.y);
            glEnd();

            glColor3f(0, 1, 0);
            glBegin(GL_LINE_STRIP);

            Vector3 curVel = rb.velocity.copy();
            Vector3 curPos = ship.pos.copy();

            glVertex2f(curPos.x, curPos.y);
            float tick = 5f;
            boolean readyToStop = false;
            for (float t = 0; t < 8000; t += tick) {
                Entity e = new Entity();
                e.addBehavior(new RigidBody(curVel, Vector3.zero()));
                e.rigidBody().addForce(moonGravity);
                e.rigidBody().addForce(earthGravity);
                e.pos = curPos;
                Vector3 realAcc = rb.acceleration.plus(Vector3.divide(e.rigidBody().netForce(), e.rigidBody().mass));
                Vector3 velOld = curVel;
View Full Code Here

    public float mouseSensitivity = 0.01f;

    public PlayerShip() {
        Mouse.setGrabbed(true);
        addBehavior(new ShipControl());
        addBehavior(new RigidBody());
        centerMouse();
    }
View Full Code Here

                thrust = 4.0f;
            } else if (isKeyDown(KEY_S)) {
                thrust = -4.0f;
            }
           
            RigidBody rb = ent.rigidBody();
            rb.impel(transform.forward().times(thrust * Time.deltaTime()));

            if (rb.velocity.mag() > 2.0f) {
                rb.velocity = rb.velocity.normalize().times(2.0f);
            }
        }
View Full Code Here

            forces.add(b.cohesion);
            forces.add(b.separation);
        }

        for (Entity boid : boids) {
            RigidBody rb = boid.rigidBody();
            for (Force f : forces) {
                rb.addForce(f);
            }
        }
    }
View Full Code Here

        removeBehavior(flight);
       
        Motion motion = getBehavior(Motion.class);
        System.out.println(motion);
        removeBehavior(motion);
        RigidBody rigidBody = new RigidBody();
        addBehavior(rigidBody);
        rigidBody.velocity = motion.velocity;
       
        World.main.add(new Explosion(transform.position));
       
        rigidBody.impel(new Vector3(2.0f, 0, 0), new Vector3(0, 1.0f, 0));
    }
View Full Code Here

public class SpaceObject extends Entity {
    private final Force gravity;
    public SpaceObject(ViewModel model, float mass) {
        super(model);

        RigidBody rb = new RigidBody(World.main);
        rb.mass = mass;
        addBehavior(rb);
       
        gravity = new PointGravity(this);
        World.main.addForce(gravity);
View Full Code Here

    private int control = 0;

    public Frigate() {
        super(loadObjModel("frigate", new File("models/frigate_body.obj"), new Vector3(10.0f)));

        rigidBody = new RigidBody();
        rigidBody.mass = 10.0f;
        rigidBody.setUniformMOI(100);
        addBehavior(rigidBody);

        ViewModel engineRight = loadObjModel("rengine", new File("models/thruster_medium.obj"), new Vector3(10.0f));
View Full Code Here

TOP

Related Classes of aspect.physics.RigidBody

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.