@Override public Vector2 cpy () { return new Vector2(this); }
@Override public Vector2 cpy () { return new Vector2(this); }
public Box2DDebugRenderer (boolean drawBodies, boolean drawJoints, boolean drawAABBs, boolean drawInactiveBodies, boolean drawVelocities, boolean drawContacts) { // next we setup the immediate mode renderer renderer = new ShapeRenderer(); // next we create a SpriteBatch and a font batch = new SpriteBatch(); lower = new Vector2(); upper = new Vector2(); // initialize vertices array for (int i = 0; i < vertices.length; i++) vertices[i] = new Vector2(); this.drawBodies = drawBodies; this.drawJoints = drawJoints; this.drawAABBs = drawAABBs; this.drawInactiveBodies = drawInactiveBodies; this.drawVelocities = drawVelocities; this.drawContacts = drawContacts; }
public Caveman (float x, float y, boolean headsLeft) { pos = new Vector2().set(x, y); this.headsLeft = headsLeft; this.stateTime = (float)Math.random(); }
public Box2DDebugRenderer (boolean drawBodies, boolean drawJoints, boolean drawAABBs, boolean drawInactiveBodies, boolean drawVelocities, boolean drawContacts) { // next we setup the immediate mode renderer renderer = new ShapeRenderer(); // initialize vertices array for (int i = 0; i < vertices.length; i++) vertices[i] = new Vector2(); this.drawBodies = drawBodies; this.drawJoints = drawJoints; this.drawAABBs = drawAABBs; this.drawInactiveBodies = drawInactiveBodies; this.drawVelocities = drawVelocities; this.drawContacts = drawContacts; }
private Vector2 readVector2 (JsonValue vectorArray, float x, float y) { if (vectorArray == null) return new Vector2(x, y); else if (vectorArray.size == 2) return new Vector2(vectorArray.getFloat(0), vectorArray.getFloat(1)); else throw new GdxRuntimeException("Expected Vector2 values <> than two."); }
private Vector2 readVector2 (JsonValue vectorArray, float x, float y) { if (vectorArray == null) return new Vector2(x, y); else if (vectorArray.size == 2) return new Vector2(vectorArray.getFloat(0), vectorArray.getFloat(1)); else throw new GdxRuntimeException("Expected Vector2 values <> than two."); }
public WorldManifold getWorldManifold () { contact.getWorldManifold(worldManifold2); int numContactPoints = contact.getManifold().pointCount; worldManifold.numContactPoints = numContactPoints; worldManifold.normal.set(worldManifold2.normal.x, worldManifold2.normal.y); for (int i = 0; i < worldManifold.points.length; i++) { worldManifold.points[i] = new Vector2(worldManifold2.points[i].x, worldManifold2.points[i].y); } return worldManifold; }
public static Array<Dummy> createDummies (int n) { float variance = 20; Array<Dummy> dummies = new Array<Dummy>(); for (int i = 0; i < n; i++) { Dummy d = new Dummy(); dummies.add(d); d.pos = new Vector2(); d.id = nextID++; } return dummies; }
/** Creates a new {@link OcclusionBuffer} * * @param width Width of the buffer image * @param height Height of the buffer image */ public OcclusionBuffer (int width, int height) { bufferWidth = width; bufferHeight = height; bufferHalfExt = new Vector2(width * 0.5f, height * 0.5f); bufferOffset = new Vector2(bufferHalfExt.x + 0.5f, bufferHalfExt.y + 0.5f); buffer = BufferUtils.newFloatBuffer(width * height); for (int i = 0; i < 8; i++) { box[i] = new Vector3(); tmpVertices[i] = new Quaternion(); clippedQuad[i] = new Quaternion(); } for (int i = 0; i < 4; i++) quad[i] = new Quaternion(); }
private Body createEdge (BodyType type, float x1, float y1, float x2, float y2, float density) { BodyDef def = new BodyDef(); def.type = type; Body box = world.createBody(def); EdgeShape poly = new EdgeShape(); poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1)); box.createFixture(poly, density); box.setTransform(x1, y1, 0); poly.dispose(); return box; }
@Override public void create () { world = new World(new Vector2(0, -40), true); renderer = new Box2DDebugRenderer(); cam = new OrthographicCamera(28, 20); createWorld(); Gdx.input.setInputProcessor(this); batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
@Override public boolean touchDown (int x, int y, int pointerId, int button) { cam.unproject(point.set(x, y, 0)); if (button == Input.Buttons.LEFT) { if (last == null) { last = new Vector2(point.x, point.y); } else { createEdge(BodyType.StaticBody, last.x, last.y, point.x, point.y, 0); last.set(point.x, point.y); } } else { last = null; } return false; }
public void create () { cam = new OrthographicCamera(48, 32); cam.position.set(0, 15, 0); renderer = new Box2DDebugRenderer(); world = new World(new Vector2(0, -10), true); Body body = world.createBody(new BodyDef()); CircleShape shape = new CircleShape(); shape.setRadius(1f); MassData mass = new MassData(); mass.mass = 1f; body.setMassData(mass); body.setFixedRotation(true); body.setType(BodyType.KinematicBody); body.createFixture(shape, 1); body.setBullet(true); body.setTransform(new Vector2(0, 0), body.getAngle()); body.setLinearVelocity(new Vector2(50f, 0)); }
@Test public void testLinear2D () { Vector2[] points = create(new Vector2[] {new Vector2(0, 0), new Vector2(1, 1)}); float len = bezier.approxLength(2); Assert.assertEquals(Math.sqrt(2), len, epsilonApprimations); Vector2 d = bezier.derivativeAt(new Vector2(), 0.5f); Assert.assertEquals(1, d.x, epsilon); Assert.assertEquals(1, d.y, epsilon); Vector2 v = bezier.valueAt(new Vector2(), 0.5f); Assert.assertEquals(0.5f, v.x, epsilon); Assert.assertEquals(0.5f, v.y, epsilon); float t = bezier.approximate(new Vector2(.5f, .5f)); Assert.assertEquals(.5f, t, epsilonApprimations); float l = bezier.locate(new Vector2(.5f, .5f)); Assert.assertEquals(.5f, t, epsilon); } }
@Test public void testToString () { assertEquals("(-5.0,42.00055)", new Vector2(-5f, 42.00055f).toString()); }
@Override public void create () { Gdx.input.setInputProcessor(this); texture = new Texture(Gdx.files.internal("data/animation.png")); TextureRegion[][] regions = TextureRegion.split(texture, 32, 48); TextureRegion[] downWalkReg = regions[0]; TextureRegion[] leftWalkReg = regions[1]; TextureRegion[] rightWalkReg = regions[2]; TextureRegion[] upWalkReg = regions[3]; downWalk = new Animation<TextureRegion>(ANIMATION_SPEED, downWalkReg); leftWalk = new Animation<TextureRegion>(ANIMATION_SPEED, leftWalkReg); rightWalk = new Animation<TextureRegion>(ANIMATION_SPEED, rightWalkReg); upWalk = new Animation<TextureRegion>(ANIMATION_SPEED, upWalkReg); currentWalk = leftWalk; currentFrameTime = 0.0f; spriteBatch = new SpriteBatch(); position = new Vector2(); }
private Body createPlayer () { BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.45f, 1.4f); playerPhysicsFixture = box.createFixture(poly, 1); poly.dispose(); CircleShape circle = new CircleShape(); circle.setRadius(0.45f); circle.setPosition(new Vector2(0, -1.4f)); playerSensorFixture = box.createFixture(circle, 0); circle.dispose(); box.setBullet(true); return box; }