Package aspect.util

Examples of aspect.util.Vector3


    public void impel(Vector3 impulse) {
        velocity = velocity.plus(Vector3.divide(impulse, mass));
    }

    public void impel(Vector3 impulse, Vector3 point) {
        Vector3 angularImpulse = Vector3.cross(point, impulse);
       
        if (ent == null || angularImpulse.mag2() == 0.0f) {
            return;
        }
       
        impel(impulse);
        impelAngular(angularImpulse);
View Full Code Here


    public void addForce(Force force) {
        forces.add(force);
    }

    public Vector3 netForce() {
        Vector3 sigmaForce = Vector3.zero();
        for (Force force : forces) {
            sigmaForce = sigmaForce.plus(force.getForce(ent));
        }

        if (world != null) {
            for (Force force : world.forces()) {
                sigmaForce = sigmaForce.plus(force.getForce(ent));
            }
        }

        return sigmaForce;
    }
View Full Code Here

        if (collider == null || c == null) {
            return;
        }

        Vector3 contact = new Vector3(0.0f);
        Vector3 displacement = new Vector3(0.0f);
        Vector3 normal = new Vector3(0.0f);

        boolean b = collider.colliding(c, contact, displacement, normal);

        if (b) {
            //ent.transform.position = ent.transform.position.plus(displacement);

            boolean both = true;

            RigidBody rb2 = c.ent.rigidBody();

            float moiA, moiB;

            if (rb2 == null) {
                rb2 = new RigidBody();
                rb2.mass = Float.POSITIVE_INFINITY;
                both = false;
            }

            Vector3 pos1 = contact.minus(ent.transform.position);
            Vector3 pos2 = contact.minus(c.ent.transform.position);
            Vector3 va = velocity.plus(Vector3.cross(angularVelocity, pos1));
            Vector3 vb = rb2.velocity.plus(Vector3.cross(rb2.angularVelocity, pos2));

            if (rb2.ent == null) {
                ent.transform.position = ent.transform.position.plus(displacement);
            } else {
                Vector3 vt = va.plus(vb);
                float magt = vt.mag();
                if (magt == 0.0f) {
                    ent.transform.position = ent.transform.position.plus(displacement);
                } else {
                    float f1 = va.mag() / magt;
                    float f2 = 1.0f - f1;

                    ent.transform.position = ent.transform.position.plus(displacement.times(f1));
                    rb2.ent.transform.position = rb2.ent.transform.position.minus(displacement.times(f2));
                }
            }

            Vector3 vr = va.minus(vb);

            // Normal impulse
            float num = -Vector3.dot(vr.times(1 + coefficientOfRestitution), normal);
            float f = 1.0f / mass + 1.0f / rb2.mass;
            Vector3 n2 = normal.times(f);
            float denom1 = Vector3.dot(normal, n2);
            moiA = momentOfInertia(Vector3.cross(normal, pos1).normalize());
            if (both) {
                moiB = rb2.momentOfInertia(Vector3.cross(normal, pos2).normalize());
            } else {
                moiB = Float.POSITIVE_INFINITY;
            }
            Vector3 cross1 = Vector3.cross(Vector3.divide(Vector3.cross(pos1, normal), moiA), pos1);
            Vector3 cross2 = Vector3.cross(Vector3.divide(Vector3.cross(pos2, normal), moiB), pos2);
            Vector3 cross = cross1.plus(cross2);
            float denom2 = Vector3.dot(normal, cross);
            float denom = denom1 + denom2;
            float impulse = num / denom;
            Vector3 impulseN = normal.times(impulse);
            impel(impulseN, pos1);
            rb2.impel(impulseN.negate(), pos2);

            // Frictional impulse
            Vector3 tangent = Vector3.cross(Vector3.cross(vr, normal), normal).normalize();
            if (tangent.mag2() == 0.0f) {
                return;
            }

            num = -Vector3.dot(vr.times(coefficientOfFriction), tangent);
            Vector3 t2 = tangent.times(f);
            denom1 = Vector3.dot(tangent, t2);
            moiA = momentOfInertia(Vector3.cross(tangent, pos1).normalize());
            if (both) {
                moiB = rb2.momentOfInertia(Vector3.cross(tangent, pos2).normalize());
            } else {
                moiB = Float.POSITIVE_INFINITY;
            }
            cross1 = Vector3.cross(Vector3.divide(Vector3.cross(pos1, tangent), moiA), pos1);
            cross2 = Vector3.cross(Vector3.divide(Vector3.cross(pos2, tangent), moiB), pos2);
            cross = cross1.plus(cross2);
            denom2 = Vector3.dot(tangent, cross);
            denom = denom1 + denom2;
            float friction = num / denom;
            Vector3 frictionT = tangent.times(friction);
            impel(frictionT, pos1);
            rb2.impel(frictionT.negate(), pos2);

            //Vector3 friction = Vector3.cross(Vector3.cross(impulse, normal), normal).times(coefficientOfFriction);
            //impel(friction, pos1);
        }
    }
View Full Code Here

        float h2 = height * height;
        float d2 = depth * depth;

        float f = entity.rigidBody().mass / 12.0f;

        entity.rigidBody().setMomentsOfInertia(new Vector3(f * (h2 + d2), f * (w2 + d2), f * (w2 + h2)));

        return entity;
    }
View Full Code Here

    public UniformGravity(Vector3 acc) {
        this.acc = acc;
    }
   
    public UniformGravity() {
        this.acc = new Vector3(0, -9.8f, 0);
    }
View Full Code Here

            } else {
                speedRight = 0;
            }
        }

        Vector3 forward = ent.transform.forward.xz().normalize().times(Time.deltaTime() * speedForward).asXZ();
        Vector3 sideways = ent.transform.right().xz().normalize().times(Time.deltaTime() * speedRight).asXZ();

        ent.transform.position = ent.transform.position.plus(sideways);
        ent.transform.position = ent.transform.position.plus(forward);
    }
View Full Code Here

            switch (parts[0]) {
                case "v": {
                    float x = Float.parseFloat(parts[1]);
                    float y = Float.parseFloat(parts[2]);
                    float z = Float.parseFloat(parts[3]);
                    allVertices.add(new Vector3(x, y, z).times(scale));
                    break;
                }

                case "f": {
                    for (int i = 0; i < 3; i++) {
                        String[] info = parts[i + 1].split("/");
                        int vertex = Integer.parseInt(info[0]);
                        if (vertex < 0) {
                            vertex = allVertices.size() + vertex;
                        } else {
                            vertex--;
                        }

                        Vector3 v = allVertices.get(vertex);
                        triangleVerts.add(v.x);
                        triangleVerts.add(v.y);
                        triangleVerts.add(v.z);
                    }
                    break;
                }

                case "l": {
                    for (int i = 0; i < 2; i++) {
                        int vertex = Integer.parseInt(parts[i + 1]);

                        if (vertex < 0) {
                            vertex = allVertices.size() + vertex;
                        } else {
                            vertex--;
                        }

                        Vector3 v = allVertices.get(vertex);
                        lineVerts.add(v.x);
                        lineVerts.add(v.y);
                        lineVerts.add(v.z);
                    }
                    break;
View Full Code Here

                }
                case "v": {
                    float x = Float.parseFloat(parts[1]);
                    float y = Float.parseFloat(parts[2]);
                    float z = Float.parseFloat(parts[3]);
                    allVertices.add(new Vector3(x, y, z).component(scale));
                    break;
                }
                case "vt": {
                    float x = Float.parseFloat(parts[1]);
                    float y = Float.parseFloat(parts[2]);
                    allTexCoords.add(new Vector2(x, y));
                    break;
                }
                case "vn": {
                    float x = Float.parseFloat(parts[1]);
                    float y = Float.parseFloat(parts[2]);
                    float z = Float.parseFloat(parts[3]);
                    allNormals.add(new Vector3(x / scale.x, y / scale.y, z / scale.z).normalize());
                    break;
                }
                case "f": {
                    LinkedList<Vertex> thisMtl = triangles.get(currentMaterial);
View Full Code Here

            float z1 = Trig.sin(angle) * radius;
           
            float x2 = Trig.cos(angle + angleStep) * radius;
            float z2 = Trig.sin(angle + angleStep) * radius;
           
            Vector3 vert1 = new Vector3(x1, -length, z1);
            Vector3 vert2 = new Vector3(x1, length, z1);
            Vector3 vert3 = new Vector3(x2, length, z2);
            Vector3 vert4 = new Vector3(x2, -length, z2);
           
            index += copyVector3(vert1, dest, index, 1);
            index += copyVector3(vert2, dest, index, 1);
            index += copyVector3(vert3, dest, index, 1);
            index += copyVector3(vert4, dest, index, 1);
View Full Code Here

        int index = start;
        for (int i = 0; i < lod; i++) {
            float lon = i * step;
            for (int j = 0; j < vlod; j++) {
                float lat = j * step - 90.0f;
                Vector3 vert1 = Vector3.fromAngles(new Angles(lat, lon, 0.0f), radius);
                Vector3 vert2 = Vector3.fromAngles(new Angles(lat, lon + step, 0.0f), radius);
                Vector3 vert3 = Vector3.fromAngles(new Angles(lat + step, lon + step, 0.0f), radius);
                Vector3 vert4 = Vector3.fromAngles(new Angles(lat + step, lon, 0.0f), radius);
               
                index += copyVector3(vert1, dest, index, 1);
                index += copyVector3(vert2, dest, index, 1);
                index += copyVector3(vert3, dest, index, 1);
                index += copyVector3(vert4, dest, index, 1);
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.