Example usage for com.badlogic.gdx.math Vector3 Vector3

List of usage examples for com.badlogic.gdx.math Vector3 Vector3

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector3 Vector3.

Prototype

public Vector3(final float[] values) 

Source Link

Document

Creates a vector from the given array.

Usage

From source file:br.cefetmg.games.movement.behavior.Chegar.java

public Direcionamento guiar(Pose agente) {
    Direcionamento output = new Direcionamento();
    Vector3 objetivo = new Vector3(this.alvo.getObjetivo());
    Vector3 velocidade = objetivo.sub(agente.posicao);
    if (velocidade.len2() > 3000) {
        output.velocidade = velocidade.clamp(maxVelocidade, maxVelocidade);
    } else {/*from   ww  w.j  a  va  2s . c  o m*/
        output.velocidade = velocidade.clamp(0, maxVelocidade / 2);
    }
    return output;
}

From source file:com.davidykay.shootout.Renderer.java

License:Apache License

public void unproject(Vector3 touchLocation) {
    Vector3 newLocation = new Vector3(touchLocation);
    camera.unproject(touchLocation);//from  w ww. j  a va 2  s. co m
    //Gdx.app.log(TAG, String.format("unproject from: (%s) to: (%s)",
    //                               newLocation.toString(),
    //                               touchLocation.toString()
    //                               ));
}

From source file:com.digitale.sim.Missile.java

License:Open Source License

public void update(float delta) {
    shotLife++;//from   w  ww  .  j  a v a2  s  .  com

    destination = new Vector3(target.position);
    Vector3 direction = new Vector3(destination.sub(position));
    double length = direction.len();
    double npcPitch = Math.toDegrees(Math.asin((double) (direction.y / length)));
    double npcYaw;
    if (Math.abs(direction.z) < 0.00001) {
        // special case
        if (direction.x > 0) {
            npcYaw = Math.PI / 2.0;
        } else if (direction.x < 0) {
            npcYaw = -Math.PI / 2.0;
        } else {
            npcYaw = 0.0;
        }
    } else {
        npcYaw = Math.atan2(direction.x, direction.z);
    }

    yawAngle = (float) Math.toDegrees(npcYaw);
    pitchAngle = -(float) npcPitch;
    position.set(position.add(direction.nor().mul(20f)));

    if (shotTime + lifeTime < System.currentTimeMillis())
        hasLeftField = true;
}

From source file:com.digitale.sim.Simulation.java

License:Open Source License

public static void updateReticules() {
    Vector3 tmp;//from   ww  w  .j  a  v  a 2 s. co  m
    // for every actor
    for (int i = 0; i < Stardust3d.actorsList.size(); i++) {
        // is it renderable?
        Actor actor = Stardust3d.actorsList.get(i);
        if (actor != null && !(actor.shipname.equals("dead")) && actor.getHitpoints() > 0) {
            // only do if actor is in space
            tmp = new Vector3((actor.position));

            Renderer.camera.project(tmp);

            tmp.x = (tmp.x / GameLoop.screenScaleX) - 16;
            tmp.y = (tmp.y / GameLoop.screenScaleY) - 16;
            actor.reticulepos = tmp;
            if (Stardust3d.DEEPDEBUG)
                System.out.println("reticule " + tmp.x + ":" + tmp.y + ":" + tmp.z);
            actor.distance = actor.position.dst(Ship.position);
            actor.distanceString = Integer.toString(Math.round(actor.distance / 10));
            actor.distanceString = actor.distanceString + "km";
        }
    }
}

From source file:com.mbrlabs.mundus.commons.scene3d.SimpleNode.java

License:Apache License

/**
 * Copy construction// w ww.  j a  v a 2s  . c om
 * 
 * @param simpleNode
 * @param id
 */
public SimpleNode(SimpleNode simpleNode, int id) {
    super(id);
    this.localPosition = new Vector3(simpleNode.localPosition);
    this.localRotation = new Quaternion(simpleNode.localRotation);
    this.localScale = new Vector3(simpleNode.localScale);
    this.combined = new Matrix4(simpleNode.combined);
}

From source file:com.mygdx.game.objects.Ragdoll.java

License:Apache License

/**
 * @param empties    Blender empties containing rigid body dimension data
 * @param armatureNodeId The name of the root skeleton/armature node
 *//* ww  w .java2  s . c o  m*/
private void createRagdoll(Array<BlenderEmpty> empties, String armatureNodeId) {
    Node armature = modelInstance.getNode(armatureNodeId, true, true);

    // Load mass and shape half extent data from Blender json
    ArrayMap<String, Vector3> halfExtMap = new ArrayMap<String, Vector3>();
    ArrayMap<String, Float> massMap = new ArrayMap<String, Float>();

    for (BlenderEmpty empty : empties) {
        Vector3 halfExtents = new Vector3(empty.scale);
        halfExtents.x = Math.abs(halfExtents.x);
        halfExtents.y = Math.abs(halfExtents.y);
        halfExtents.z = Math.abs(halfExtents.z);
        halfExtMap.put(empty.name, halfExtents);

        float partMass = Float.parseFloat(empty.custom_properties.get("mass"));
        massMap.put(empty.name, super.mass * partMass);
    }

    ArrayMap<String, btCollisionShape> shapeMap = new ArrayMap<String, btCollisionShape>();
    ArrayMap<String, btRigidBody> bodyMap = new ArrayMap<String, btRigidBody>();

    // Create rigid bodies using the previously loaded mass and half extents.
    // Put them along with the shapes into maps.
    for (Iterator<ObjectMap.Entry<String, Vector3>> iterator = halfExtMap.iterator(); iterator.hasNext();) {
        ObjectMap.Entry<String, Vector3> entry = iterator.next();
        String partName = entry.key;
        Vector3 partHalfExt = entry.value;
        float partMass = massMap.get(partName);

        btCollisionShape partShape = new btBoxShape(partHalfExt);
        shapeMap.put(partName, partShape);

        InvisibleBody phyCmp = new InvisibleBody(partName, partShape, partMass, new Matrix4(),
                this.belongsToFlag, this.collidesWithFlag, false, true);
        phyCmp.constructionInfo.dispose();

        bodyMap.put(partName, phyCmp.body);
        this.addPart(phyCmp.body, armature.getChild(partName, true, true));
    }
    // Abdomen is the at the top of the armature hierarchy
    this.addPart(bodyMap.get("abdomen"), armature, new Vector3(0, halfExtMap.get("abdomen").y * 1.6f, 0));

    final Matrix4 localA = new Matrix4();
    final Matrix4 localB = new Matrix4();
    btHingeConstraint hingeC;
    btConeTwistConstraint coneC;
    btFixedConstraint fixedC;
    String a, b;

    // TODO: This part could probably be automated somehow...

    // Set the ragdollConstraints
    a = "abdomen";
    b = "chest";
    localA.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, PI0_25, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(-PI0_25, PI0_5);

    a = "chest";
    b = "neck";
    localA.setFromEulerAnglesRad(0, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(fixedC = new btFixedConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));

    a = "neck";
    b = "head";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);

    a = "abdomen";
    b = "left_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).scl(-1, 1, 1).trn(halfExtMap.get(a).x * 0.5f,
            -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).scl(-1, 1, 1).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "abdomen";
    b = "right_thigh";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x * 0.5f, -halfExtMap.get("abdomen").y, 0);
    localB.setFromEulerAnglesRad(0, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_25, PI0_25, PI0_25);
    coneC.setDamping(10);

    a = "left_thigh";
    b = "left_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    a = "right_thigh";
    b = "right_shin";
    localA.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(-PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_25 * 3);

    // TODO: causes shoulder rotation
    a = "chest";
    b = "left_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(halfExtMap.get(a).x + halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(PI0_25, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    // TODO: as above
    a = "chest";
    b = "right_upper_arm";
    localA.setFromEulerAnglesRad(0, PI, 0).trn(-halfExtMap.get(a).x - halfExtMap.get(b).x, halfExtMap.get(a).y,
            0);
    localB.setFromEulerAnglesRad(-PI0_25, 0, 0).trn(0, -halfExtMap.get("right_upper_arm").y, 0);
    this.constraints.add(coneC = new btConeTwistConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    coneC.setLimit(PI0_5, PI0_5, 0);
    coneC.setDamping(10);

    a = "left_upper_arm";
    b = "left_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

    a = "right_upper_arm";
    b = "right_forearm";
    localA.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, halfExtMap.get(a).y, 0);
    localB.setFromEulerAnglesRad(PI0_5, 0, 0).trn(0, -halfExtMap.get(b).y, 0);
    this.constraints.add(hingeC = new btHingeConstraint(bodyMap.get(a), bodyMap.get(b), localA, localB));
    hingeC.setLimit(0, PI0_5);

}

From source file:com.mygdx.game.pathfinding.NavMesh.java

License:Apache License

/**
 * Calculate a triangle graph path between two triangles.
 *
 * @param fromTri//from  w  w w. j a v  a2  s  .c  om
 * @param fromPoint
 * @param toTri
 * @param toPoint
 * @param path
 * @return
 */
public boolean getPath(Triangle fromTri, Vector3 fromPoint, Triangle toTri, Vector3 toPoint,
        NavMeshGraphPath path) {
    path.clear();
    if (pathFinder.searchConnectionPath(fromTri, toTri, heuristic, path)) {
        path.start = new Vector3(fromPoint);
        path.end = new Vector3(toPoint);
        path.startTri = fromTri;
        return true;
    }
    Gdx.app.debug(TAG, "Path not found.");
    return false;
}

From source file:com.mygdx.game.pathfinding.NavMeshPointPath.java

License:Apache License

/**
 * Calculate the shortest path through the navigation mesh triangles.
 *
 * @param trianglePath// w w  w .  j ava 2  s  .  c  o  m
 */
public void calculateForGraphPath(NavMeshGraphPath trianglePath) {
    clear();
    nodes = trianglePath.nodes;
    this.start = new Vector3(trianglePath.start);
    this.end = new Vector3(trianglePath.end);
    this.startTri = trianglePath.startTri;

    // Check that the start point is actually inside the start triangle, if not, project it to the closest
    // triangle edge. Otherwise the funnel calculation might generate spurious path segments.
    Ray ray = new Ray(tmp1.set(V3_UP).scl(1000).add(start), tmp2.set(V3_DOWN));
    if (!Intersector.intersectRayTriangle(ray, startTri.a, startTri.b, startTri.c, null)) {
        float minDst = Float.POSITIVE_INFINITY;
        Vector3 projection = new Vector3();
        Vector3 newStart = new Vector3();
        float dst;
        // A-B
        if ((dst = GeometryUtils.nearestSegmentPointSquareDistance(projection, startTri.a, startTri.b,
                start)) < minDst) {
            minDst = dst;
            newStart.set(projection);
        }
        // B-C
        if ((dst = GeometryUtils.nearestSegmentPointSquareDistance(projection, startTri.b, startTri.c,
                start)) < minDst) {
            minDst = dst;
            newStart.set(projection);
        }
        // C-A
        if ((dst = GeometryUtils.nearestSegmentPointSquareDistance(projection, startTri.c, startTri.a,
                start)) < minDst) {
            minDst = dst;
            newStart.set(projection);
        }
        start.set(newStart);
    }
    if (nodes.size == 0) {
        addPoint(start, startTri);
        addPoint(end, startTri);
    } else {
        lastEdge = new Edge(nodes.get(nodes.size - 1).getToNode(), nodes.get(nodes.size - 1).getToNode(), end,
                end);
        calculateEdgePoints();
    }
}

From source file:com.mygdx.game.pathfinding.NavMeshPointPath.java

License:Apache License

/**
 * Store all edge crossing points between the start and end indices.
 * If the path crosses exactly the start or end points (which is quite likely),
 * store the edges in order of crossing in the EdgePoint data structure.
 * <p/>//from w w w.ja  v  a  2s.  c om
 * Edge crossings are calculated as intersections with the plane from the
 * start, end and up vectors.
 *
 * @param startIndex
 * @param endIndex
 * @param startPoint
 * @param endPoint
 */
private void calculateEdgeCrossings(int startIndex, int endIndex, Vector3 startPoint, Vector3 endPoint) {

    if (startIndex >= numEdges() || endIndex >= numEdges()) {
        return;
    }
    crossingPlane.set(startPoint, tmp1.set(startPoint).add(V3_UP), endPoint);

    EdgePoint previousLast = lastPointAdded;

    Edge edge = getEdge(endIndex);
    EdgePoint end = new EdgePoint(new Vector3(endPoint), edge.toNode);

    for (int i = startIndex; i < endIndex; i++) {
        edge = getEdge(i);

        if (edge.rightVertex.equals(startPoint) || edge.leftVertex.equals(startPoint)) {
            previousLast.toNode = edge.toNode;
            if (!previousLast.connectingEdges.contains(edge, true)) {
                previousLast.connectingEdges.add(edge);
            }

        } else if (edge.leftVertex.equals(endPoint) || edge.rightVertex.equals(endPoint)) {
            if (!end.connectingEdges.contains(edge, true)) {
                end.connectingEdges.add(edge);
            }

        } else if (Intersector.intersectSegmentPlane(edge.leftVertex, edge.rightVertex, crossingPlane, tmp1)
                && !Float.isNaN(tmp1.x + tmp1.y + tmp1.z)) {
            if (i != startIndex || i == 0) {
                lastPointAdded.toNode = edge.fromNode;
                EdgePoint crossing = new EdgePoint(new Vector3(tmp1), edge.toNode);
                crossing.connectingEdges.add(edge);
                addPoint(crossing);
            }
        }
    }
    if (endIndex < numEdges() - 1) {
        end.connectingEdges.add(getEdge(endIndex));
    }
    if (!lastPointAdded.equals(end)) {
        addPoint(end);
    }
}

From source file:com.mygdx.game.pathfinding.Triangle.java

License:Apache License

public Triangle(Vector3 a, Vector3 b, Vector3 c, int triIndex, int meshPartIndex) {
    this.a = a;//from   ww w  . j  av  a  2  s .  c  o  m
    this.b = b;
    this.c = c;
    this.triIndex = triIndex;
    this.meshPartIndex = meshPartIndex;
    this.centroid = new Vector3(a).add(b).add(c).scl(1f / 3f);
    this.connections = new Array<Connection<Triangle>>();
}