List of usage examples for com.badlogic.gdx.math Vector2 set
@Override
public Vector2 set(Vector2 v)
From source file:org.destinationsol.game.PathLoader.java
License:Apache License
private Vector2 newVec(Vector2 v) { Vector2 res = vectorPool.isEmpty() ? new Vector2() : vectorPool.remove(0); if (v != null) res.set(v); return res;//w ww . j a va 2 s . c o m }
From source file:org.destinationsol.game.planet.FlatPlaceFinder.java
License:Apache License
public Vector2 find(SolGame game, Planet p, ConsumedAngles takenAngles, float objHalfWidth) { Vector2 pPos = p.getPos();//from w ww . j a v a 2 s . c o m Vector2 res = new Vector2(pPos); float minDeviation = 90; float resAngle = 0; float objAngularHalfWidth = SolMath.angularWidthOfSphere(objHalfWidth, p.getGroundHeight()); for (int i = 0; i < 20; i++) { float angle = SolMath.rnd(180); if (takenAngles != null && takenAngles.isConsumed(angle, objAngularHalfWidth)) continue; myDeviation = angle; SolMath.fromAl(myVec, angle, p.getFullHeight()); myVec.add(pPos); game.getObjMan().getWorld().rayCast(myRayBack, myVec, pPos); if (myDeviation < minDeviation) { res.set(myVec); minDeviation = myDeviation; resAngle = angle; } } if (takenAngles != null) takenAngles.add(resAngle, objAngularHalfWidth); res.sub(pPos); SolMath.rotate(res, -p.getAngle()); return res; }
From source file:org.destinationsol.game.planet.Planet.java
License:Apache License
@Bound public Vector2 getAdjustedEffectSpd(Vector2 pos, Vector2 spd) { Vector2 r = SolMath.getVec(spd); if (myConfig.skyConfig == null) { return r; }//from w ww . j av a 2s . c om Vector2 up = SolMath.distVec(myPos, pos); float dst = up.len(); if (dst == 0 || getFullHeight() < dst) { SolMath.free(up); return r; } float smokeConst = 1.2f * myGravConst; if (dst < myGroundHeight) { up.scl(smokeConst / dst / myGroundHeight / myGroundHeight); r.set(up); SolMath.free(up); return r; } float spdPerc = (dst - myGroundHeight) / Const.ATM_HEIGHT; r.scl(spdPerc); up.scl(smokeConst / dst / dst / dst); r.add(up); SolMath.free(up); return r; }
From source file:org.destinationsol.game.planet.PlanetObjectsBuilder.java
License:Apache License
private void addDeco0(SolGame game, float groundHeight, Vector2 planetPos, Map<Vector2, List<Dra>> collector, DecoConfig dc) {//from w ww . j ava2s . c om World w = game.getObjMan().getWorld(); ConsumedAngles consumed = new ConsumedAngles(); final Vector2 rayCasted = new Vector2(); RayCastCallback rcc = new RayCastCallback() { @Override public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (!(fixture.getBody().getUserData() instanceof TileObject)) { return -1; } rayCasted.set(point); return fraction; } }; int decoCount = (int) (2 * SolMath.PI * groundHeight * dc.density); for (int i = 0; i < decoCount; i++) { float decoSz = SolMath.rnd(dc.szMin, dc.szMax); float angularHalfWidth = SolMath.angularWidthOfSphere(decoSz / 2, groundHeight); float decoAngle = 0; for (int j = 0; j < 5; j++) { decoAngle = SolMath.rnd(180); if (!consumed.isConsumed(decoAngle, angularHalfWidth)) { consumed.add(decoAngle, angularHalfWidth); break; } } SolMath.fromAl(rayCasted, decoAngle, groundHeight, true); rayCasted.add(planetPos); w.rayCast(rcc, rayCasted, planetPos); float decoDist = rayCasted.dst(planetPos); float baseAngle = SolMath.windowCenter(decoAngle, DECO_PACK_ANGULAR_WIDTH); float baseDist = SolMath.windowCenter(decoDist, DECO_PACK_SZ); Vector2 basePos = SolMath.fromAl(baseAngle, baseDist).add(planetPos); Vector2 decoRelPos = new Vector2(rayCasted).sub(basePos); SolMath.rotate(decoRelPos, -baseAngle - 90, true); float decoRelAngle = decoAngle - baseAngle; TextureAtlas.AtlasRegion decoTex = SolMath.elemRnd(dc.texs); if (dc.allowFlip && SolMath.test(.5f)) decoTex = game.getTexMan().getFlipped(decoTex); RectSprite s = new RectSprite(decoTex, decoSz, dc.orig.x, dc.orig.y, decoRelPos, DraLevel.DECO, decoRelAngle, 0, SolColor.W, false); List<Dra> ss = collector.get(basePos); if (ss == null) { ss = new ArrayList<Dra>(); collector.put(new Vector2(basePos), ss); } ss.add(s); SolMath.free(basePos); } }