List of usage examples for org.apache.commons.math3.geometry.euclidean.threed Vector3D MINUS_J
Vector3D MINUS_J
To view the source code for org.apache.commons.math3.geometry.euclidean.threed Vector3D MINUS_J.
Click Source Link
From source file:jtrace.object.Cube.java
/** * Create cube with unit side./* w ww .java 2s . c o m*/ */ public Cube() { super(); normals = new Ray[6]; for (int i = 0; i < 6; i++) normals[i] = new Ray(); normals[0].origin = new Vector3D(0.5, Vector3D.PLUS_I); normals[1].origin = new Vector3D(0.5, Vector3D.MINUS_I); normals[2].origin = new Vector3D(0.5, Vector3D.PLUS_J); normals[3].origin = new Vector3D(0.5, Vector3D.MINUS_J); normals[4].origin = new Vector3D(0.5, Vector3D.PLUS_K); normals[5].origin = new Vector3D(0.5, Vector3D.MINUS_K); normals[0].direction = Vector3D.PLUS_I; normals[1].direction = Vector3D.MINUS_I; normals[2].direction = Vector3D.PLUS_J; normals[3].direction = Vector3D.MINUS_J; normals[4].direction = Vector3D.PLUS_K; normals[5].direction = Vector3D.MINUS_K; }
From source file:fr.cs.examples.attitude.EarthObservation_day_night_switch_with_spinned_transitions.java
/** Program entry point. * @param args program arguments (unused here) *///from w ww.ja v a 2s. c om public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); final SortedSet<String> output = new TreeSet<String>(); //---------------------------------------- // Initial state definition : date, orbit //---------------------------------------- final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 02, 00, 00, 00.000, TimeScalesFactory.getUTC()); final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680); final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231); final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU); //------------------------------ // Attitudes sequence definition //------------------------------ final AttitudesSequence attitudesSequence = new AttitudesSequence(); // Attitude laws definition final double settingRate = FastMath.toRadians(1.0); final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0); final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH); final AttitudeProvider transitionLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), 0, 0); final AttitudeProvider rollSetUpLaw = new SpinStabilized(nightRestingLaw, AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_I, settingRate); final AttitudeProvider pitchSetUpLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, settingRate); final AttitudeProvider pitchTearDownLaw = new SpinStabilized(dayObservationLaw, AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_J, -settingRate); final AttitudeProvider rollTearDownLaw = new SpinStabilized(transitionLaw, AbsoluteDate.J2000_EPOCH, Vector3D.PLUS_I, -settingRate); // Event detectors definition //--------------------------- final PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth(); // Detectors : end day-night rdv 2 final DateDetector endDayNightRdV2Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-2 night-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endDayNightRdV2Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to night law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-2 night-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end day-night rdv 1 final DateDetector endDayNightRdV1Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to day-night rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-1 day-night-rdv2-mode"); endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20)); endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endDayNightRdV1Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day-night rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-1 day-night-rdv2-mode"); endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20)); endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detector : eclipse entry final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() { public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day-night rdv 1 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " eclipse-entry day-night-rdv1-mode"); endDayNightRdV1Event_increase.addEventDate(s.getDate().shiftedBy(40)); endDayNightRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end night-day rdv 2 final DateDetector endNightDayRdV2Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to day law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-2 day-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endNightDayRdV2Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-2 day-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end night-day rdv 1 final DateDetector endNightDayRdV1Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night-day rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-1 night-day-rdv2-mode"); endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40)); endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endNightDayRdV1Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to night-day rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-1 night-day-rdv2-mode"); endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40)); endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detector : eclipse exit final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() { public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night-day rdv 1 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " eclipse-exit night-day-rdv1-mode"); endNightDayRdV1Event_increase.addEventDate(s.getDate().shiftedBy(20)); endNightDayRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) { return oldState; } }); // Attitude sequences definition //------------------------------ attitudesSequence.addSwitchingCondition(dayObservationLaw, dayNightEvent, false, true, pitchTearDownLaw); attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_increase, true, false, rollTearDownLaw); attitudesSequence.addSwitchingCondition(pitchTearDownLaw, endDayNightRdV1Event_decrease, false, true, rollTearDownLaw); attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_increase, true, false, nightRestingLaw); attitudesSequence.addSwitchingCondition(rollTearDownLaw, endDayNightRdV2Event_decrease, false, true, nightRestingLaw); attitudesSequence.addSwitchingCondition(nightRestingLaw, nightDayEvent, true, false, rollSetUpLaw); attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_increase, true, false, pitchSetUpLaw); attitudesSequence.addSwitchingCondition(rollSetUpLaw, endNightDayRdV1Event_decrease, false, true, pitchSetUpLaw); attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_increase, true, false, dayObservationLaw); attitudesSequence.addSwitchingCondition(pitchSetUpLaw, endNightDayRdV2Event_decrease, false, true, dayObservationLaw); // Initialisation //--------------- if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) { // initial position is in daytime attitudesSequence.resetActiveProvider(dayObservationLaw); System.out .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " begin with day law"); } else { // initial position is in nighttime attitudesSequence.resetActiveProvider(nightRestingLaw); System.out .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " begin with night law"); } //---------------------- // Propagator definition //---------------------- // Propagator : consider the analytical Eckstein-Hechler model final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60); // Register the switching events to the propagator attitudesSequence.registerSwitchEvents(propagator); propagator.setMasterMode(10.0, new OrekitFixedStepHandler() { private DecimalFormat f1 = new DecimalFormat("0.0000000000000000E00", new DecimalFormatSymbols(Locale.US)); private Vector3DFormat f2 = new Vector3DFormat(" ", " ", " ", f1); private PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); private PVCoordinatesProvider moon = CelestialBodyFactory.getMoon(); private Frame eme2000 = FramesFactory.getEME2000(); private Frame itrf2005 = FramesFactory.getITRF(IERSConventions.IERS_2010, true); private String printVector3D(final String name, final Vector3D v) { return name + " " + f2.format(v); } private String printRotation(final String name, final Rotation r) { return name + " " + f1.format(r.getQ1()) + " " + f1.format(r.getQ2()) + " " + f1.format(r.getQ3()) + " " + f1.format(r.getQ0()); } private String printRotation2(final String name, final Rotation r) { return name + " " + f1.format(-r.getQ1()) + " " + f1.format(-r.getQ2()) + " " + f1.format(-r.getQ3()) + " " + f1.format(-r.getQ0()); } public void init(final SpacecraftState s0, final AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException { try { // the Earth position in spacecraft should be along spacecraft Z axis // during nigthtime and away from it during daytime due to roll and pitch offsets final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO); final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K); // the g function is the eclipse indicator, its an angle between Sun and Earth limb, // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb final double eclipseAngle = dayNightEvent.g(currentState); final double endNightDayTimer1 = endNightDayRdV1Event_decrease.g(currentState); final double endNightDayTimer2 = endNightDayRdV2Event_decrease.g(currentState); final double endDayNightTimer1 = endDayNightRdV1Event_decrease.g(currentState); final double endDayNightTimer2 = endDayNightRdV2Event_decrease.g(currentState); output.add(currentState.getDate() + " " + FastMath.toDegrees(eclipseAngle) + " " + endNightDayTimer1 + " " + endNightDayTimer2 + " " + endDayNightTimer1 + " " + endDayNightTimer2 + " " + FastMath.toDegrees(pointingOffset)); final AbsoluteDate date = currentState.getDate(); final PVCoordinates pv = currentState.getPVCoordinates(eme2000); final Rotation lvlhRot = new Rotation(pv.getPosition(), pv.getMomentum(), Vector3D.MINUS_K, Vector3D.MINUS_J); final Rotation earthRot = eme2000.getTransformTo(itrf2005, date).getRotation(); System.out.println("Scenario::setVectorMap 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " " + printVector3D("sun", sun.getPVCoordinates(date, eme2000).getPosition()) + " " + printVector3D("moon", moon.getPVCoordinates(date, eme2000).getPosition()) + " " + printVector3D("satPos", pv.getPosition()) + " " + printVector3D("satVel", pv.getVelocity()) + " " + printVector3D("orbMom", pv.getMomentum())); System.out.println("Scenario::setQuatMap 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " " + printRotation("earthFrame", earthRot) + " " + printRotation("LVLHFrame", lvlhRot)); System.out.println("Scenario::computeStep 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)); System.out.println(" -> " + printRotation2("", currentState.getAttitude().getRotation()) + " " + printVector3D("", currentState.getAttitude().getSpin())); } catch (OrekitException oe) { throw new PropagationException(oe); } } }); //---------- // Propagate //---------- // Propagate from the initial date for the fixed duration propagator.propagate(initialDate.shiftedBy(1.75 * 3600.)); //-------------- // Print results //-------------- // we print the lines according to lexicographic order, which is chronological order here // to make sure out of orders calls between step handler and event handlers don't mess things up for (final String line : output) { System.out.println(line); } } catch (OrekitException oe) { System.err.println(oe.getMessage()); } }
From source file:fr.cs.examples.attitude.EarthObservation_day_night_switch_with_fixed_transitions.java
/** Program entry point. * @param args program arguments (unused here) */// ww w . ja v a 2 s . c om public static void main(String[] args) { try { // configure Orekit Autoconfiguration.configureOrekit(); final SortedSet<String> output = new TreeSet<String>(); //---------------------------------------- // Initial state definition : date, orbit //---------------------------------------- final AbsoluteDate initialDate = new AbsoluteDate(2004, 01, 02, 00, 00, 00.000, TimeScalesFactory.getUTC()); final Vector3D position = new Vector3D(-6142438.668, 3492467.560, -25767.25680); final Vector3D velocity = new Vector3D(505.8479685, 942.7809215, 7435.922231); final Orbit initialOrbit = new KeplerianOrbit(new PVCoordinates(position, velocity), FramesFactory.getEME2000(), initialDate, Constants.EIGEN5C_EARTH_MU); //------------------------------ // Attitudes sequence definition //------------------------------ final AttitudesSequence attitudesSequence = new AttitudesSequence(); // Attitude laws definition //------------------------- // Mode : day final AttitudeProvider dayObservationLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(40), 0); // Mode : night final AttitudeProvider nightRestingLaw = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH); // Mode : day-night rdv 1 final AttitudeProvider dayNightRdV1Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(20), 0); // Mode : day-night rdv 2 final AttitudeProvider dayNightRdV2Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), 0, 0); // Mode : night-day rdv 1 final AttitudeProvider nightDayRdV1Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), 0, 0); // Mode : night-day rdv 2 final AttitudeProvider nightDayRdV2Law = new LofOffset(initialOrbit.getFrame(), LOFType.VVLH, RotationOrder.XYZ, FastMath.toRadians(20), FastMath.toRadians(20), 0); // Event detectors definition //--------------------------- final PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); final PVCoordinatesProvider earth = CelestialBodyFactory.getEarth(); // Detectors : end day-night rdv 2 final DateDetector endDayNightRdV2Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-2 night-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endDayNightRdV2Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to night law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-2 night-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end day-night rdv 1 final DateDetector endDayNightRdV1Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to day-night rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-1 day-night-rdv2-mode"); endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20)); endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endDayNightRdV1Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day-night rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-day-night-1 day-night-rdv2-mode"); endDayNightRdV2Event_increase.addEventDate(s.getDate().shiftedBy(20)); endDayNightRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detector : eclipse entry final EventDetector dayNightEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() { public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day-night rdv 1 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " eclipse-entry day-night-rdv1-mode"); endDayNightRdV1Event_increase.addEventDate(s.getDate().shiftedBy(40)); endDayNightRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end night-day rdv 2 final DateDetector endNightDayRdV2Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to day law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-2 day-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endNightDayRdV2Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to day law"); System.out.println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-2 day-mode"); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detectors : end night-day rdv 1 final DateDetector endNightDayRdV1Event_increase = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night-day rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-1 night-day-rdv2-mode"); endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40)); endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); final DateDetector endNightDayRdV1Event_decrease = new DateDetector(10, 1e-04) .withHandler(new EventHandler<DateDetector>() { public Action eventOccurred(final SpacecraftState s, final DateDetector detector, final boolean increasing) { if (!increasing) { output.add(s.getDate() + ": switching to night-day rdv 2 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " end-night-day-1 night-day-rdv2-mode"); endNightDayRdV2Event_increase.addEventDate(s.getDate().shiftedBy(40)); endNightDayRdV2Event_decrease.addEventDate(s.getDate().shiftedBy(40)); } return Action.CONTINUE; } public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) { return oldState; } }); // Detector : eclipse exit final EventDetector nightDayEvent = new EclipseDetector(sun, 696000000., earth, Constants.WGS84_EARTH_EQUATORIAL_RADIUS).withHandler(new EventHandler<EclipseDetector>() { public Action eventOccurred(final SpacecraftState s, final EclipseDetector detector, final boolean increasing) { if (increasing) { output.add(s.getDate() + ": switching to night-day rdv 1 law"); System.out .println("# " + (s.getDate().durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " eclipse-exit night-day-rdv1-mode"); endNightDayRdV1Event_increase.addEventDate(s.getDate().shiftedBy(20)); endNightDayRdV1Event_decrease.addEventDate(s.getDate().shiftedBy(20)); } return Action.CONTINUE; } public SpacecraftState resetState(EclipseDetector detector, SpacecraftState oldState) { return oldState; } }); // Attitude sequences definition //------------------------------ attitudesSequence.addSwitchingCondition(dayObservationLaw, dayNightEvent, false, true, dayNightRdV1Law); attitudesSequence.addSwitchingCondition(dayNightRdV1Law, endDayNightRdV1Event_increase, true, false, dayNightRdV2Law); attitudesSequence.addSwitchingCondition(dayNightRdV1Law, endDayNightRdV1Event_decrease, false, true, dayNightRdV2Law); attitudesSequence.addSwitchingCondition(dayNightRdV2Law, endDayNightRdV2Event_increase, true, false, nightRestingLaw); attitudesSequence.addSwitchingCondition(dayNightRdV2Law, endDayNightRdV2Event_decrease, false, true, nightRestingLaw); attitudesSequence.addSwitchingCondition(nightRestingLaw, nightDayEvent, true, false, nightDayRdV1Law); attitudesSequence.addSwitchingCondition(nightDayRdV1Law, endNightDayRdV1Event_increase, true, false, nightDayRdV2Law); attitudesSequence.addSwitchingCondition(nightDayRdV1Law, endNightDayRdV1Event_decrease, false, true, nightDayRdV2Law); attitudesSequence.addSwitchingCondition(nightDayRdV2Law, endNightDayRdV2Event_increase, true, false, dayObservationLaw); attitudesSequence.addSwitchingCondition(nightDayRdV2Law, endNightDayRdV2Event_decrease, false, true, dayObservationLaw); // Initialisation //--------------- if (dayNightEvent.g(new SpacecraftState(initialOrbit)) >= 0) { // initial position is in daytime attitudesSequence.resetActiveProvider(dayObservationLaw); System.out .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " begin with day law"); } else { // initial position is in nighttime attitudesSequence.resetActiveProvider(nightRestingLaw); System.out .println("# " + (initialDate.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " begin with night law"); } //---------------------- // Propagator definition //---------------------- // Propagator : consider the analytical Eckstein-Hechler model final Propagator propagator = new EcksteinHechlerPropagator(initialOrbit, attitudesSequence, Constants.EIGEN5C_EARTH_EQUATORIAL_RADIUS, Constants.EIGEN5C_EARTH_MU, Constants.EIGEN5C_EARTH_C20, Constants.EIGEN5C_EARTH_C30, Constants.EIGEN5C_EARTH_C40, Constants.EIGEN5C_EARTH_C50, Constants.EIGEN5C_EARTH_C60); // Register the switching events to the propagator attitudesSequence.registerSwitchEvents(propagator); propagator.setMasterMode(10.0, new OrekitFixedStepHandler() { private DecimalFormat f1 = new DecimalFormat("0.0000000000000000E00", new DecimalFormatSymbols(Locale.US)); private Vector3DFormat f2 = new Vector3DFormat(" ", " ", " ", f1); private PVCoordinatesProvider sun = CelestialBodyFactory.getSun(); private PVCoordinatesProvider moon = CelestialBodyFactory.getMoon(); private Frame eme2000 = FramesFactory.getEME2000(); private Frame itrf2005 = FramesFactory.getITRF(IERSConventions.IERS_2010, true); private String printVector3D(final String name, final Vector3D v) { return name + " " + f2.format(v); } private String printRotation(final String name, final Rotation r) { return name + " " + f1.format(r.getQ1()) + " " + f1.format(r.getQ2()) + " " + f1.format(r.getQ3()) + " " + f1.format(r.getQ0()); } private String printRotation2(final String name, final Rotation r) { return name + " " + f1.format(-r.getQ1()) + " " + f1.format(-r.getQ2()) + " " + f1.format(-r.getQ3()) + " " + f1.format(-r.getQ0()); } public void init(final SpacecraftState s0, final AbsoluteDate t) { } public void handleStep(SpacecraftState currentState, boolean isLast) throws PropagationException { try { // the Earth position in spacecraft should be along spacecraft Z axis // during nigthtime and away from it during daytime due to roll and pitch offsets final Vector3D earth = currentState.toTransform().transformPosition(Vector3D.ZERO); final double pointingOffset = Vector3D.angle(earth, Vector3D.PLUS_K); // the g function is the eclipse indicator, its an angle between Sun and Earth limb, // positive when Sun is outside of Earth limb, negative when Sun is hidden by Earth limb final double eclipseAngle = dayNightEvent.g(currentState); final double endNightDayTimer1 = endNightDayRdV1Event_decrease.g(currentState); final double endNightDayTimer2 = endNightDayRdV2Event_decrease.g(currentState); final double endDayNightTimer1 = endDayNightRdV1Event_decrease.g(currentState); final double endDayNightTimer2 = endDayNightRdV2Event_decrease.g(currentState); output.add(currentState.getDate() + " " + FastMath.toDegrees(eclipseAngle) + " " + endNightDayTimer1 + " " + endNightDayTimer2 + " " + endDayNightTimer1 + " " + endDayNightTimer2 + " " + FastMath.toDegrees(pointingOffset)); final AbsoluteDate date = currentState.getDate(); final PVCoordinates pv = currentState.getPVCoordinates(eme2000); final Rotation lvlhRot = new Rotation(pv.getPosition(), pv.getMomentum(), Vector3D.MINUS_K, Vector3D.MINUS_J); final Rotation earthRot = eme2000.getTransformTo(itrf2005, date).getRotation(); System.out.println("Scenario::setVectorMap 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " " + printVector3D("sun", sun.getPVCoordinates(date, eme2000).getPosition()) + " " + printVector3D("moon", moon.getPVCoordinates(date, eme2000).getPosition()) + " " + printVector3D("satPos", pv.getPosition()) + " " + printVector3D("satVel", pv.getVelocity()) + " " + printVector3D("orbMom", pv.getMomentum())); System.out.println("Scenario::setQuatMap 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY) + " " + printRotation("earthFrame", earthRot) + " " + printRotation("LVLHFrame", lvlhRot)); System.out.println("Scenario::computeStep 0x960b7e0 " + (date.durationFrom(AbsoluteDate.J2000_EPOCH) / Constants.JULIAN_DAY)); System.out.println(" -> " + printRotation2("", currentState.getAttitude().getRotation()) + " " + printVector3D("", currentState.getAttitude().getSpin())); } catch (OrekitException oe) { throw new PropagationException(oe); } } }); //---------- // Propagate //---------- // Propagate from the initial date for the fixed duration propagator.propagate(initialDate.shiftedBy(1.75 * 3600.)); //-------------- // Print results //-------------- // we print the lines according to lexicographic order, which is chronological order here // to make sure out of orders calls between step handler and event handlers don't mess things up for (final String line : output) { System.out.println(line); } } catch (OrekitException oe) { System.err.println(oe.getMessage()); } }
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);//ww w .j av a 2 s . 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.DEFObject.java
public DEFObject(final TR tr, Model model, EnemyDefinition def, EnemyPlacement pl) { super(tr, model); this.def = def; boundingRadius = TR.legacy2Modern(def.getBoundingBoxRadius()) / 1.5; anchoring = Anchoring.floating;/* w ww . j a va2 s. com*/ logic = def.getLogic(); mobile = true; canTurn = true; foliage = false; boss = def.isObjectIsBoss(); //Default Direction setDirection(new ObjectDirection(pl.getRoll(), pl.getPitch(), pl.getYaw() + 65536)); boolean customExplosion = false; this.setModelOffset(TR.legacy2Modern(def.getPivotX()), TR.legacy2Modern(def.getPivotY()), TR.legacy2Modern(def.getPivotZ())); switch (logic) { case groundDumb: mobile = false; canTurn = false; anchoring = Anchoring.terrain; break; case groundTargeting://Ground turrets { mobile = false; canTurn = true; addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); //TODO: def.getFiringVertices() needs actual vertex lookup. ProjectileFiringBehavior pfb; addBehavior(pfb = new ProjectileFiringBehavior() .setProjectileFactory( tr.getResourceManager().getProjectileFactories()[def.getWeapon().ordinal()]) .setFiringPositions(new Vector3D[] { new Vector3D(0, 0, 0) })); try { pfb.addSupply(9999999); } catch (SupplyNotNeededException e) { } addBehavior(new AutoFiring().setProjectileFiringBehavior(pfb) .setPatternOffsetMillis((int) (Math.random() * 2000)).setMaxFiringDistance(TR.mapSquareSize * 3) .setSmartFiring(false).setMaxFireVectorDeviation(.5).setTimePerPatternEntry(500)); anchoring = Anchoring.terrain; break; } case flyingDumb: canTurn = false; break; case groundTargetingDumb: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); anchoring = Anchoring.terrain; break; case flyingSmart: smartPlaneBehavior(tr, def, false); break; case bankSpinDrill: unhandled(def); break; case sphereBoss: projectileFiringBehavior(); mobile = true; break; case flyingAttackRetreatSmart: smartPlaneBehavior(tr, def, false); //addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); break; case splitShipSmart://TODO smartPlaneBehavior(tr, def, false); //addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); break; case groundStaticRuin://Destroyed object is replaced with another using SimpleModel i.e. weapons bunker mobile = false; canTurn = false; anchoring = Anchoring.terrain; break; case targetHeadingSmart: mobile = false;//Belazure's crane bots addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); anchoring = Anchoring.terrain; break; case targetPitchSmart: mobile = false; addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); anchoring = Anchoring.terrain; break; case coreBossSmart: mobile = false; projectileFiringBehavior(); break; case cityBossSmart: mobile = false; projectileFiringBehavior(); break; case staticFiringSmart: { //addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); final ProjectileFiringBehavior pfb = new ProjectileFiringBehavior(); try { pfb.addSupply(99999999); } catch (SupplyNotNeededException e) { } pfb.setProjectileFactory(tr.getResourceManager().getProjectileFactories()[def.getWeapon().ordinal()]); addBehavior(pfb); addBehavior(new AutoFiring().setProjectileFiringBehavior(pfb) .setPatternOffsetMillis((int) (Math.random() * 2000)).setMaxFiringDistance(TR.mapSquareSize * 8) .setSmartFiring(true)); mobile = false; canTurn = false; break; } case sittingDuck: canTurn = false; mobile = false; break; case tunnelAttack: { final ProjectileFiringBehavior pfb = new ProjectileFiringBehavior(); try { pfb.addSupply(99999999); } catch (SupplyNotNeededException e) { } pfb.setProjectileFactory(tr.getResourceManager().getProjectileFactories()[def.getWeapon().ordinal()]); addBehavior(pfb); //addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); addBehavior(new AutoFiring().setProjectileFiringBehavior(pfb) .setPatternOffsetMillis((int) (Math.random() * 2000)) .setMaxFiringDistance(TR.mapSquareSize * .2).setSmartFiring(false).setMaxFireVectorDeviation(.3) .setTimePerPatternEntry(2000)); /*addBehavior(new Bobbing(). setPhase(Math.random()). setBobPeriodMillis(10*1000+Math.random()*3000).setAmplitude(2000). setAdditionalHeight(0));*/ //Conflicts with TunnelRailed mobile = false; break; } case takeoffAndEscape: addBehavior(new MovesByVelocity()); addBehavior( (Behavior) (new HasPropulsion().setMinPropulsion(0).setPropulsion(def.getThrustSpeed() / 1.2))); addBehavior(new AccelleratedByPropulsion().setEnable(false)); addBehavior(new VelocityDragBehavior().setDragCoefficient(.86)); addBehavior(new CustomPlayerWithinRangeBehavior() { @Override public void withinRange() { DEFObject.this.getBehavior().probeForBehavior(AccelleratedByPropulsion.class) .setThrustVector(Vector3D.PLUS_J).setEnable(true); } }).setRange(TR.mapSquareSize * 10); addBehavior(new LoopingPositionBehavior()); addBehavior(new ExplodesOnDeath(ExplosionType.Blast, BIG_EXP_SOUNDS[(int) (Math.random() * 3)])); customExplosion = true; canTurn = false; mobile = false; break; case fallingAsteroid: anchoring = Anchoring.floating; fallingObjectBehavior(); customExplosion = true; addBehavior(new ExplodesOnDeath(ExplosionType.BigExplosion, MED_EXP_SOUNDS[(int) (Math.random() * 2)])); //setVisible(false); //addBehavior(new FallingDebrisBehavior(tr,model)); break; case cNome://Walky bot? anchoring = Anchoring.terrain; break; case cNomeLegs://Walky bot? anchoring = Anchoring.terrain; break; case cNomeFactory: mobile = false; break; case geigerBoss: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); anchoring = Anchoring.terrain; mobile = false; break; case volcanoBoss: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); anchoring = Anchoring.terrain; mobile = false; break; case volcano://Wat. unhandled(def); canTurn = false; mobile = false; anchoring = Anchoring.terrain; break; case missile://Silo? mobile = false;//TODO anchoring = Anchoring.terrain; break; case bob: addBehavior(new Bobbing().setAdditionalHeight(TR.mapSquareSize * 1)); addBehavior(new SteadilyRotating()); addBehavior(new ExplodesOnDeath(ExplosionType.Blast, MED_EXP_SOUNDS[(int) (Math.random() * 2)])); possibleBobbingSpinAndCrashOnDeath(.5, def); customExplosion = true; anchoring = Anchoring.floating; mobile = false; canTurn = false;//ironic? break; case alienBoss: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); mobile = false; break; case canyonBoss1: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); mobile = false; break; case canyonBoss2: addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); mobile = false; break; case lavaMan://Also terraform-o-bot addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); mobile = false; break; case arcticBoss: //ARTIC / Ymir. Hangs from ceiling. addBehavior(new HorizAimAtPlayerBehavior(tr.getGame().getPlayer())); projectileFiringBehavior(); mobile = false; anchoring = Anchoring.ceiling; break; case helicopter://TODO break; case tree: canTurn = false; mobile = false; foliage = true; anchoring = Anchoring.terrain; break; case ceilingStatic: canTurn = false; mobile = false; setTop(Vector3D.MINUS_J); anchoring = Anchoring.ceiling; break; case bobAndAttack: { addBehavior(new SteadilyRotating().setRotationPhase(2 * Math.PI * Math.random())); final ProjectileFiringBehavior pfb = new ProjectileFiringBehavior(); try { pfb.addSupply(99999999); } catch (SupplyNotNeededException e) { } pfb.setProjectileFactory(tr.getResourceManager().getProjectileFactories()[def.getWeapon().ordinal()]); addBehavior(pfb);//Bob and attack don't have the advantage of movement, so give them the advantage of range. addBehavior(new AutoFiring().setProjectileFiringBehavior(pfb) .setPatternOffsetMillis((int) (Math.random() * 2000)) .setMaxFiringDistance(TR.mapSquareSize * 17).setSmartFiring(true)); addBehavior(new Bobbing().setPhase(Math.random()).setBobPeriodMillis(10 * 1000 + Math.random() * 3000)); addBehavior(new ExplodesOnDeath(ExplosionType.Blast, BIG_EXP_SOUNDS[(int) (Math.random() * 3)])); possibleBobbingSpinAndCrashOnDeath(.5, def); customExplosion = true; mobile = false; canTurn = false; anchoring = Anchoring.floating; break; } case forwardDrive: canTurn = false; anchoring = Anchoring.terrain; break; case fallingStalag: fallingObjectBehavior(); customExplosion = true; addBehavior(new ExplodesOnDeath(ExplosionType.BigExplosion, MED_EXP_SOUNDS[(int) (Math.random() * 2)])); //canTurn=false; //mobile=false; anchoring = Anchoring.floating; break; case attackRetreatBelowSky: smartPlaneBehavior(tr, def, false); anchoring = Anchoring.floating; break; case attackRetreatAboveSky: smartPlaneBehavior(tr, def, true); anchoring = Anchoring.floating; break; case bobAboveSky: addBehavior(new Bobbing().setAdditionalHeight(TR.mapSquareSize * 5)); addBehavior(new SteadilyRotating()); possibleBobbingSpinAndCrashOnDeath(.5, def); mobile = false; canTurn = false; anchoring = Anchoring.floating; break; case factory: canTurn = false; mobile = false; anchoring = Anchoring.floating; break; }//end switch(logic) /////////////////////////////////////////////////////////// //Position Limit { final PositionLimit posLimit = new PositionLimit(); posLimit.getPositionMaxima()[1] = tr.getWorld().sizeY; posLimit.getPositionMinima()[1] = -tr.getWorld().sizeY; addBehavior(posLimit); } if (anchoring == Anchoring.terrain) { addBehavior(new CustomDeathBehavior(new Runnable() { @Override public void run() { tr.getGame().getCurrentMission().notifyGroundTargetDestroyed(); } })); addBehavior(new TerrainLocked()); } else if (anchoring == Anchoring.ceiling) { addBehavior(new TerrainLocked().setLockedToCeiling(true)); } else addBehavior(new CustomDeathBehavior(new Runnable() { @Override public void run() { tr.getGame().getCurrentMission().notifyAirTargetDestroyed(); }//end run() })); //Misc addBehavior(new TunnelRailed(tr));//Centers in tunnel when appropriate addBehavior(new DeathBehavior()); addBehavior(new DamageableBehavior().setHealth(pl.getStrength() + (spinCrash ? 16 : 0)) .setMaxHealth(pl.getStrength() + (spinCrash ? 16 : 0)).setEnable(!boss)); setActive(!boss); addBehavior(new DamagedByCollisionWithGameplayObject()); if (!foliage) addBehavior(new DebrisOnDeathBehavior()); else { addBehavior(new CustomDeathBehavior(new Runnable() { @Override public void run() { tr.getGame().getCurrentMission().notifyFoliageDestroyed(); } })); } if (canTurn || boss) { addBehavior(new RotationalMomentumBehavior()); addBehavior(new RotationalDragBehavior()).setDragCoefficient(.86); addBehavior(new AutoLeveling()); } if (foliage) { addBehavior(new ExplodesOnDeath(ExplosionType.Billow)); } else if ((!mobile || anchoring == Anchoring.terrain) && !customExplosion) { addBehavior(new ExplodesOnDeath(ExplosionType.BigExplosion, BIG_EXP_SOUNDS[(int) (Math.random() * 3)])); } else if (!customExplosion) { addBehavior(new ExplodesOnDeath(ExplosionType.Blast, MED_EXP_SOUNDS[(int) (Math.random() * 2)])); } if (mobile) { addBehavior(new MovesByVelocity()); addBehavior(new HasPropulsion()); addBehavior(new AccelleratedByPropulsion()); addBehavior(new VelocityDragBehavior()); if (anchoring == Anchoring.terrain) { } else {//addBehavior(new BouncesOffSurfaces().setReflectHeading(false)); addBehavior(new CollidesWithTerrain().setAutoNudge(true).setNudgePadding(40000)); } getBehavior().probeForBehavior(VelocityDragBehavior.class).setDragCoefficient(.86); getBehavior().probeForBehavior(Propelled.class).setMinPropulsion(0); getBehavior().probeForBehavior(Propelled.class).setPropulsion(def.getThrustSpeed() / 1.2); addBehavior(new LoopingPositionBehavior()); } //end if(mobile) if (def.getPowerup() != null && Math.random() * 100. < def.getPowerupProbability()) { addBehavior(new LeavesPowerupOnDeathBehavior(def.getPowerup())); } }
From source file:org.jtrfp.trcl.obj.DEFObject.java
private void smartPlaneBehavior(TR tr, EnemyDefinition def, boolean retreatAboveSky) { final HorizAimAtPlayerBehavior haapb = new HorizAimAtPlayerBehavior(tr.getGame().getPlayer()) .setLeftHanded(Math.random() >= .5); addBehavior(haapb);/*from w w w .ja v a 2s . c o m*/ final AdjustAltitudeToPlayerBehavior aatpb = new AdjustAltitudeToPlayerBehavior(tr.getGame().getPlayer()) .setAccelleration(1000); addBehavior(aatpb); final ProjectileFiringBehavior pfb = new ProjectileFiringBehavior() .setProjectileFactory(tr.getResourceManager().getProjectileFactories()[def.getWeapon().ordinal()]); try { pfb.addSupply(99999999); } catch (SupplyNotNeededException e) { } addBehavior(pfb); possibleSpinAndCrashOnDeath(.4, def); if (spinCrash) { final DamageTrigger spinAndCrashAddendum = new DamageTrigger() { @Override public void healthBelowThreshold() { final WorldObject parent = getParent(); final Behavior beh = parent.getBehavior(); final HasPropulsion hp = beh.probeForBehavior(HasPropulsion.class); hp.setPropulsion(hp.getPropulsion() / 1); beh.probeForBehavior(AutoLeveling.class).setLevelingAxis(LevelingAxis.HEADING) .setLevelingVector(Vector3D.MINUS_J).setRetainmentCoeff(.985, .985, .985); } }; addBehavior(spinAndCrashAddendum); } //end if(spinCrash) AccelleratedByPropulsion escapeProp = null; if (retreatAboveSky) { escapeProp = new AccelleratedByPropulsion(); escapeProp.setThrustVector(new Vector3D(0, .1, 0)).setEnable(false); addBehavior(escapeProp); } final AutoFiring afb = new AutoFiring(); afb.setMaxFireVectorDeviation(.3); afb.setFiringPattern(new boolean[] { true, false, false, false, true, true, false }); afb.setTimePerPatternEntry((int) (400 + Math.random() * 300)); afb.setPatternOffsetMillis((int) (Math.random() * 1000)); afb.setProjectileFiringBehavior(pfb); addBehavior(afb); final SpinAccellerationBehavior sab = (SpinAccellerationBehavior) new SpinAccellerationBehavior() .setEnable(false); addBehavior(sab); addBehavior(new SmartPlaneBehavior(haapb, afb, sab, aatpb, escapeProp, retreatAboveSky)); }
From source file:org.jtrfp.trcl.obj.TunnelExitObject.java
public TunnelExitObject(TR tr, Tunnel tun) { super(tr);/*from w ww .j a v a 2s . c o m*/ addBehavior(new TunnelExitBehavior()); final DirectionVector v = tun.getSourceTunnel().getExit(); final double EXIT_Y_NUDGE = 0; final InterpolatingAltitudeMap map = tr.getGame().getCurrentMission().getOverworldSystem().getAltitudeMap(); final double exitY = map.heightAt(TR.legacy2Modern(v.getZ()), TR.legacy2Modern(v.getX())) + EXIT_Y_NUDGE; this.exitLocation = new Vector3D(TR.legacy2Modern(v.getZ()), exitY, TR.legacy2Modern(v.getX())); this.tun = tun; exitHeading = map.normalAt(exitLocation.getZ() / TR.mapSquareSize, exitLocation.getX() / TR.mapSquareSize); Vector3D horiz = exitHeading.crossProduct(Vector3D.MINUS_J); if (horiz.getNorm() == 0) { horiz = Vector3D.PLUS_I; } else horiz = horiz.normalize(); exitTop = exitHeading.crossProduct(horiz.negate()).normalize().negate(); exitLocation = exitLocation.add(exitHeading.scalarMultiply(10000)); this.tr = tr; setVisible(false); try { Model m = tr.getResourceManager().getBINModel("SHIP.BIN", tr.getGlobalPaletteVL(), null, tr.gpu.get().getGl()); setModel(m); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.orekit.bodies.EllipsoidTest.java
@Test public void testPrincipalPlanesIntersections() { final Ellipsoid ellipsoid = new Ellipsoid(FramesFactory.getEME2000(), 1, 2, 3); final Ellipse xy = ellipsoid.getPlaneSection(Vector3D.ZERO, Vector3D.PLUS_K); Assert.assertEquals(0, Vector3D.distance(Vector3D.ZERO, xy.getCenter()), 1.0e-15); checkPrincipalAxes(xy, Vector3D.PLUS_J, Vector3D.MINUS_I); Assert.assertEquals(2.0, xy.getA(), 1.0e-15); Assert.assertEquals(1.0, xy.getB(), 1.0e-15); Assert.assertTrue(xy.getFrame() == ellipsoid.getFrame()); Assert.assertEquals(0.0, errorOnEllipsoid(xy, ellipsoid), 1.0e-15); Assert.assertEquals(0.0, errorOnPlane(xy, Vector3D.ZERO, Vector3D.PLUS_K), 1.0e-15); final Ellipse yz = ellipsoid.getPlaneSection(Vector3D.ZERO, Vector3D.PLUS_I); Assert.assertEquals(0, Vector3D.distance(Vector3D.ZERO, yz.getCenter()), 1.0e-15); checkPrincipalAxes(yz, Vector3D.PLUS_K, Vector3D.MINUS_J); Assert.assertEquals(3.0, yz.getA(), 1.0e-15); Assert.assertEquals(2.0, yz.getB(), 1.0e-15); Assert.assertTrue(yz.getFrame() == ellipsoid.getFrame()); Assert.assertEquals(0.0, errorOnEllipsoid(yz, ellipsoid), 1.0e-15); Assert.assertEquals(0.0, errorOnPlane(yz, Vector3D.ZERO, Vector3D.PLUS_I), 1.0e-15); final Ellipse zx = ellipsoid.getPlaneSection(Vector3D.ZERO, Vector3D.PLUS_J); Assert.assertEquals(0, Vector3D.distance(Vector3D.ZERO, zx.getCenter()), 1.0e-15); checkPrincipalAxes(zx, Vector3D.PLUS_K, Vector3D.PLUS_I); Assert.assertEquals(3.0, zx.getA(), 1.0e-15); Assert.assertEquals(1.0, zx.getB(), 1.0e-15); Assert.assertTrue(zx.getFrame() == ellipsoid.getFrame()); Assert.assertEquals(0.0, errorOnEllipsoid(zx, ellipsoid), 1.0e-15); Assert.assertEquals(0.0, errorOnPlane(zx, Vector3D.ZERO, Vector3D.PLUS_J), 1.0e-15); }
From source file:org.orekit.forces.BoxAndSolarArraySpacecraft.java
/** Build the surface vectors for body facets of a simple parallelepipedic box. * @param xLength length of the body along its X axis (m) * @param yLength length of the body along its Y axis (m) * @param zLength length of the body along its Z axis (m) * @return surface vectors array/* www .j a v a 2 s . com*/ */ private static Facet[] simpleBoxFacets(final double xLength, final double yLength, final double zLength) { return new Facet[] { new Facet(Vector3D.MINUS_I, yLength * zLength), new Facet(Vector3D.PLUS_I, yLength * zLength), new Facet(Vector3D.MINUS_J, xLength * zLength), new Facet(Vector3D.PLUS_J, xLength * zLength), new Facet(Vector3D.MINUS_K, xLength * yLength), new Facet(Vector3D.PLUS_K, xLength * yLength) }; }
From source file:org.orekit.frames.ITRFProviderWithoutTidalEffectsTest.java
@Test public void testRoughOrientation() throws OrekitException { AbsoluteDate date = new AbsoluteDate(2001, 03, 21, 0, 4, 0, TimeScalesFactory.getUTC()); Frame itrf2008 = FramesFactory.getITRF(IERSConventions.IERS_2010, true); Vector3D u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I); Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_I) < FastMath.toRadians(0.5)); date = date.shiftedBy(6 * 3600);/*from ww w. j av a 2 s .c o m*/ u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I); Assert.assertTrue(Vector3D.angle(u, Vector3D.MINUS_J) < FastMath.toRadians(0.5)); date = date.shiftedBy(6 * 3600); u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I); Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_I) < FastMath.toRadians(0.5)); date = date.shiftedBy(6 * 3600); u = itrf2008.getTransformTo(FramesFactory.getEME2000(), date).transformVector(Vector3D.PLUS_I); Assert.assertTrue(Vector3D.angle(u, Vector3D.PLUS_J) < FastMath.toRadians(0.5)); }