List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D Vector3D
public Vector3D(double[] v) throws DimensionMismatchException
From source file:org.jtrfp.trcl.beh.phy.BouncesOffSurfaces.java
@Override public void collidedWithSurface(WorldObject wo, double[] surfaceNormal) { final WorldObject parent = getParent(); final Vector3D oldHeading = parent.getHeading(); final Vector3D oldTop = parent.getTop(); final Vector3D _surfaceNormal = new Vector3D(surfaceNormal); if (oldHeading == null) throw new NullPointerException("Parent heading is null."); if (surfaceNormal == null) throw new NullPointerException("Surface normal is null."); if (reflectHeading && new Rotation(oldHeading, _surfaceNormal).getAngle() > Math.PI / 2.) { Vector3D newHeading = (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldHeading) * -2) .add(oldHeading));//from w w w .j ava 2 s. co m parent.setHeading(newHeading); final Rotation resultingRotation = new Rotation(oldHeading, newHeading); Vector3D newTop = resultingRotation.applyTo(oldTop); //if(newTop.getY()<0)newTop=newTop.negate(); parent.setTop(newTop); } //end if(should reflect) //if(parent instanceof Velocible){ final Velocible velocible = (Velocible) parent.probeForBehavior(Velocible.class); Vector3D oldVelocity = velocible.getVelocity(); if (oldVelocity.getNorm() == 0) oldVelocity = Vector3D.PLUS_I; if (new Rotation(oldVelocity.normalize(), _surfaceNormal).getAngle() > Math.PI / 2.) { velocible.setVelocity( (_surfaceNormal.scalarMultiply(_surfaceNormal.dotProduct(oldVelocity) * -2).add(oldVelocity)) .scalarMultiply(velocityRetainmentCoefficient)); //Nudge parent.setPosition( new Vector3D(parent.getPosition()).add(_surfaceNormal.scalarMultiply(1000.)).toArray()); } //end if(should bounce) //}//end if(Velocible) }
From source file:org.jtrfp.trcl.beh.ProjectileBehavior.java
public void reset(Vector3D heading, double speed) { this.speed = speed; honingTarget = null;/*from w w w .j a v a 2s. c o m*/ final WorldObject parent = getParent(); final Behavior beh = parent.getBehavior(); parent.setHeading(heading); if (honing) { // Find target WorldObject closestObject = null; double closestDistance = Double.POSITIVE_INFINITY; List<WorldObject> possibleTargets = getParent().getTr().getCollisionManager() .getCurrentlyActiveCollisionList(); synchronized (possibleTargets) { for (WorldObject possibleTarget : possibleTargets) { if (possibleTarget instanceof DEFObject) { DEFObject possibleDEFTarget = (DEFObject) possibleTarget; if (!possibleDEFTarget.isIgnoringProjectiles() && !possibleDEFTarget.isRuin()) { final Vector3D targetPos = new Vector3D(possibleTarget.getPositionWithOffset()); final Vector3D delta = targetPos.subtract(new Vector3D(getParent().getPosition())); final double dist = delta.getNorm(); final Vector3D proposedHeading = delta.normalize(); final Vector3D headingDelta = getParent().getHeading().subtract(proposedHeading); final double compositeHeadingDelta = headingDelta.getNorm(); if (compositeHeadingDelta < .5) { final double compositeDistance = dist; if (compositeDistance < closestDistance) { closestDistance = dist; closestObject = possibleTarget; parent.setHeading(proposedHeading); getParent().getBehavior().probeForBehavior(AutoLeveling.class) .setLevelingVector(heading); } // end if(closesObject) } // end if(headingDelta<1) } // end if(isIgnoringProjectiles) } // end if(DEFObject) } } // end for(WorldObject others) honingTarget = new WeakReference<WorldObject>(closestObject); // if(honingTarget==null){ getParent().getBehavior().probeForBehavior(AutoLeveling.class).setLevelingVector(heading); movesByVelocity.setVelocity(getParent().getHeading().scalarMultiply(speed)); // }//end if(honingTarget==null) } // end if(honingTarget) beh.probeForBehavior(LimitedLifeSpan.class).reset(LIFESPAN_MILLIS); beh.probeForBehavior(DeathBehavior.class).reset(); }
From source file:org.jtrfp.trcl.beh.ProjectileBehavior.java
@Override public void _tick(long tickTimeMillis) { if (honingTarget != null) { if (honingTarget.get() == null) return; if (honingAdjustmentUpdate++ % 5 == 0) { if (!honingTarget.get().isVisible()) return;// Dead or otherwise. final Vector3D honingVector = new Vector3D(honingTarget.get().getPositionWithOffset()) .subtract(new Vector3D(getParent().getPosition())).normalize(); //Sanity check if (Double.isNaN(honingVector.getX())) return; if (Double.isNaN(honingVector.getY())) return; if (Double.isNaN(honingVector.getZ())) return; getParent().getBehavior().probeForBehavior(AutoLeveling.class).setLevelingVector(honingVector); movesByVelocity.setVelocity(getParent().getHeading().scalarMultiply(speed)); } // end if(updateHoningVector) } // end if(honingTarget) }
From source file:org.jtrfp.trcl.beh.RollLevelingBehavior.java
@Override public void _tick(long tickTimeMillis) { WorldObject p = getParent();//w w w . j av a 2s.c o m final double[] initHdng = p.getHeadingArray(); final double[] initTop = p.getTopArray(); //Escape on invalid cases if (initHdng[1] <= -1) return; if (initHdng[1] >= 1) return; if (initTop[1] == 0) return; //Create an imaginary heading/top where heading.y=0 imgHdng[0] = initHdng[0]; imgHdng[1] = 0; imgHdng[2] = initHdng[2]; Vect3D.normalize(imgHdng, imgHdng); //Create a rotation to convert back later after performing the roll adjustment. Rotation rot = new Rotation(new Vector3D(initHdng), new Vector3D(imgHdng)); Vector3D imgTop = rot.applyTo(new Vector3D(initTop)).normalize(); double topY = imgTop.getY(); if (topY == 0) return; //Retainment softener prevents gimbal swing effect when facing up or down. final double retainmentSoftener = Misc.clamp(Math.abs(initHdng[1]), 0, 1); final double softenedRetainment = retainment * (1. - retainmentSoftener) + retainmentSoftener; //Perform the roll adjustment using weighting supplied by softenedRetainer if (topY > 0) {//Rightside up, approach 1. topY = topY * softenedRetainment + 1 * (1. - softenedRetainment); } else {//Upside down, approach -1 topY = topY * softenedRetainment + -1 * (1. - softenedRetainment); } Vector3D newTop = rot.applyInverseTo(new Vector3D(imgTop.getX(), topY, imgTop.getZ()).normalize()); //Apply. This will automatically notify change. No need to change heading as it is intrinsically the same. p.setTop(newTop); }
From source file:org.jtrfp.trcl.beh.SpawnsRandomSmoke.java
@Override public void _tick(long timeMillis) { if (Math.random() < .6) { Vector3D pos = new Vector3D(getParent().getPositionWithOffset()); Smokes.triggerSmoke(pos.add(new Vector3D(Math.random() * 2000 - 1000, 0, Math.random() * 2000 - 1000)), SmokeType.Puff);/*from w w w . j a v a2s . c om*/ } }
From source file:org.jtrfp.trcl.beh.SurfaceImpactSFXBehavior.java
@Override public void collidedWithSurface(WorldObject src, double[] surfaceNormal) { final double collDot = Math .abs(getParent().getHeading().normalize().dotProduct(new Vector3D(surfaceNormal).normalize())); System.err.println("Surface collision detected " + collDot); if (System.currentTimeMillis() < timeOfLastSFXMillis + 500) return;//from w ww . j a v a 2s. co m timeOfLastSFXMillis = System.currentTimeMillis(); if (src instanceof TerrainChunk) { //Calculate if this impact is severe or glazing if (collDot < .6) { ss.enqueuePlaybackEvent(ss.getPlaybackFactory().create(rm.soundTextures.get("GROUND.WAV"), VOLUME)); } else {//Hard crash //Boom ss.enqueuePlaybackEvent(ss.getPlaybackFactory() .create(rm.soundTextures.get(CRASH_SOUNDS[(int) (Math.random() * 2)]), VOLUME)); } //end hard Crash } //end terrain else if (src instanceof TunnelSegment) { //Shearing noise ss.enqueuePlaybackEvent(ss.getPlaybackFactory().create(rm.soundTextures.get("SCRAPE.WAV"), VOLUME)); ss.enqueuePlaybackEvent(ss.getPlaybackFactory() .create(rm.soundTextures.get(CRASH_SOUNDS[(int) (Math.random() * 2)]), VOLUME)); } //end if(TunnelSegment) }
From source file:org.jtrfp.trcl.Camera.java
/** * @return the cameraPosition */ public Vector3D getCameraPosition() { return new Vector3D(super.getPosition()); }
From source file:org.jtrfp.trcl.flow.Mission.java
/** * Find a tunnel at the given map square, if any. * @param mapSquareXZ Position in cells, not world coords. * @return The Tunnel at this map square, or null if none here. * @since Jan 13, 2015//from w w w. ja va 2 s .co m */ public TunnelEntranceObject getTunnelEntranceObject(Point mapSquareXZ) { final int key = pointToHash(mapSquareXZ); System.out.println("getTunnelEntranceObject " + mapSquareXZ); for (TunnelEntranceObject teo : tunnelMap.values()) System.out.print(" " + new Vector3D(teo.getPosition()).scalarMultiply(1 / TR.mapSquareSize)); System.out.println(); return tunnelMap.get(key); }
From source file:org.jtrfp.trcl.flow.Mission.java
public void setSatelliteView(boolean satelliteView) { if (!(getMissionMode() instanceof AboveGroundMode) && satelliteView) throw new IllegalArgumentException("Cannot activate satellite view while mission mode is " + getMissionMode().getClass().getSimpleName()); if (satelliteView && tr.getGame().isPaused()) throw new IllegalArgumentException("Cannot activate satellite view while paused."); pcs.firePropertyChange(SATELLITE_VIEW, this.satelliteView, satelliteView); if (satelliteView != this.satelliteView) { final Game game = tr.getGame(); final Camera cam = tr.mainRenderer.get().getCamera(); if (satelliteView) {//Switched on tr.getThreadManager().setPaused(true); game.getNavSystem().deactivate(); game.getHUDSystem().deactivate(); cam.setFogEnabled(false);/* w w w .j av a 2s . c o m*/ cam.probeForBehavior(MatchPosition.class).setEnable(false); cam.probeForBehavior(MatchDirection.class).setEnable(false); final Vector3D pPos = new Vector3D(game.getPlayer().getPosition()); final Vector3D pHeading = tr.getGame().getPlayer().getHeading(); cam.setPosition(new Vector3D(pPos.getX(), TR.mapSquareSize * 25, pPos.getZ())); cam.setHeading(Vector3D.MINUS_J); cam.setTop(new Vector3D(pHeading.getX(), .0000000001, pHeading.getZ()).normalize()); tr.getGame().getSatDashboard().setVisible(true); } else {//Switched off tr.getThreadManager().setPaused(false); tr.getGame().getNavSystem().activate(); game.getHUDSystem().activate(); cam.setFogEnabled(true); cam.probeForBehavior(MatchPosition.class).setEnable(true); cam.probeForBehavior(MatchDirection.class).setEnable(true); tr.getGame().getSatDashboard().setVisible(false); } //end !satelliteView } //end if(change) this.satelliteView = satelliteView; }
From source file:org.jtrfp.trcl.obj.ExplosionSystem.java
private boolean isNewExplosionFeasible(final Vector3D loc, ExplosionType type) { final TreeSet<Explosion> proximalExplosions = new TreeSet<Explosion>(new Comparator<Explosion>() { @Override/*from w ww.jav a 2s. co m*/ public int compare(Explosion o1, Explosion o2) { return Misc.satCastInt(o1.getTimeOfLastReset() - o2.getTimeOfLastReset()); } }); for (int explosionTypeIndex = 0; explosionTypeIndex < allExplosions.length; explosionTypeIndex++) { Explosion[] explosionsOfThisType = allExplosions[explosionTypeIndex]; for (Explosion thisExplosion : explosionsOfThisType) { if (thisExplosion.isActive()) { final double distance = new Vector3D(thisExplosion.getPosition()).distance(loc); if (distance < 1000) return false; if (distance < OneShotBillboardEvent.PROXIMITY_TEST_DIST) proximalExplosions.add(thisExplosion); } // end if(isActive) } // end for(explosionsOfThisType) } // end for(explosions) if (proximalExplosions.size() + 1 > OneShotBillboardEvent.MAX_PROXIMAL_EVENTS) proximalExplosions.first().destroy();//Destroy oldest return true; }