Package aspect.util

Examples of aspect.util.Vector3


        World.main.clear();
        Light.clear();

        //floor = new Entity(box(new Color(0.0f, 0.8f, 0.2f), 20f, 20f, 20f));
        Vector3[] fv = new Vector3[8];
        fv[0] = new Vector3(-10.0f, 0.0f, -10.0f);
        fv[1] = new Vector3(-10.0f, 0.0f, 10.0f);
        fv[2] = new Vector3(10.0f, 0.0f, 10.0f);
        fv[3] = new Vector3(10.0f, 0.0f, -10.0f);
        fv[4] = new Vector3(-5.0f, 5.0f, -5.0f);
        fv[5] = new Vector3(-5.0f, 5.0f, 5.0f);
        fv[6] = new Vector3(5.0f, 5.0f, 5.0f);
        fv[7] = new Vector3(5.0f, 5.0f, -5.0f);

        Vector3[] fn = new Vector3[5];
        fn[0] = Vector3.yAxis();
        fn[1] = new Vector3(1.0f, 1.0f, 0.0f).normalize();
        fn[2] = new Vector3(0.0f, 1.0f, 1.0f).normalize();
        fn[3] = new Vector3(0.0f, 1.0f, -1.0f).normalize();
        fn[4] = new Vector3(-1.0f, 1.0f, 0.0f).normalize();

        Vector3[] fe = new Vector3[6];
        fe[0] = Vector3.xAxis();
        fe[1] = Vector3.zAxis();
        fe[2] = new Vector3(1.0f, 1.0f, 1.0f).normalize();
        fe[3] = new Vector3(1.0f, 1.0f, -1.0f).normalize();
        fe[4] = new Vector3(-1.0f, 1.0f, -1.0f).normalize();
        fe[5] = new Vector3(-1.0f, 1.0f, 1.0f).normalize();

        ViewModel floorModel = loadObjModel(new File("models/platform.obj"), Vector3.one());
        Entity floor = new Entity(floorModel);

        floor.transform.position = new Vector3(0, -7, 0);

        //floor.transform.set(new Vector3(0, -12, 0), Vector3.yAxis().negate(), Vector3.zAxis(), Vector3.one());
        floor.addBehavior(new Collider(fv, fn, fe));

        World.main.add(floor);

        Light light = new Light(Color.WHITE);
        light.transform.position = new Vector3(-5, 5, 2);
        light.setAttenuation(1, 0, 0);

        //player = new Player(new Vector3(0, 0, 4));
        //World.main.add(player);
        camera = new Transform(new Vector3(-10, 10, 10), new Vector3(1, -1, -1), Vector3.yAxis(), Vector3.one());

        gravity = new UniformGravity();
        World.main.addForce(gravity);
       
        counter = new Canvas(128, 32);
        updateCounter();

        spawner = new Entity();
        spawner.transform.position.y = 15.0f;

        spawner.addBehavior(new Behavior() {
            private float timeUntilSpawn = 2.0f;

            @Override
            public void update() {
                timeUntilSpawn -= Time.deltaTime();

                if (timeUntilSpawn <= 0) {
                    float width = random.nextFloat() * 2.0f + 1.0f;
                    float height = random.nextFloat() * 2.0f + 1.0f;
                    float depth = random.nextFloat() * 2.0f + 1.0f;
                    final Entity entity = RigidBody.box(new Material(Color.random()), width, height, depth, 1.0f);

                    entity.addBehavior(new Behavior() {
                        @Override
                        public void update() {
                            if (entity.transform.position.y < -20.0f || isKeyDown(KEY_LCONTROL)) {
                                entity.destroy();
                                numBlocks--;
                                updateCounter();
                            }
                        }
                    });

                    entity.transform.position = spawner.transform.position;
                    entity.transform.forward = new Vector3(random.nextFloat(), random.nextFloat(), random.nextFloat());
                    entity.transform.setUp(new Vector3(random.nextFloat(), random.nextFloat(), random.nextFloat()));
                    //entity.transform.up.x = 0.1f;
                    World.main.add(entity);
                    numBlocks++;
                    updateCounter();
                    timeUntilSpawn = 2.0f;
View Full Code Here


    }
   
    @Override
    public void render() {
        ViewModel model = counter.getModel();
        model.transform.position = new Vector3(96, getCanvasHeight() - 32);
        setRenderMode(ORTHOGRAPHIC);
        model.render();
        setRenderMode(PERSPECTIVE);
    }
View Full Code Here

        }
    }

    private void stop() {
        if (gravity.acc.equals(Vector3.zero())) {
            gravity.acc = new Vector3(0, -9.8f, 0);
        } else {
            gravity.acc = Vector3.zero();
        }
    }
View Full Code Here

        @Override
        public void update() {
            if (thrust > 0) {
                Matrix4x4 m = ent.transform.global.getMdlMatrix();
                Vector3 point = m.transformPoint(new Vector3(1.0f, 0.0f, 3.0f));

                Vector3 vel = Frigate.this.rigidBody().velocity;

                vel = vel.plus(Vector3.cross(Frigate.this.rigidBody().angularVelocity, point.minus(ent.transform.global.position)));

                World.main.add(new Trail(point, vel.plus(ent.transform.global.forward().times(-20.0f)), Frigate.this));
            }
        }
View Full Code Here

    }
   
  
    @Override
    public void update() {
        Vector3 velOld = velocity;
        velocity = Vector3.add(velocity, acceleration.times(Time.deltaTime()));
       
        Vector3 avgVel = Vector3.divide(velOld.plus(velocity), 2.0f);
        ent.transform.position = ent.transform.position.plus(avgVel.times(Time.deltaTime()));
       
       
       
        Vector3 rVelOld = angularVelocity;
        angularVelocity = angularVelocity.plus(angularAcceleration.times(Time.deltaTime()));
   
        Vector3 avgRVel = Vector3.divide(rVelOld.plus(angularVelocity), 2.0f);
        Matrix4x4 m = Matrix4x4.identity().rotate(avgRVel, Time.deltaTime());
       
        ent.transform.up = m.transformVector(ent.transform.up);
        ent.transform.forward = m.transformVector(ent.transform.forward);
    }
View Full Code Here

    private Vector3 v2;
    private Entity entity;
   
    public LineCollider(Entity entity, float width) {
        this.entity = entity;
        this.v1 = new Vector3(-width / 2, 0, 0);
        this.v2 = new Vector3(width / 2, 0, 0);
    }
View Full Code Here

        Vector3[] edges = getEdges();
        Vector3[] cedges = c.getEdges();

        for (int i = 0; i < numEdges; i++) {
            for (int j = 0; j < c.numEdges; j++) {
                Vector3 cross = Vector3.cross(edges[i], cedges[j]);
                if (cross.mag2() != 0.0f) {
                    axes[pos++] = cross.normalize();
                } else {
                    axes[pos++] = null;
                }
            }
        }

        float dist = Float.POSITIVE_INFINITY;

        int i = 0;
        for (Vector3 n : axes) {

            if (n == null) {
                continue;
            }

            float min1 = Float.POSITIVE_INFINITY;
            Vector3 min1v = null;
            float max1 = Float.NEGATIVE_INFINITY;
            Vector3 max1v = null;
            float min2 = Float.POSITIVE_INFINITY;
            Vector3 min2v = null;
            float max2 = Float.NEGATIVE_INFINITY;
            Vector3 max2v = null;

            for (Vector3 v : verts) {
                float proj = Vector3.dot(v, n);
                if (proj < min1) {
                    min1 = proj;
                    min1v = v;
                }
                if (proj > max1) {
                    max1 = proj;
                    max1v = v;
                }
            }

            for (Vector3 v : cverts) {
                float proj = Vector3.dot(v, n);
                if (proj < min2) {
                    min2 = proj;
                    min2v = v;
                }
                if (proj > max2) {
                    max2 = proj;
                    max2v = v;
                }
            }

            if (min1 <= min2 && min2 <= max1 || min2 <= min1 && min1 <= max2) {
                if (max1 - min2 < dist) {
                    dist = max1 - min2;
                    displacement.set(n.times(-dist));

                    normal.set(n.negate());
                    if (i < numNormals) {
                        contact.set(min2v);
                    } else if (i < numNormals + c.numNormals) {
                        contact.set(max1v.plus(displacement));
                    } else {
                        int e = i - (numNormals + c.numNormals);
                       
                        Vector3 v1 = Vector3.cross(edges[e / c.numEdges], n);
                        Vector3 v2 = Vector3.cross(cedges[e % c.numEdges], n);
                       
                        float off1 = Vector3.dot(v1, max1v);
                        float off2 = Vector3.dot(v2, min2v);
                        float off3 = Vector3.dot(n, min2v);
                       
                        Vector3 v4 = new Vector3(off1, off2, off3);
                        Matrix3x3 m = new Matrix3x3(v1, v2, n);
                       
                        contact.set(m.invert().transform(v4));
                    }
                }

                if (max2 - min1 < dist) {
                    dist = max2 - min1;
                    displacement.set(n.times(dist));
                    normal.set(n);
                    if (i < numNormals) {
                        contact.set(max2v);
                    } else if (i < numNormals + c.numNormals) {
                        contact.set(min1v.plus(displacement));
                    } else {
                        int e = i - (numNormals + c.numNormals);
                       
                        Vector3 v1 = Vector3.cross(edges[e / c.numEdges], n);
                        Vector3 v2 = Vector3.cross(cedges[e % c.numEdges], n);
                       
                        float off1 = Vector3.dot(v1, min1v);
                        float off2 = Vector3.dot(v2, max2v);
                        float off3 = Vector3.dot(n, max2v);
                       
                        Vector3 v4 = new Vector3(off1, off2, off3);
                        Matrix3x3 m = new Matrix3x3(v1, v2, n);
                       
                        contact.set(m.invert().transform(v4));
                    }
                }
View Full Code Here

        Vector3[] edges = new Vector3[2];

        w /= 2;
        h /= 2;

        vertices[0] = new Vector3(w, h);
        vertices[1] = new Vector3(w, -h);
        vertices[2] = new Vector3(-w, -h);
        vertices[3] = new Vector3(-w, h);

        normals[0] = Vector3.zAxis();

        edges[0] = Vector3.yAxis();
        edges[1] = Vector3.xAxis();
View Full Code Here

        w /= 2;
        h /= 2;
        d /= 2;

        vertices[0] = new Vector3(w, h, d);
        vertices[1] = new Vector3(w, h, -d);
        vertices[2] = new Vector3(w, -h, -d);
        vertices[3] = new Vector3(w, -h, d);
        vertices[4] = new Vector3(-w, h, d);
        vertices[5] = new Vector3(-w, h, -d);
        vertices[6] = new Vector3(-w, -h, -d);
        vertices[7] = new Vector3(-w, -h, d);

        normals[0] = Vector3.xAxis();
        normals[1] = Vector3.yAxis();
        normals[2] = Vector3.zAxis();
View Full Code Here

        this.world = world;
        this.inertiaTensor = Matrix3x3.identity();
    }

    public float momentOfInertia(Vector3 axis) {
        Vector3 axisLocal = ent.transform.getCamMatrix().transformVector(axis);
        return Vector3.dot(axisLocal, inertiaTensor.transform(axisLocal));
    }
View Full Code Here

TOP

Related Classes of aspect.util.Vector3

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.