Java Code Examples for com.badlogic.gdx.math.Vector3#set()
The following examples show how to use
com.badlogic.gdx.math.Vector3#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NavMesh.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Make a ray test at this point, using a ray spanning from far up in the sky, to far down in the ground, * along the up axis. * * @param testPoint The test point * @param out The point of intersection between ray and triangle * @param allowedMeshParts Which mesh parts to test. Null if all meshparts should be tested. * @return The triangle, or null if ray did not hit any triangles. */ public Triangle verticalRayTest(Vector3 testPoint, Vector3 out, Bits allowedMeshParts) { tmpRayVerticalRayTest.set( tmpVerticalRayTest1.set(Constants.V3_UP).scl(500).add(testPoint), tmpVerticalRayTest2.set(Constants.V3_DOWN)); Triangle hitTri = rayTest(tmpRayVerticalRayTest, 1000, allowedMeshParts); if (hitTri == null) { // TODO: Perhaps this should be Nan? out.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); return null; } else { Intersector.intersectRayTriangle(tmpRayVerticalRayTest, hitTri.a, hitTri.b, hitTri.c, out); return hitTri; } }
Example 2
Source File: HUD.java From gdx-proto with Apache License 2.0 | 6 votes |
public void getMoveTranslation(Vector3 trans) { trans.setZero(); float x = 0f, y = 0f, z = 0f; if (forward.isPressed()) { z += 1f; } if (back.isPressed()) { z -= 1f; } if (left.isPressed()) { x += 1f; } if (right.isPressed()) { x -= 1f; } trans.set(x, y, z); }
Example 3
Source File: GeometryUtils.java From GdxDemo3D with Apache License 2.0 | 6 votes |
/** * Projects a point to a line segment. This implementation is thread-safe. * * @param nearest Output for the nearest vector to the segment. * @param start Segment start point * @param end Segment end point * @param point Point to project from * @return Squared distance between point and nearest. */ public static float nearestSegmentPointSquareDistance (Vector3 nearest, Vector3 start, Vector3 end, Vector3 point) { nearest.set(start); float abX = end.x - start.x; float abY = end.y - start.y; float abZ = end.z - start.z; float abLen2 = abX * abX + abY * abY + abZ * abZ; if (abLen2 > 0) { // Avoid NaN due to the indeterminate form 0/0 float t = ((point.x - start.x) * abX + (point.y - start.y) * abY + (point.z - start.z) * abZ) / abLen2; float s = MathUtils.clamp(t, 0, 1); nearest.x += abX * s; nearest.y += abY * s; nearest.z += abZ * s; } return nearest.dst2(point); }
Example 4
Source File: HelpScreen.java From FruitCatcher with Apache License 2.0 | 6 votes |
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { Vector3 touchPos = new Vector3(); touchPos.set(screenX, screenY, 0); camera.unproject(touchPos); for(int i=0;i<buttons.length;i++) { if (buttons[i].isPressed(touchPos)) { if (i == 0) { game.gotoMenuScreen(); } break; } } return true; }
Example 5
Source File: Terrain.java From Mundus with Apache License 2.0 | 5 votes |
public Vector3 getVertexPosition(Vector3 out, int x, int z) { final float dx = (float) x / (float) (vertexResolution - 1); final float dz = (float) z / (float) (vertexResolution - 1); final float height = heightData[z * vertexResolution + x]; out.set(dx * this.terrainWidth, height, dz * this.terrainDepth); return out; }
Example 6
Source File: HeightMap.java From gdx-proto with Apache License 2.0 | 5 votes |
/** * Get the interpolated height for x,z coords, accounting for scale, interpolated using neighbors. * This will give the interpolated height when the parameters lie somewhere between actual heightmap data points. * parameters assume heightmap's origin is at world coordinates x:0, z: 0 * @return the scale-adjusted interpolated height at specified world coordinates */ public float getInterpolatedHeight(float xf, float zf) { Vector3 a = tmp; Vector3 b = tmp2; Vector3 c = tmp3; Vector3 d = tmp4; float baseX = (float) Math.floor(xf / widthScale); float baseZ = (float) Math.floor(zf / widthScale); float x = baseX * widthScale; float z = baseZ * widthScale; float x2 = x + widthScale; float z2 = z + widthScale; a.set(x, getHeight(x , z2), z2); b.set(x, getHeight(x , z), z); c.set(x2, getHeight(x2, z), z); d.set(x2, getHeight(x2, z2), z2); float zFrac = 1f - (zf - z) / widthScale; float xFrac = (xf - x) / widthScale; float y = (1f - zFrac) * ((1-xFrac) * a.y + xFrac * d.y) + zFrac * ((1-xFrac) * b.y + xFrac * c.y); return y; }
Example 7
Source File: GameScreen.java From FruitCatcher with Apache License 2.0 | 5 votes |
@Override public boolean touchDragged(int screenX, int screenY, int pointer) { if (st.isStarted && !st.isPaused) { Vector3 touchPos = new Vector3(); touchPos.set(screenX, screenY, 0); camera.unproject(touchPos); if (st.secondsRemaining > 0) { basket.setPositionX(touchPos.x); } } return true; }
Example 8
Source File: GameScreen.java From FruitCatcher with Apache License 2.0 | 5 votes |
@Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { if (st.isPaused) { resume(); return true; } Vector3 touchPos = new Vector3(); touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(touchPos); if (!st.isStarted) { st.isStarted = startGameMessage.isStartPressed(touchPos); if (st.isStarted) { startGame(); } } else if (st.secondsRemaining == 0) { if (backButton.isPressed(touchPos)) { game.endGame(0); game.gotoMenuScreen(); } else if (endGameMessage.isPressed(touchPos)) { if (st.score >= goal) { int totalScore = game.getTotalScore() + st.score; game.setTotalScore(totalScore); game.gotoNextGame(); } else { game.restartLevel(); } resetState(); initGame(); } } return true; }
Example 9
Source File: GameCharacter.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Midpoint of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneMidpointWorldPosition(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; // Use global transform to account for model scaling node.globalTransform.getTranslation(TMP_V1); TMP_V3.set(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V3.sub(TMP_V1.sub(TMP_V2).scl(0.5f)); modelInstance.transform.getRotation(TMP_Q, true).transform(TMP_V3); TMP_V3.add(getPosition()); return out.set(TMP_V3); }
Example 10
Source File: Triangle.java From GdxDemo3D with Apache License 2.0 | 5 votes |
/** * Calculates the angle in radians between a reference vector and the (plane) normal of the triangle. * * @param reference * @return */ public float getAngle(Vector3 reference) { float x = reference.x; float y = reference.y; float z = reference.z; Vector3 normal = reference; normal.set(a).sub(b).crs(b.x - c.x, b.y - c.y, b.z - c.z).nor(); float angle = (float) Math.acos(normal.dot(x, y, z) / (normal.len() * Math.sqrt(x * x + y * y + z * z))); reference.set(x, y, z); return angle; }
Example 11
Source File: MenuScreen.java From FruitCatcher with Apache License 2.0 | 5 votes |
@Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { Vector3 touchPos = new Vector3(); touchPos.set(screenX, screenY, 0); camera.unproject(touchPos); for(int i=0;i<buttons.length;i++) { if (buttons[i].isPressed(touchPos)) { if (i == 0) { game.gotoLevelScreen(); } else if (i == 1) { game.startGameKidsMode(); game.gotoGameScreen(null); } else if (i == 2) { game.showHighscores(); } break; } } if (helpButton.isPressed(touchPos)) { game.showHelp(); } if (soundOn && soundButtons[0].isPressed(touchPos)) { soundOn = false; State.setSoundOn(soundOn); game.getSoundManager().setSoundOn(soundOn); } else if (!soundOn && soundButtons[1].isPressed(touchPos)) { soundOn = true; State.setSoundOn(soundOn); game.getSoundManager().setSoundOn(soundOn); } return true; }
Example 12
Source File: DynamicEntity.java From gdx-proto with Apache License 2.0 | 4 votes |
public Vector3 getForwardFacing(Vector3 storage) { storage.set(Vector3.Z); relativize(storage); return storage; }
Example 13
Source File: DefaultSceneScreen.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private void getInputUnProject(Vector3 out) { out.set(Gdx.input.getX(), Gdx.input.getY(), 0); viewport.unproject(out); }
Example 14
Source File: LevelBuilder.java From gdx-proto with Apache License 2.0 | 4 votes |
public static void createLevel() { // graphical representation of the ground Log.debug("createLevel - create ground"); if (Main.isClient()) { ModelBuilder mb = new ModelBuilder(); mb.begin(); Vector3 bl = new Vector3(); Vector3 tl = new Vector3(); Vector3 tr = new Vector3(); Vector3 br = new Vector3(); Vector3 norm = new Vector3(0f, 1f, 0f); // the size of each rect that makes up the ground Texture groundTex = Assets.manager.get("textures/ground1.jpg", Texture.class); Material groundMat = new Material(TextureAttribute.createDiffuse(groundTex)); MeshPartBuilder mpb = mb.part("ground", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, groundMat); float u1 = 0f; float v1 = 0f; float u2 = groundPieceSize / 5f; float v2 = groundPieceSize / 5f; mpb.setUVRange(u1, v1, u2, v2); bl.set(0, 0, 0); tl.set(0, 0, groundPieceSize); tr.set(groundPieceSize, 0, groundPieceSize); br.set(groundPieceSize, 0, 0); //mpb.rect(bl, tl, tr, br, norm); int divisions = ((int) groundPieceSize) / 4; mpb.patch(bl, tl, tr, br, norm, divisions, divisions); Model groundModel = mb.end(); models.add(groundModel); groundPieces.clear(); int count = 0; for (int x = 0; x < GameWorld.WORLD_WIDTH; x += groundPieceSize) { for (int z = 0; z < GameWorld.WORLD_DEPTH; z += groundPieceSize) { count++; ModelInstance groundPiece = new ModelInstance(groundModel); groundPiece.transform.setToTranslation(x, 0f, z); groundPieces.add(groundPiece); } } Log.debug("createLevel - created " + count + " groundPieces"); } // physical representation of the ground btCollisionObject groundObj = new btCollisionObject(); btCollisionShape groundShape = new btStaticPlaneShape(Vector3.Y, 0f); groundObj.setCollisionShape(groundShape); Physics.applyStaticGeometryCollisionFlags(groundObj); Physics.inst.addStaticGeometryToWorld(groundObj); if (Main.isServer()) { Log.debug("createLevel - create static models"); // server creates static models here, client will create the models when received from server upon connection createStaticModels(25); } Log.debug("createLevel - create boxes"); Box.createBoxes(10); }
Example 15
Source File: GLTFTypes.java From gdx-gltf with Apache License 2.0 | 4 votes |
public static Vector3 map(Vector3 v, float[] fv) { return v.set(fv[0], fv[1], fv[2]); }
Example 16
Source File: TranslateTool.java From Mundus with Apache License 2.0 | 4 votes |
@Override public void act() { super.act(); if (getProjectManager().current().currScene.currentSelection != null) { translateHandles(); if (state == TransformState.IDLE) return; Ray ray = getProjectManager().current().currScene.viewport.getPickRay(Gdx.input.getX(), Gdx.input.getY()); Vector3 rayEnd = getProjectManager().current().currScene.currentSelection.getLocalPosition(temp0); float dst = getProjectManager().current().currScene.cam.position.dst(rayEnd); rayEnd = ray.getEndPoint(rayEnd, dst); if (initTranslate) { initTranslate = false; lastPos.set(rayEnd); } GameObject go = getProjectManager().current().currScene.currentSelection; boolean modified = false; Vector3 vec = new Vector3(); if (state == TransformState.TRANSFORM_XZ) { vec.set(rayEnd.x - lastPos.x, 0, rayEnd.z - lastPos.z); modified = true; } else if (state == TransformState.TRANSFORM_X) { vec.set(rayEnd.x - lastPos.x, 0, 0); modified = true; } else if (state == TransformState.TRANSFORM_Y) { vec.set(0, rayEnd.y - lastPos.y, 0); modified = true; } else if (state == TransformState.TRANSFORM_Z) { vec.set(0, 0, rayEnd.z - lastPos.z); modified = true; } // TODO translation in global sapce // if(globalSpace) { // System.out.println("Before: " + vec); // System.out.println("After: " + vec); // } go.translate(vec); if (modified) { gameObjectModifiedEvent.setGameObject(getProjectManager().current().currScene.currentSelection); Mundus.INSTANCE.postEvent(gameObjectModifiedEvent); } lastPos.set(rayEnd); } }
Example 17
Source File: SimpleNode.java From Mundus with Apache License 2.0 | 4 votes |
@Override public Vector3 getLocalScale(Vector3 out) { return out.set(localScale); }
Example 18
Source File: SimpleNode.java From Mundus with Apache License 2.0 | 4 votes |
@Override public Vector3 getLocalPosition(Vector3 out) { return out.set(localPosition); }
Example 19
Source File: GLTFTypes.java From gdx-gltf with Apache License 2.0 | 4 votes |
public static Vector3 map(Vector3 v, float[] fv, int offset) { return v.set(fv[offset+0], fv[offset+1], fv[offset+2]); }
Example 20
Source File: SceneCamera.java From bladecoder-adventure-engine with Apache License 2.0 | 3 votes |
public void getInputUnProject(Viewport viewport, Vector3 out) { out.set(Gdx.input.getX(), Gdx.input.getY(), 0); unproject(out, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(), viewport.getScreenHeight()); out.x = MathUtils.clamp(out.x, 0, scrollingWidth - 1); out.y = MathUtils.clamp(out.y, 0, scrollingHeight - 1); }