List of usage examples for com.badlogic.gdx.math Vector2 Vector2
public Vector2()
From source file:com.gamejolt.mikykr5.ceidecpong.states.BaseState.java
License:Open Source License
/** * Sets up all the general state fields. * /*from w ww . j a v a2s. co m*/ * @param core The game core. * @throws IllegalArgumentException If core is null. */ public BaseState(final GameCore core) throws IllegalArgumentException { if (core == null) throw new IllegalArgumentException(CLASS_NAME + ": Core is null."); this.core = core; this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); win2world = new Vector3(0.0f, 0.0f, 0.0f); touchPointWorldCoords = new Vector2(); }
From source file:com.github.antag99.chick.component.Position.java
License:Open Source License
/** * Returns a new {@link Vector2} set to the value of this component. * * @return A new {@link Vector2} with the value of this component. *//*from w w w . ja v a 2s. c o m*/ public Vector2 v() { return v(new Vector2()); }
From source file:com.gmail.emersonmx.asteroids.component.MovementComponent.java
License:Open Source License
public MovementComponent() { velocity = new Vector2(); direction = new Vector2(1, 0); direction.clamp(-1, 1); acceleration = 1; angularVelocity = 10; }
From source file:com.gmail.emersonmx.asteroids.component.TransformComponent.java
License:Open Source License
public TransformComponent() { position = new Vector2(); rotation = 0; }
From source file:com.hajnar.GravityShip.GameObjects.GameCamera.java
License:Apache License
public GameCamera(float width, float height) { super(width, height); this.playerVelocityBefore = 0; this.offset = new Vector2(); this.cameraTranslation = new Vector2(); }
From source file:com.hajnar.GravityShip.GameObjects.Terrain.java
License:Apache License
public void generateMeshes() { ArrayList<Fixture> terrainFixtures = objectBody.getFixtureList(); Vector2 boxVertex = new Vector2(); meshes = new ArrayList<Mesh>(); boundingBoxes = new ArrayList<BoundingBox>(); EarClippingTriangulator ear = new EarClippingTriangulator(); for (Fixture terrainFixture : terrainFixtures) { PolygonShape shape = (PolygonShape) terrainFixture.getShape(); boxVertex = new Vector2(); int vc = shape.getVertexCount(); ArrayList<Vector2> boxVertices = new ArrayList<Vector2>(); ArrayList<Vector2> triaBoxVertices = new ArrayList<Vector2>(); for (int i = 0; i < vc; i++) { shape.getVertex(i, boxVertex); boxVertex = objectBody.getWorldPoint(boxVertex).mul(Helper.BOX_TO_WORLD); boxVertices.add(boxVertex.cpy()); }/*from w w w .j a va 2 s . c o m*/ triaBoxVertices = (ArrayList<Vector2>) ear.computeTriangles(boxVertices); float[] meshVertices = new float[triaBoxVertices.size() * 4]; short[] meshIndices = new short[triaBoxVertices.size()]; for (int i = 0; i < triaBoxVertices.size(); i++) { meshVertices[i * 4] = triaBoxVertices.get(i).x; meshVertices[i * 4 + 1] = triaBoxVertices.get(i).y; meshVertices[i * 4 + 2] = triaBoxVertices.get(i).x * TEXTURE_SCALE; meshVertices[i * 4 + 3] = triaBoxVertices.get(i).y * TEXTURE_SCALE; meshIndices[i] = (short) i; } Mesh mesh = new Mesh(true, triaBoxVertices.size(), triaBoxVertices.size(), new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0")); mesh.setVertices(meshVertices); mesh.setIndices(meshIndices); meshes.add(mesh); boundingBoxes.add(mesh.calculateBoundingBox()); } }
From source file:com.hajnar.GravityShip.GameWorld.java
License:Apache License
public GameWorld() { state = WORLD_RUNNING;/*w ww . ja v a 2s . c o m*/ thrustParticleEffect = new ParticleEffect(); thrustParticleEffect.load(Gdx.files.internal("data/thrust.p"), Gdx.files.internal("data")); thrustParticleEmitters = thrustParticleEffect.getEmitters(); explosionParticleEffect = new ParticleEffect(); explosionParticleEffect.load(Gdx.files.internal("data/explossion.p"), Gdx.files.internal("data")); explosionParticleEmitters = explosionParticleEffect.getEmitters(); starsParticleEffect = new ParticleEffect(); starsParticleEffect.load(Gdx.files.internal("data/stars.p"), Gdx.files.internal("data")); starsParticleEmitters = starsParticleEffect.getEmitters(); landingZones = new ArrayList<LandingZone>(); canons = new ArrayList<Canon>(); bullets = new ArrayList<Bullet>(); blackHoles = new ArrayList<BlackHole>(); stars = new ArrayList<Star>(); objectsToDestroy = new ArrayList<GameObject>(); collidingObjects = new GameObject[2]; landedZoneType = 0; landedDuration = 0; firePauseDuration = 0; startFuelAmmount = 0; canonsFireInterval = 0; tmpVector = new Vector2(); }
From source file:com.hindelid.ld.thirtyfour.Fish.java
License:Apache License
public Fish(float aX, float aY) { mRadus = Constants.sRandom.nextFloat() * 0.4f + 0.4f; mPos = new Vector2(); mTailOffset = new Vector2(MathUtils.cosDeg(deg) * mRadus, MathUtils.sinDeg(deg) * mRadus); mLampOffset = new Vector2(MathUtils.sinDeg(deg) * mRadus, MathUtils.cosDeg(deg) * mRadus); mBoundingBox = new Rectangle(0, 0, mRadus * 2, mRadus * 2); setPos(aX, aY);//w ww . j a v a 2 s.c o m }
From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DUtils.java
License:Apache License
/** @return the vertices of the given Shape */ public static Vector2[] vertices(Shape shape, Vector2[] output) { if (shapeCache.containsKey(shape)) return output = shapeCache.get(shape).vertices; else {/*from w w w.ja v a2 s .co m*/ switch (shape.getType()) { case Polygon: PolygonShape polygonShape = (PolygonShape) shape; output = new Vector2[polygonShape.getVertexCount()]; for (int i = 0; i < output.length; i++) { output[i] = new Vector2(); polygonShape.getVertex(i, output[i]); } break; case Edge: EdgeShape edgeShape = (EdgeShape) shape; edgeShape.getVertex1(tmpVec); edgeShape.getVertex2(tmpVec2); output = new Vector2[] { tmpVec, tmpVec2 }; break; case Chain: ChainShape chainShape = (ChainShape) shape; output = new Vector2[chainShape.getVertexCount()]; for (int i = 0; i < output.length; i++) { output[i] = new Vector2(); chainShape.getVertex(i, output[i]); } break; case Circle: CircleShape circleShape = (CircleShape) shape; output = new Vector2[] { new Vector2(circleShape.getPosition().x - circleShape.getRadius(), circleShape.getPosition().y + circleShape.getRadius()), // top left new Vector2(circleShape.getPosition().x - circleShape.getRadius(), circleShape.getPosition().y - circleShape.getRadius()), // bottom left new Vector2(circleShape.getPosition().x + circleShape.getRadius(), circleShape.getPosition().y - circleShape.getRadius()), // bottom right new Vector2(circleShape.getPosition().x + circleShape.getRadius(), circleShape.getPosition().y + circleShape.getRadius()) // top right }; break; default: throw new IllegalArgumentException( "Shapes of the type '" + shape.getType().name() + "' are not supported"); } if (autoShapeCache && shapeCache.size < autoShapeCacheMaxSize) { Vector2[] cachedOutput = new Vector2[output.length]; System.arraycopy(output, 0, cachedOutput, 0, output.length); shapeCache.put(shape, new ShapeCache(cachedOutput, amplitude(filterX(cachedOutput)), amplitude(filterY(cachedOutput)), min(filterX(cachedOutput)), max(filterX(cachedOutput)), min(filterY(cachedOutput)), max(filterY(cachedOutput)))); } return output; } }
From source file:com.indignado.games.smariano.utils.dermetfan.math.GeometryUtils.java
License:Apache License
/** * @param vertices the vertices of the polygon to examine for convexity * @return if the polygon is convex/* w w w . j av a2 s . c om*/ */ public static boolean isConvex(Vector2[] vertices) { // http://www.sunshine2k.de/coding/java/Polygon/Convex/polygon.htm Vector2 p, v, u; float res = 0; for (int i = 0; i < vertices.length; i++) { p = vertices[i]; tmpVec = vertices[(i + 1) % vertices.length]; v = new Vector2(); v.x = tmpVec.x - p.x; v.y = tmpVec.y - p.y; u = vertices[(i + 2) % vertices.length]; if (i == 0) // in first loop direction is unknown, so save it in res res = u.x * v.y - u.y * v.x + v.x * p.y - v.y * p.x; else { float newres = u.x * v.y - u.y * v.x + v.x * p.y - v.y * p.x; if (newres > 0 && res < 0 || newres < 0 && res > 0) return false; } } return true; }