List of usage examples for com.badlogic.gdx.math Vector3 set
public Vector3 set(float x, float y, float z)
From source file:apps101.libgdx_demo.Game.java
License:Open Source License
@Override public void render() { Gdx.gl.glClearColor(0.199f, 0.398f, 0.598f, 0.4f); // OpenGL code to make the screen blue Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); // OpenGL code to clear the screen camera.update();/* w w w . j av a2 s . c o m*/ /** Render the smileyface image and helloworld image **/ batch.setProjectionMatrix(camera.combined); batch.begin(); batch.draw(smileyface, rect_smiley.x, rect_smiley.y); batch.draw(helloworld, rect_hello.x, rect_hello.y); batch.end(); /** Simple technique to detect user input on the touch screen **/ if (Gdx.input.isTouched()) { Vector3 touchPos = new Vector3(); touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(touchPos); /** center the smiley face on the touch (x,y) coordinates **/ rect_smiley.x = touchPos.x - 128 / 2; rect_smiley.y = touchPos.y - 128 / 2; } }
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();/*from ww w . j a v a2 s . com*/ 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); }
From source file:com.altportalgames.colorrain.utils.TiledMapHelper.java
License:Apache License
/** * Renders the part of the map that should be visible to the user. *//* w w w. j a v a 2s . co m*/ public void render() { tiledMapRenderer.getProjectionMatrix().set(camera.combined); Vector3 tmp = new Vector3(); tmp.set(0, 0, 0); camera.unproject(tmp); /*tiledMapRenderer.render((int) tmp.x, tiledMapRenderer.getMapHeightUnits() - (int) tmp.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), layersList);*/ tiledMapRenderer.render(tmp.x, tmp.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), layersList); }
From source file:com.avechados.main.TiledMapHelper.java
License:Apache License
/** * Renders the part of the map that should be visible to the user. *//*from w w w .ja v a 2 s .com*/ public void render() { tileMapRenderer.getProjectionMatrix().set(camera.combined); Vector3 tmp = new Vector3(); tmp.set(0, 0, 0); camera.unproject(tmp); tileMapRenderer.render((int) tmp.x, (int) tmp.y, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), layersList); }
From source file:com.axatrikx.solor.view.DummyLevelScreen.java
License:Apache License
@Override public void render(float delta) { super.render(delta); // begin a new batch and draw the bucket and // all drops// w w w . j a va 2 s . co m batch.begin(); font.draw(batch, "Drops Collected: " + dropsGathered, 0, 480); batch.draw(bucketImage, bucket.x, bucket.y); for (Rectangle raindrop : raindrops) { batch.draw(dropImage, raindrop.x, raindrop.y); } batch.end(); // process user input if (Gdx.input.isTouched()) { Vector3 touchPos = new Vector3(); touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0); camera.unproject(touchPos); bucket.x = touchPos.x - 64 / 2; } if (Gdx.input.isKeyPressed(Keys.LEFT)) bucket.x -= 200 * Gdx.graphics.getDeltaTime(); if (Gdx.input.isKeyPressed(Keys.RIGHT)) bucket.x += 200 * Gdx.graphics.getDeltaTime(); // make sure the bucket stays within the screen bounds if (bucket.x < 0) bucket.x = 0; if (bucket.x > 800 - 64) bucket.x = 800 - 64; // check if we need to create a new raindrop if (TimeUtils.nanoTime() - lastDropTime > 1000000000) spawnRaindrop(); // move the raindrops, remove any that are beneath the bottom edge of // the screen or that hit the bucket. In the later case we play back // a sound effect as well. Iterator<Rectangle> iter = raindrops.iterator(); while (iter.hasNext()) { Rectangle raindrop = iter.next(); raindrop.y -= 200 * Gdx.graphics.getDeltaTime(); if (raindrop.y + 64 < 0) iter.remove(); if (raindrop.overlaps(bucket)) { dropsGathered++; dropSound.play(); iter.remove(); } } }
From source file:com.badlogic.gdx.physics.bullet.demo.screens.DemoScreen.java
public void dropThing(boolean type) { if (!isPaused()) { float x = (random.nextFloat() * 10f) - 5f; float y = (random.nextFloat() * 10f) - 5f; float z = 20; final btTransform transform = Pools.btTRANSFORM.obtain(); final Vector3 vector = Pools.VECTOR3.obtain(); final Matrix3 basis = Pools.MATRIX3.obtain(); transform.setIdentity();//from www . j a v a2 s. c o m transform.setOrigin(vector.set(x, y, z)); MeshSimulationObject object; if (type) { // Don't autodispose the mesh and texture object = new MeshSimulationObject(cubeMesh, GL10.GL_TRIANGLES, false, cubeTexture, false); object.initialize(new btBoxShape(vector.set(1, 1, 1)), 50, -1, transform); } else { // Don't autodispose the mesh and texture object = new MeshSimulationObject(icosphereMesh, GL10.GL_TRIANGLES, false, icosphereTexture, false); object.initialize(new btSphereShape(1), 50, -1, transform); } addCollisionSimulationObject(object); Pools.btTRANSFORM.free(transform); Pools.VECTOR3.free(vector); Pools.MATRIX3.free(basis); } }
From source file:com.badlogic.gdx.physics.bullet.demo.screens.DemoScreen.java
@Override protected void hookAddSimulationObjects() { final btTransform transform = Pools.btTRANSFORM.obtain(); final Vector3 vector = Pools.VECTOR3.obtain(); // Terrain/*from ww w. j av a 2s . co m*/ transform.setIdentity(); vector.set(0, 0, 0); transform.setOrigin(vector); terrain = new MeshSimulationObject(terrainMesh, GL10.GL_TRIANGLES, false, terrainTexture, false); terrain.initialize(MeshSimulationObject.createTriangleMeshShape(terrainMesh, terrainTriangleMesh), 0, -1, transform); terrain.getRigidbody().setCollisionFlags(CollisionFlags.CF_STATIC_OBJECT); addCollisionSimulationObject(terrain); // terrain = new StaticPlaneSimulationObject(vector.set(0, 0, 1), 1, -1, 50, 50, terrainTexture, false); // addCollisionSimulationObject(terrain); Pools.btTRANSFORM.free(transform); Pools.VECTOR3.free(vector); }
From source file:com.badlogic.gdx.physics.bullet.demo.simulationobjects.RigidSimulationObject.java
/** * Initializes the {@link RigidSimulationObject} from the given shape and other parameters. Call this once before * adding to the dynamics world./*w w w .ja v a 2 s . co m*/ * <p> * * @param collisionShape * the shape (the reference is held by this class and will be diposed automatically) * @param mass * the mass * @param friction * the friction or -1 for default * @param startTransform * the start transform (reference is not captured) */ public void initialize(btCollisionShape collisionShape, float mass, float friction, btTransform startTransform) { this.collisionShape = collisionShape; motionState = new btDefaultMotionState(startTransform); final Vector3 localInertia = Pools.VECTOR3.obtain(); localInertia.set(0, 0, 0); if (mass != 0) { collisionShape.calculateLocalInertia(mass, localInertia); } final btRigidBodyConstructionInfo bodyCI = new btRigidBodyConstructionInfo(mass, motionState, collisionShape, localInertia); if (friction != -1) { bodyCI.setM_friction(friction); } rigidBody = new btRigidBody(bodyCI); // All fields copied during construction bodyCI.delete(); setCollisionObject(rigidBody); Pools.VECTOR3.free(localInertia); }
From source file:com.badlogic.gdx.tests.g3d.HeightField.java
public Vector3 getWeightedNormalAt(Vector3 out, int x, int y) { // This commented code is based on http://www.flipcode.com/archives/Calculating_Vertex_Normals_for_Height_Maps.shtml // Note that this approach only works for a heightfield on the XZ plane with a magnitude on the y axis // float sx = data[(x < width - 1 ? x + 1 : x) + y * width] + data[(x > 0 ? x-1 : x) + y * width]; // if (x == 0 || x == (width - 1)) // sx *= 2f;//from w w w .ja v a 2s . c o m // float sy = data[(y < height - 1 ? y + 1 : y) * width + x] + data[(y > 0 ? y-1 : y) * width + x]; // if (y == 0 || y == (height - 1)) // sy *= 2f; // float xScale = (corner11.x - corner00.x) / (width - 1f); // float zScale = (corner11.z - corner00.z) / (height - 1f); // float yScale = magnitude.len(); // out.set(-sx * yScale, 2f * xScale, sy*yScale*xScale / zScale).nor(); // return out; // The following approach weights the normal of the four triangles (half quad) surrounding the position. // A more accurate approach would be to weight the normal of the actual triangles. int faces = 0; out.set(0, 0, 0); Vector3 center = getPositionAt(tmpV2, x, y); Vector3 left = x > 0 ? getPositionAt(tmpV3, x - 1, y) : null; Vector3 right = x < (width - 1) ? getPositionAt(tmpV4, x + 1, y) : null; Vector3 bottom = y > 0 ? getPositionAt(tmpV5, x, y - 1) : null; Vector3 top = y < (height - 1) ? getPositionAt(tmpV6, x, y + 1) : null; if (top != null && left != null) { out.add(tmpV7.set(top).sub(center).nor().crs(tmpV8.set(center).sub(left).nor()).nor()); faces++; } if (left != null && bottom != null) { out.add(tmpV7.set(left).sub(center).nor().crs(tmpV8.set(center).sub(bottom).nor()).nor()); faces++; } if (bottom != null && right != null) { out.add(tmpV7.set(bottom).sub(center).nor().crs(tmpV8.set(center).sub(right).nor()).nor()); faces++; } if (right != null && top != null) { out.add(tmpV7.set(right).sub(center).nor().crs(tmpV8.set(center).sub(top).nor()).nor()); faces++; } if (faces != 0) out.scl(1f / (float) faces); else out.set(magnitude).nor(); return out; }
From source file:com.bladecoder.engine.model.SceneCamera.java
License:Apache License
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); }