List of usage examples for com.badlogic.gdx.math Vector3 sub
public Vector3 sub(float value)
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 {// w w w. j a va 2s.c o m output.velocidade = velocidade.clamp(0, maxVelocidade / 2); } return output; }
From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.GameObject.java
License:Apache License
public void lookAt(Vector3 point) { Vector3 from = transform.getTranslation(new Vector3()).cpy(); Vector3 to = point.cpy(); Vector3 direction = to.sub(from).nor(); direction.set(-direction.x, -direction.y, -direction.z); Quaternion quaternion = new Quaternion(); Matrix4 instanceRotation = transform.cpy().mul(transform); instanceRotation.setToLookAt(direction, new Vector3(0, -1, 0)); instanceRotation.rotate(0, 0, 1, 180); instanceRotation.getRotation(quaternion); transform.set(from, quaternion);// www .j a va 2s .c o m }
From source file:com.digitale.sim.Simulation.java
License:Open Source License
private static float MoveBackToCollisionPoint(float frameDuration, Ship object1, Actor object2, float distanceAtFrameEnd, float collisionDistance) { // Calculate the position of each object at the start of the frame. float object1PosAtFrameStart_X = (float) (object1.position.x - object1.heading.x * frameDuration); float object1PosAtFrameStart_Y = (float) (object1.position.y - object1.heading.y * frameDuration); float object1PosAtFrameStart_Z = (float) (object1.position.z - object1.heading.z * frameDuration); Vector3 object1PosAtFrameStart = new Vector3(object1PosAtFrameStart_X, object1PosAtFrameStart_Y, object1PosAtFrameStart_Z);//ww w . ja v a2 s . c o m float object2PosAtFrameStart_X = (float) (object2.position.x - object2.heading.x * frameDuration); float object2PosAtFrameStart_Y = (float) (object2.position.y - object2.heading.y * frameDuration); float object2PosAtFrameStart_Z = (float) (object2.position.z - object2.heading.z * frameDuration); Vector3 object2PosAtFrameStart = new Vector3(object2PosAtFrameStart_X, object2PosAtFrameStart_Y, object2PosAtFrameStart_Z); // Calculate the distance between the objects at the start of the frame. Vector3 differenceAtFrameStart = object2PosAtFrameStart.sub(object1PosAtFrameStart); float distanceAtFrameStart = differenceAtFrameStart.len(); // Calculate the total change in distance during the frame, and the required change to reach the collision. float distanceTotalDelta = distanceAtFrameEnd - distanceAtFrameStart; float distanceDeltaToCollision = collisionDistance - distanceAtFrameStart; // Calculate the percentage change to the collision and after the collision. float percentageDeltaToCollision = distanceDeltaToCollision / distanceTotalDelta; float percentageDeltaAfterCollision = 1 - percentageDeltaToCollision; // Calculte the time before and after the collision in the frame. double millisecondsToCollision = frameDuration * percentageDeltaToCollision; float millisecondsAfterCollision = (float) (frameDuration * percentageDeltaAfterCollision); // Calculate and move the objects to their positions at the point of collision. float object1PosAtCollision_X = (float) (object1PosAtFrameStart_X + object1.heading.x * millisecondsToCollision); float object1PosAtCollision_Y = (float) (object1PosAtFrameStart_Y + object1.heading.y * millisecondsToCollision); float object1PosAtCollision_Z = (float) (object1PosAtFrameStart_Z + object1.heading.z * millisecondsToCollision); Vector3 object1PosAtCollision = new Vector3(object1PosAtCollision_X, object1PosAtCollision_Y, object1PosAtCollision_Z); object1.position = (object1PosAtCollision); float object2PosAtCollision_X = (float) (object2PosAtFrameStart_X + object2.heading.x * millisecondsToCollision); float object2PosAtCollision_Y = (float) (object2PosAtFrameStart_Y + object2.heading.y * millisecondsToCollision); float object2PosAtCollision_Z = (float) (object2PosAtFrameStart_Y + object2.heading.z * millisecondsToCollision); Vector3 object2PosAtCollision = new Vector3(object2PosAtCollision_X, object2PosAtCollision_Y, object2PosAtCollision_Z); object2.position = (object2PosAtCollision); return millisecondsAfterCollision; }
From source file:com.digitale.utils.Util.java
License:Open Source License
public static Vector3 lookAt(Vector3 target, Vector3 observer) { float playerx = target.x; float playery = target.y; float playerz = target.z; Vector3 playerVector = new Vector3(playerx, playery, playerz); Vector3 direction = new Vector3(playerVector.sub(observer)); 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 {//ww w .j av a 2 s . co m npcYaw = 0.0; } } else { npcYaw = Math.atan2(direction.x, direction.z); } npcYaw = Math.toDegrees(npcYaw); return new Vector3((float) (npcPitch), (float) (npcYaw), 0); }
From source file:com.github.fauu.helix.displayable.DecalDisplayable.java
License:Open Source License
private void moveTo(Vector3 position) { Vector3 translation = position.sub(this.position); move(translation); }
From source file:com.lyeeedar.Roguelike3D.Graphics.Models.Shapes.java
License:Open Source License
public static Vector3 orthoNormalize(Vector3 vec1, Vector3 vec2) { vec1.nor();/* w w w . j a v a 2s . com*/ vec1.mul(vec2.dot(vec1)); vec2.sub(vec1); vec2.nor(); return vec2; }
From source file:com.mbrlabs.mundus.ui.modules.Outline.java
License:Apache License
private void setupDragAndDrop() { dragAndDrop = new DragAndDrop(); // source/* w ww . java2 s.c o m*/ dragAndDrop.addSource(new DragAndDrop.Source(tree) { @Override public DragAndDrop.Payload dragStart(InputEvent event, float x, float y, int pointer) { DragAndDrop.Payload payload = new DragAndDrop.Payload(); Tree.Node node = tree.getNodeAt(y); if (node != null) { payload.setObject(node); return payload; } return null; } }); // target dragAndDrop.addTarget(new DragAndDrop.Target(tree) { @Override public boolean drag(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { // Select node under mouse if not over the selection. Tree.Node overNode = tree.getNodeAt(y); if (overNode == null && tree.getSelection().isEmpty()) { return true; } if (overNode != null && !tree.getSelection().contains(overNode)) { tree.getSelection().set(overNode); } return true; } @Override public void drop(DragAndDrop.Source source, DragAndDrop.Payload payload, float x, float y, int pointer) { Tree.Node node = (Tree.Node) payload.getObject(); if (node != null) { GameObject draggedGo = (GameObject) node.getObject(); Tree.Node newParent = tree.getNodeAt(y); // check if a go is dragged in one of its' children or // itself if (newParent != null) { GameObject parentGo = (GameObject) newParent.getObject(); if (parentGo.isChildOf(draggedGo)) { return; } } GameObject oldParent = draggedGo.getParent(); // remove child from old parent draggedGo.remove(); // add to new parent if (newParent == null) { // recalculate position for root layer Vector3 newPos; Vector3 draggedPos = new Vector3(); draggedGo.getPosition(draggedPos); // if moved from old parent if (oldParent != null) { // new position = oldParentPos + draggedPos Vector3 parentPos = new Vector3(); oldParent.getPosition(parentPos); newPos = parentPos.add(draggedPos); } else { // new local position = World position newPos = draggedPos; } projectContext.currScene.sceneGraph.addGameObject(draggedGo); draggedGo.setLocalPosition(newPos.x, newPos.y, newPos.z); } else { GameObject parentGo = (GameObject) newParent.getObject(); // recalculate position Vector3 parentPos = new Vector3(); Vector3 draggedPos = new Vector3(); // World coorinates draggedGo.getPosition(draggedPos); parentGo.getPosition(parentPos); // if gameObject came from old parent if (oldParent != null) { // calculate oldParentPos + draggedPos Vector3 oldParentPos = new Vector3(); oldParent.getPosition(oldParentPos); draggedPos = oldParentPos.add(draggedPos); } // Local in releation to new parent Vector3 newPos = draggedPos.sub(parentPos); // add parentGo.addChild(draggedGo); draggedGo.setLocalPosition(newPos.x, newPos.y, newPos.z); } // update tree buildTree(sceneGraph); } } }); }
From source file:connex.Main.java
License:Open Source License
/** * @param timer/*from w w w . jav a 2 s. c om*/ */ private static void aitask(Timer timer) { timer.scheduleAtFixedRate(new TimerTask() { private int ticks; public void run() { try { //Class.forName("com.mysql.jdbc.Driver"); System.out.println("start NPC ai"); final Statement stmt; final Statement updatestmt; final Statement qrystmt; String query; //con = DriverManager.getConnection(MYSQLURL, serviceUser, // servicePass); updatestmt = con.createStatement(); stmt = con.createStatement(); qrystmt = con.createStatement(); // surnameUid=1000000 =hive ai scout ResultSet rs = stmt .executeQuery("SELECT * FROM `npc` WHERE (surnames_uid=1000000)and hitpoints >0"); // for each Hive ai scout while (rs.next()) { if (rs.getString("uid") != null) { float npcx = rs.getFloat("sysx"); float npcy = rs.getFloat("sysy"); float npcz = rs.getFloat("sysz"); BigInteger npcUID = BigInteger.valueOf(Long.valueOf(rs.getString("uid"))); int locx = rs.getInt("x"); int locy = rs.getInt("y"); int locz = rs.getInt("z"); // find nearest player in range query = "select uid,firstname, surname, sysx, sysy, sysz," + " MIN(ABS(sysx-" + npcx + ")) +MIN(ABS(sysy-" + npcy + ")) +MIN(ABS(sysz-" + npcz + ")) as dist" + " from player_char" + " where (x=" + locx + " and y=" + locy + " and z=" + locz + " and status=1" + ")" + " group by sysx,sysy,sysz" + " order by dist limit 1"; //if (DEBUG) System.out.println(query); ResultSet playerdata = qrystmt.executeQuery(query); Vector3 npcVector = new Vector3(npcx, npcy, npcz); while (playerdata.next()) { float playerx = playerdata.getFloat("sysx"); float playery = playerdata.getFloat("sysy"); float playerz = playerdata.getFloat("sysz"); int playerUID = playerdata.getInt("uid"); Vector3 playerVector = new Vector3(playerx, playery, playerz); Vector3 direction = new Vector3(playerVector.sub(npcVector)); double length = direction.len(); if (DEBUG) System.out.println(length); if (length < 2000) { if (DEBUG) System.out.println("moving to player"); 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); } npcYaw = Math.toDegrees(npcYaw); direction = (direction.nor().mul(10f)); query = "update npc set pitchangle=" + -npcPitch + ", yawangle=" + npcYaw + ",lastupdate=(select Now() from landscape limit 1)" + ",sysx=sysx+" + direction.x + ",sysy=sysy+" + direction.y + ",sysz=sysz+" + direction.z + "where uid=" + npcUID; if (DEBUG) System.out.println(query); int affected = updatestmt.executeUpdate(query); //attack players in range if (length < 200 && ticks == 1) { query = "update player_char set hitpoints=hitpoints-50, lastattackeruid=-" + npcUID + ",lastupdate=(select Now() from landscape limit 1) where uid=" + playerUID; if (DEBUG) System.out.println(query); int newaffected = updatestmt.executeUpdate(query); } } } } } ticks++; if (ticks == 10) ticks = 0; // con.close(); stmt.close(); updatestmt.close(); qrystmt.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }, 0, 200); }
From source file:connex.NPCtasks.java
License:Open Source License
/** * @param stmt// w w w. j a va 2 s . c o m * @param updatestmt * @throws SQLException */ private static void respawnShieldDisruptor(Statement stmt, Statement updatestmt) throws SQLException { String query; ResultSet rs; // surname id 1 is a shield disruptor hive ai rs = stmt.executeQuery("SELECT count(*)as count FROM `npc` WHERE (surnames_uid=1)and shipname!='dead'"); while (rs.next()) { int count = Integer.valueOf(rs.getString("count")); System.out.println("count " + count); if (count <= 20) { double s = Math.random(); double t = Math.random(); double u = s * Math.PI * 2; double z = t * 2 - 1; double r = Math.sqrt(1 - z * z); double x = r * Math.cos(u); double y = r * Math.sin(u); //point disruptor at station Vector3 npcVector = new Vector3((float) (x), (float) (y), (float) (z)); Vector3 targetVector = new Vector3(0, 0, 0); Vector3 direction = new Vector3(targetVector.sub(npcVector)); double length = direction.len(); System.out.println(length); 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); } npcYaw = Math.toDegrees(npcYaw); query = "INSERT INTO npc (`UID`, `race`, `x`, `y`, `z`, `is_static`, `firstnames_uid`, `surnames_uid`," + " `sysx`, `sysy`, `sysz`, `hitpoints`, `faction`, `stamina`, `intelligence`, `social`, `dexterity`, `leadership`, `recuperation`, `exp`," + "`firstattackeruid`,`lastattackeruid`,`expvalue`,`creditvalue`,`status`,`yawangle`,`pitchangle`,`shipname`,`lastupdate`)" + " VALUES (NULL, 'aih', '1', '1', '10', '1', '7168', '1', '" + x * 1500 + "', '" + y * 1500 + "', '" + z * 1500 + "', '500', 'aihive', '1', '1', '1', '1', '1', '1', '0','0','0','100','1000','1','" + npcYaw + "','" + npcPitch + "','shielddisruptor',(select NOW() from landscape limit 1))"; System.out.println(query); int affected = updatestmt.executeUpdate(query); } } }
From source file:MeshBoneUtil.CreatureManager.java
License:Open Source License
public void AlterBonesByAnchor(HashMap<String, MeshBoneUtil.MeshBone> bones_map, String animation_name_in) { if (target_creature.anchor_points_active == false) { return;/*from www . ja va 2 s . c o m*/ } Vector2 anchor_point = target_creature.GetAnchorPoint(animation_name_in); Vector3 anchor_vector = new Vector3(anchor_point.x, anchor_point.y, 0); for (String curKey : bones_map.keySet()) { MeshBone cur_bone = bones_map.get(curKey); Vector3 start_pt = cur_bone.getWorldStartPt(); Vector3 end_pt = cur_bone.getWorldEndPt(); start_pt.sub(anchor_vector); end_pt.sub(anchor_vector); cur_bone.setWorldStartPt(start_pt); cur_bone.setWorldEndPt(end_pt); } }