List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D getZ
public double getZ()
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 a2 s . com*/ 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.CubeCollisionBehavior.java
public CubeCollisionBehavior(WorldObject wo) { super();//from ww w .ja va 2s .c o m Vector3D max = wo.getModel().getTriangleList().getMaximumVertexDims(); Vector3D min = wo.getModel().getTriangleList().getMinimumVertexDims(); origin = new double[] { (max.getX() + min.getX()) / 2., (max.getY() + min.getY()) / 2., (max.getZ() + min.getZ()) / 2. }; dims = new double[] { max.getX() - min.getX(), max.getY() - min.getY(), max.getZ() - min.getZ() }; }
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 w w w .ja va 2 s . c om } }
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 w w w. j av a 2 s. com*/ 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) }
From source file:org.jtrfp.trcl.beh.phy.ShiftingObjectBehavior.java
public ShiftingObjectBehavior(int totalShiftPeriodMsec, Vector3D startPos, Vector3D endPos) { seq = new Sequencer(totalShiftPeriodMsec, 2, true); xAnimator = new AttribAnimator(xPos, seq, new double[] { startPos.getX(), endPos.getX() }); yAnimator = new AttribAnimator(yPos, seq, new double[] { startPos.getY(), endPos.getY() }); zAnimator = new AttribAnimator(zPos, seq, new double[] { startPos.getZ(), endPos.getZ() }); }
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();//from ww w . j a v a2 s . 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.Camera.java
/** * @param lookAtVector the lookAtVector to set */// www . java 2 s.c o m public synchronized void setLookAtVector(Vector3D lookAtVector) { double[] heading = super.getHeadingArray(); heading[0] = lookAtVector.getX(); heading[1] = lookAtVector.getY(); heading[2] = lookAtVector.getZ(); //cameraMatrix=null; }
From source file:org.jtrfp.trcl.Camera.java
/** * @param cameraPosition/* w ww . ja v a 2s. c o m*/ * the cameraPosition to set */ public void setPosition(Vector3D cameraPosition) { this.setPosition(cameraPosition.getX(), cameraPosition.getY(), cameraPosition.getZ()); }
From source file:org.jtrfp.trcl.Camera.java
private RealMatrix applyMatrix() { try {//from ww w . ja va2 s . c o m Vector3D eyeLoc = getCameraPosition(); Vector3D aZ = getLookAtVector().negate(); Vector3D aX = getUpVector().crossProduct(aZ).normalize(); Vector3D aY = getUpVector(); rotationMatrix = new Array2DRowRealMatrix( new double[][] { new double[] { aX.getX(), aX.getY(), aX.getZ(), 0 }, new double[] { aY.getX(), aY.getY(), aY.getZ(), 0 }, new double[] { aZ.getX(), aZ.getY(), aZ.getZ(), 0 }, new double[] { 0, 0, 0, 1 } }); RealMatrix tM = new Array2DRowRealMatrix(new double[][] { new double[] { 1, 0, 0, -eyeLoc.getX() }, new double[] { 0, 1, 0, -eyeLoc.getY() }, new double[] { 0, 0, 1, -eyeLoc.getZ() }, new double[] { 0, 0, 0, 1 } }); return completeMatrix = getProjectionMatrix().multiply(rotationMatrix.multiply(tM)); } catch (MathArithmeticException e) { } //Don't crash. return completeMatrix; }