List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double x, double y, double z)
From source file:org.hbird.business.archive.converters.Vector3DConverter.java
@Override public Vector3D convert(DBObject obj) { double x = (Double) obj.get("x"); double y = (Double) obj.get("y"); double z = (Double) obj.get("z"); return new Vector3D(x, y, z); }
From source file:org.josvaldor.prospero.energy.system.star.sun.Sun.java
public Sun() { this.name = "sun"; this.mass = 1.9891e30; this.radius = 6.96342e5; this.color = Color.YELLOW; this.position = new Vector3D(0, 0, 0); this.angularVelocity = 2.865329607243705e-06; }
From source file:org.josvaldor.prospero.energy.system.star.sun.Sun.java
public Sun(Calendar calendar) { this.name = "sun"; this.mass = 1.9891e30; this.radius = 6.96342e5; this.color = Color.YELLOW; this.position = new Vector3D(0, 0, 0); this.time = calendar; this.angularVelocity = 2.865329607243705e-06; // Sunspot sunspot = null; // for (String[] s : CSVParser.getData(dailySunspotFileName)) { // sunspot = new Sunspot(); // sunspot.setDaily(s); // this.dailySunspotList.add(sunspot); // }//from w w w. j av a 2 s .co m // for (String[] s : CSVParser.getData(monthlySunspotFileName)) { // sunspot = new Sunspot(); // sunspot.setMonthly(s); // this.monthlySunspotList.add(sunspot); // } // for (String[] s : CSVParser.getData(monthlySmoothedSunspotFileName)) { // sunspot = new Sunspot(); // sunspot.setMonthlySmoothed(s); // this.monthlySmoothedSunspotList.add(sunspot); // } }
From source file:org.jtrfp.trcl.beh.AdjustAltitudeToPlayerBehavior.java
public AdjustAltitudeToPlayerBehavior setAccelleration(int accelleration) { UP = new Vector3D(0, accelleration, 0); DOWN = new Vector3D(0, -accelleration, 0); return this; }
From source file:org.jtrfp.trcl.beh.AutoFiring.java
/** * Adapted from <a href='http://jaran.de/goodbits/2011/07/17/calculating-an-intercept-course-to-a-target-with-constant-direction-and-velocity-in-a-2-dimensional-plane/'>this article.</a> * @param targetPos//from www . j a v a 2 s.c o m * @param targetVel * @param attackPos * @param attackSpeed * @return * @since Feb 13, 2014 */ private static Vector3D interceptOf(final Vector3D targetPos, final Vector3D targetVel, final Vector3D attackPos, final double attackSpeed) { final double dX = targetPos.getX() - attackPos.getX(); final double dY = targetPos.getY() - attackPos.getY(); final double dZ = targetPos.getZ() - attackPos.getZ(); final double h1 = targetVel.getX() * targetVel.getX() + targetVel.getY() * targetVel.getY() + targetVel.getZ() * targetVel.getZ() - attackSpeed * attackSpeed; final double h2 = dX * targetVel.getX() + dY * targetVel.getY() + dZ * targetVel.getZ(); double t; if (h1 == 0) t = -(dX * dX + dY * dY + dZ * dZ) / 2 * h2; else { final double minusPHalf = -h2 / h1; final double disc = minusPHalf * minusPHalf - (dX * dX + dY * dY + dZ * dZ) / h1; if (disc < 0) return null; final double root = Math.sqrt(disc); final double t1 = minusPHalf + root; final double t2 = minusPHalf - root; final double tMin = Math.min(t1, t2); final double tMax = Math.max(t1, t2); t = tMin > 0 ? tMin : tMax; if (t < 0) return null; } //end else(calculate full) return new Vector3D(targetPos.getX() + t * targetVel.getX(), targetPos.getY() + t * targetVel.getY(), targetPos.getZ() + t * targetVel.getZ()); }
From source file:org.jtrfp.trcl.beh.AutoLeveling.java
@Override public void _tick(long timeInMillis) { final WorldObject parent = getParent(); final Vector3D oldHeading = parent.getHeading(); final Vector3D oldTop = parent.getTop(); final Vector3D oldCross = oldHeading.crossProduct(oldTop); final Vector3D newHeading = levelingAxis == LevelingAxis.HEADING ? new Vector3D( oldHeading.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0], oldHeading.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1], oldHeading.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2]) .normalize() : oldHeading.normalize();//from w ww . j a v a 2 s .c o m final Vector3D newTop = levelingAxis == LevelingAxis.TOP ? new Vector3D( oldTop.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0], oldTop.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1], oldTop.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2]).normalize() : oldTop.normalize(); final Vector3D newCross = levelingAxis == LevelingAxis.CROSS ? new Vector3D( oldCross.getX() * retainmentCoeff[0] + levelingVector.getX() * inverseRetainmentCoeff[0], oldCross.getY() * retainmentCoeff[1] + levelingVector.getY() * inverseRetainmentCoeff[1], oldCross.getZ() * retainmentCoeff[2] + levelingVector.getZ() * inverseRetainmentCoeff[2]) .normalize() : oldCross.normalize(); final Rotation topDelta = new Rotation(oldTop, newTop); final Rotation headingDelta = new Rotation(oldHeading, newHeading); final Rotation crossDelta = new Rotation(oldCross, newCross); parent.setHeading(crossDelta.applyTo(headingDelta.applyTo(topDelta.applyTo(oldHeading)))); parent.setTop(crossDelta.applyTo(headingDelta.applyTo(topDelta.applyTo(oldTop)))); }
From source file:org.jtrfp.trcl.beh.CollidesWithTerrain.java
@Override public void _tick(long tickTimeMillis) { if (tickCounter++ % 2 == 0 && !recentlyCollided) return;/*w w w. j av a 2 s. c om*/ recentlyCollided = false; final WorldObject p = getParent(); final TR tr = p.getTr(); final World world = tr.getWorld(); final InterpolatingAltitudeMap aMap; final Mission mission = tr.getGame().getCurrentMission(); try { aMap = mission.getOverworldSystem().getAltitudeMap(); } catch (NullPointerException e) { return; } if (mission.getOverworldSystem().isTunnelMode()) return;//No terrain to collide with while in tunnel mode. if (aMap == null) return; final double[] thisPos = p.getPosition(); final double groundHeightNorm = aMap.heightAt((thisPos[0] / TR.mapSquareSize), (thisPos[2] / TR.mapSquareSize)); final double groundHeight = groundHeightNorm * (world.sizeY / 2); final double ceilingHeight = (1.99 - aMap.heightAt((thisPos[0] / TR.mapSquareSize), (thisPos[2] / TR.mapSquareSize))) * (world.sizeY / 2) + CEILING_Y_NUDGE; final Vector3D groundNormal = (aMap.normalAt((thisPos[0] / TR.mapSquareSize), (thisPos[2] / TR.mapSquareSize))); Vector3D downhillDirectionXZ = new Vector3D(groundNormal.getX(), 0, groundNormal.getZ()); if (downhillDirectionXZ.getNorm() != 0) downhillDirectionXZ = downhillDirectionXZ.normalize(); else downhillDirectionXZ = Vector3D.PLUS_J; final OverworldSystem overworldSystem = tr.getGame().getCurrentMission().getOverworldSystem(); if (overworldSystem == null) return; final boolean terrainMirror = overworldSystem.isChamberMode(); final double thisY = thisPos[1]; boolean groundImpact = thisY < (groundHeight + (autoNudge ? nudgePadding : 0)); final boolean ceilingImpact = (thisY > ceilingHeight && terrainMirror && !ignoreCeiling); final Vector3D ceilingNormal = new Vector3D(groundNormal.getX(), -groundNormal.getY(), groundNormal.getZ()); Vector3D surfaceNormal = groundImpact ? groundNormal : ceilingNormal; final double dot = surfaceNormal.dotProduct(getParent().getHeading()); if (terrainMirror && groundHeightNorm > .97) { groundImpact = true; surfaceNormal = downhillDirectionXZ; } //end if(smushed between floor and ceiling) if (groundLock) { recentlyCollided = true; thisPos[1] = groundHeight; p.notifyPositionChange(); return; } //end if(groundLock) if (tunnelEntryCapable && groundImpact && dot < 0) { final OverworldSystem os = mission.getOverworldSystem(); if (!os.isTunnelMode()) { TunnelEntranceObject teo = mission.getTunnelEntranceObject( new Point((int) (thisPos[0] / TR.mapSquareSize), (int) (thisPos[2] / TR.mapSquareSize))); if (teo != null && !mission.isBossFight()) { mission.enterTunnel(teo.getSourceTunnel()); return; } } //end if(above ground) } //end if(tunnelEntryCapable()) if (groundImpact || ceilingImpact) {// detect collision recentlyCollided = true; double padding = autoNudge ? nudgePadding : 0; padding *= groundImpact ? 1 : -1; thisPos[1] = (groundImpact ? groundHeight : ceilingHeight) + padding; p.notifyPositionChange(); if (dot < 0 || ignoreHeadingForImpact) {//If toward ground, call impact listeners. surfaceNormalVar = surfaceNormal; final Behavior behavior = p.getBehavior(); behavior.probeForBehaviors(sub, SurfaceImpactListener.class); } //end if(pointedTowardGround) } // end if(collision) }
From source file:org.jtrfp.trcl.beh.DebrisOnDeathBehavior.java
@Override public void notifyDeath() { WorldObject p = getParent();/*from w ww . j av a 2 s . c om*/ final double maxVertexValue; final Model model = p.getModel(); if (model.getTriangleList() != null) maxVertexValue = model.getTriangleList().getMaximumVertexValue(); else if (model.getTransparentTriangleList() != null) maxVertexValue = model.getTransparentTriangleList().getMaximumVertexValue(); else return;//Give up for (int i = 0; i < MIN_FRAGS + maxVertexValue / 4000; i++) { final Vector3D oldPos = p.probeForBehavior(DeathBehavior.class).getLocationOfLastDeath(); p.getTr().getResourceManager().getDebrisSystem().spawn(oldPos, new Vector3D(Math.random() * MAX_SPEED - MAX_SPEED / 2., Math.random() * MAX_SPEED + 60000, Math.random() * MAX_SPEED - MAX_SPEED / 2.)); } //end for(NUM_FRAGS) }
From source file:org.jtrfp.trcl.beh.HeadingXAlwaysPositiveBehavior.java
@Override public void _tick(long tickTime) { final WorldObject p = getParent(); final Vector3D heading = p.getHeading(); if (heading.getX() < 0) { //Rotate 180 degrees on top axis p.setHeading(new Vector3D(0, heading.getY(), heading.getZ()).normalize()); final Vector3D horiz = p.getHeading().crossProduct(p.getTop()).normalize(); final Vector3D newTop = horiz.crossProduct(p.getHeading()).normalize(); p.setTop(newTop);/*from www .ja va 2 s .c o m*/ } }
From source file:org.jtrfp.trcl.beh.HorizAimAtPlayerBehavior.java
@Override public void _tick(long timeInMillis) { if (chaseTarget != null) { WorldObject thisObject = getParent(); final Player player = thisObject.getTr().getGame().getPlayer(); if (player.getBehavior().probeForBehavior(Cloakable.class).isCloaked()) return; final RotationalMomentumBehavior rmb = thisObject.getBehavior() .probeForBehavior(RotationalMomentumBehavior.class); assert !Vect3D.isAnyEqual(chaseTarget.getPosition(), Double.POSITIVE_INFINITY); assert !Vect3D.isAnyEqual(thisObject.getPosition(), Double.NEGATIVE_INFINITY); TR.twosComplimentSubtract(chaseTarget.getPosition(), thisObject.getPosition(), vectorToTargetVar); assert !Vect3D.isAnyNaN(vectorToTargetVar); assert !Vect3D.isAnyEqual(vectorToTargetVar, Double.POSITIVE_INFINITY); assert !Vect3D.isAnyEqual(vectorToTargetVar, Double.NEGATIVE_INFINITY); vectorToTargetVar[1] = 0;/*from ww w . jav a2s .c om*/ Vect3D.normalize(vectorToTargetVar, vectorToTargetVar); final Vector3D thisHeading = new Vector3D(thisObject.getHeading().getX(), 0, thisObject.getHeading().getZ()).normalize(); Vect3D.subtract(thisHeading.toArray(), vectorToTargetVar, headingVarianceDelta); if (Math.sqrt(headingVarianceDelta[2] * headingVarianceDelta[2] + headingVarianceDelta[0] * headingVarianceDelta[0]) < hysteresis) return; if (!reverse) Vect3D.negate(vectorToTargetVar); Rotation rot = new Rotation(new Vector3D(vectorToTargetVar), thisHeading); final Vector3D deltaVector = rot.applyTo(Vector3D.PLUS_K); if ((deltaVector.getZ() > 0 || deltaVector.getX() < 0) == leftHanded) { rmb.accellerateEquatorialMomentum(-equatorialAccelleration); } else { rmb.accellerateEquatorialMomentum(equatorialAccelleration); } } //end if(target!null) }