diff --git a/examples/DisDemo/src/disdemo/DisDemo.java b/examples/DisDemo/src/disdemo/DisDemo.java deleted file mode 100644 index 43354fac62edb7d1b2156b90114d19ace2245940..0000000000000000000000000000000000000000 --- a/examples/DisDemo/src/disdemo/DisDemo.java +++ /dev/null @@ -1,153 +0,0 @@ -package disdemo; - -import edu.nps.moves.dis7.enumerations.Country; -import edu.nps.moves.dis7.enumerations.EntityKind; -import edu.nps.moves.dis7.enumerations.ForceID; -import edu.nps.moves.dis7.enumerations.PlatformDomain; -import edu.nps.moves.dis7.pdus.DisTime; -import edu.nps.moves.dis7.pdus.Domain; -import edu.nps.moves.dis7.pdus.EntityStatePdu; -import edu.nps.moves.dis7.pdus.Vector3Double; -import edu.nps.moves.spatial.*; - -import java.io.IOException; -import java.net.*; -import java.nio.ByteBuffer; -import java.util.*; - -/** - * - * @author DMcG - */ -public class DisDemo { - - /** - * Program invocation, execution starts here - * @param args command-line arguments - * @throws java.lang.Exception execution error - */ - public static void main(String[] args) throws Exception - { - EntityStatePdu espdu = new EntityStatePdu(); - - int NUMBER_OF_SENDS = 20; - int PORT = 3000; - int INTERVAL_MSEC = 1000; // 1 second - - // Create a new coordinate system at the give latitude, longitude, and altitude - RangeCoordinates rangeCoordinates = new RangeCoordinates(31.435, 45.223, 17.0); - - // Convert from the coodinate system with the origin above to DIS coordinates - Vector3Double disCoordinates = rangeCoordinates.DISCoordFromLocalFlat(0, 0, 0); - espdu.setEntityLocation(disCoordinates); - - // Set various fields--entityID, entity type, etc. - espdu.setExerciseID((byte)1); - - espdu.getEntityID().setSiteID(17); - espdu.getEntityID().setApplicationID(42); - espdu.getEntityID().setEntityID(104); - - espdu.getEntityType().setEntityKind(EntityKind.PLATFORM); // platform - espdu.getEntityType().setDomain(Domain.inst(PlatformDomain.LAND)); // land - espdu.getEntityType().setCategory((short)2); - espdu.getEntityType().setSubCategory(1); - espdu.getEntityType().setSpecific((short)1); - espdu.getEntityType().setCountry(Country.UNITED_STATES_OF_AMERICA_USA); - - espdu.getMarking().setCharacters("lulz".getBytes()); - espdu.setForceId(ForceID.FRIENDLY); - - try (DatagramSocket socket = new DatagramSocket(PORT)) - { - - // We set the starting position to (0,0,0) in the local coordinate - // system, which is equivalent to the (lat, lon, alt) set above as - // the origin, which also corresponds to some DIS geocentric point. - // All three coordinate system points correspond to the same point - // in space. - Vector3Double startPosition = new Vector3Double(); - startPosition.setX(0.0); - startPosition.setY(0.0); - startPosition.setZ(0.0); - - // Our mover is told to start at (0,0,0) in the local coordinate system - EntityMoverSquare mover = new EntityMoverSquare(startPosition); - - List<InetAddress> allBcasts = getBroadcastAddresses(); - Vector3Double currentPosition, currentPositionDisCoords; - ByteBuffer buffer; - DatagramPacket packet; - - // Do some movement for a while - System.out.println ("Sending " + NUMBER_OF_SENDS + " ESPDU packets at " + - INTERVAL_MSEC + " msec (" + INTERVAL_MSEC/1000.0 + - " second) intervals on"); - System.out.println (" broadcast address=" + allBcasts + " port " + PORT); - for(int index = 1; index <= NUMBER_OF_SENDS; index++) - { - mover.step(); - - // get the current position of the enity in the local coordinate system - currentPosition = mover.getPosition(); - - // Convert that point to the DIS geocentric coordinate system - currentPositionDisCoords = rangeCoordinates.DISCoordFromLocalFlat(currentPosition.getX(), currentPosition.getY(), currentPosition.getZ()); - - // Set entity position in the espdu - espdu.setEntityLocation(currentPositionDisCoords); - - // Marshall it, send it - espdu.setTimestamp(new DisTime().getDisRelativeTimestamp()); - buffer = ByteBuffer.wrap(espdu.marshal()); - - for(InetAddress aBcast: allBcasts) - { - packet = new DatagramPacket(buffer.array(), buffer.array().length, aBcast, PORT); - socket.send(packet); - } - - Thread.sleep(INTERVAL_MSEC); - System.out.println("... sent " + index); - } - } - catch(IOException | InterruptedException e) - { - System.err.println(e); - } - - } - - public static List<InetAddress> getBroadcastAddresses() - { - List<InetAddress> broadcastAddresses = new ArrayList<>(); - - try - { - Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); - while (interfaces.hasMoreElements()) - { - NetworkInterface networkInterface = interfaces.nextElement(); - if (networkInterface.isLoopback()) - continue; // Don't want to broadcast to the loopback interface - - for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) - { - InetAddress broadcast = interfaceAddress.getBroadcast(); - if (broadcast == null) - continue; - - // Use the address - broadcastAddresses.add(broadcast); - } - } - } - catch(SocketException e) - { - System.err.println(e); - } - - return broadcastAddresses; - } - -} diff --git a/examples/DisDemo/src/disdemo/EntityMover.java b/examples/DisDemo/src/disdemo/EntityMover.java deleted file mode 100644 index dcf6efcdc3bab81f81b4723406d08a33e90c65ba..0000000000000000000000000000000000000000 --- a/examples/DisDemo/src/disdemo/EntityMover.java +++ /dev/null @@ -1,29 +0,0 @@ -package disdemo; - -import edu.nps.moves.dis7.pdus.*; - -/** - * Abstract superclass for moving entities. Initialized with a starting - * position (IN LOCAL COORDINATES). Step() performs one quanta of moving - * the thing around. After movement you can retrieve the new position with - * getPosition(), convert it to global DIS coordinates, and be on your way. - * - * @author DMcG - */ -public abstract class EntityMover -{ - Vector3Double position; - - public EntityMover(Vector3Double startPosition) - { - this.position = startPosition; - } - - public abstract void step(); - - public Vector3Double getPosition() - { - return position; - } - -} diff --git a/examples/DisDemo/src/disdemo/EntityMoverSquare.java b/examples/DisDemo/src/disdemo/EntityMoverSquare.java deleted file mode 100644 index e5397dcf0870137009d56cc540391e31baec3170..0000000000000000000000000000000000000000 --- a/examples/DisDemo/src/disdemo/EntityMoverSquare.java +++ /dev/null @@ -1,75 +0,0 @@ -package disdemo; - -import edu.nps.moves.dis7.pdus.*; - -/** - * Logic for moving something around in a square using a local coordinate system, - * ENU. East is positive X, north is positive Y, positive Z is "up". - * - * @author DMcG - */ -public class EntityMoverSquare extends EntityMover -{ - /** How much an entity moves every quanta */ - private static final int STEP_SIZE = 1; - /** How big the square we move around is */ - private static final int SQUARE_SIZE = 50; // size of a side to the square, in meters - /** Directions we can travel. */ - public enum Direction{NORTH, EAST, SOUTH, WEST}; - - public Direction currentDirection; - - public EntityMoverSquare(Vector3Double position) - { - super(position); - this.currentDirection = Direction.NORTH; - } - - @Override - public void step() - { - switch(currentDirection) - { - case NORTH: - position.setY( position.getY() + STEP_SIZE); - if(position.getY() >= SQUARE_SIZE) - { - currentDirection = Direction.EAST; - } - break; - - case EAST: - position.setX( position.getX() + STEP_SIZE); - if(position.getX() >= SQUARE_SIZE) - { - currentDirection = Direction.SOUTH; - } - break; - - case SOUTH: - position.setY( position.getY() - STEP_SIZE); - if(position.getY() <= 0.0) - { - currentDirection = Direction.WEST; - } - break; - - - case WEST: - - position.setX( position.getX() - STEP_SIZE); - if(position.getX() <= 0.0) - { - currentDirection = Direction.NORTH; - } - break; - - default: - System.out.println("Unrecognized direction"); - } - - System.out.println("Current position: " + position.getX() + ", " + position.getY() + ", " + position.getZ()); - - } - -} diff --git a/examples/build.xml b/examples/build.xml index ad9bc7fa833d8aeb9bbfd6174a271b71de2a4a5d..afefa42d630f9ba22633f4f3fd5092071c26bd28 100644 --- a/examples/build.xml +++ b/examples/build.xml @@ -1,90 +1,102 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- You may freely edit this file. See commented blocks below for --> -<!-- some examples of how to customize the build. --> -<!-- (If you delete it and reopen the project it will be recreated.) --> -<!-- By default, only the Clean and Build commands use this build script. --> -<!-- Commands such as Run, Debug, and Test only use this build script if --> -<!-- the Compile on Save feature is turned off for the project. --> -<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> -<!-- in the project's Project Properties dialog box.--> - -<project name="MV3500 examples" default="default" basedir="."> - <description>Builds, tests, and runs the project Networked Graphics MV3500 examples.</description> - <import file="nbproject/build-impl.xml"/> - - <!-- TODO target to test all examples as quick unit test --> - - <target name="test.examples"> - <!-- invoke single-process tests first --> - <!-- invoke two-process tests next, perhaps following patterns in open-dis7-java --> - </target> - - <target name="clean.pduLogAdditions"> - <delete verbose="true"> - <fileset dir="pduLog"> - <include name="Pdusave*.dislog"/> - <exclude name="Pdusave.dislog"/><!-- version control default example --> - </fileset> - </delete> - </target> - <!-- - - There exist several targets which are by default empty and which can be - used for execution of your tasks. These targets are usually executed - before and after some main targets. They are: - - -pre-init: called before initialization of project properties - -post-init: called after initialization of project properties - -pre-compile: called before javac compilation - -post-compile: called after javac compilation - -pre-compile-single: called before javac compilation of single file - -post-compile-single: called after javac compilation of single file - -pre-compile-test: called before javac compilation of JUnit tests - -post-compile-test: called after javac compilation of JUnit tests - -pre-compile-test-single: called before javac compilation of single JUnit test - -post-compile-test-single: called after javac compilation of single JUunit test - -pre-jar: called before JAR building - -post-jar: called after JAR building - -post-clean: called after cleaning build products - - (Targets beginning with '-' are not intended to be called on their own.) - - Example of inserting an obfuscator after compilation could look like this: - - <target name="-post-compile"> - <obfuscate> - <fileset dir="${build.classes.dir}"/> - </obfuscate> - </target> - - For list of available properties check the imported - nbproject/build-impl.xml file. - - - Another way to customize the build is by overriding existing main targets. - The targets of interest are: - - -init-macrodef-javac: defines macro for javac compilation - -init-macrodef-junit: defines macro for junit execution - -init-macrodef-debug: defines macro for class debugging - -init-macrodef-java: defines macro for class execution - -do-jar: JAR building - run: execution of project - -javadoc-build: Javadoc generation - test-report: JUnit report generation - - An example of overriding the target for project execution could look like this: - - <target name="run" depends="Networked_Graphics_MV3500_examples-impl.jar"> - <exec dir="bin" executable="launcher.exe"> - <arg file="${dist.jar}"/> - </exec> - </target> - - Notice that the overridden target depends on the jar target and not only on - the compile target as the regular run target does. Again, for a list of available - properties which you can use, check the target you are overriding in the - nbproject/build-impl.xml file. - - --> -</project> +<?xml version="1.0" encoding="UTF-8"?> +<!-- You may freely edit this file. See commented blocks below for --> +<!-- some examples of how to customize the build. --> +<!-- (If you delete it and reopen the project it will be recreated.) --> +<!-- By default, only the Clean and Build commands use this build script. --> +<!-- Commands such as Run, Debug, and Test only use this build script if --> +<!-- the Compile on Save feature is turned off for the project. --> +<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> +<!-- in the project's Project Properties dialog box.--> + +<project name="MV3500 examples" default="default" basedir="."> + <description>Builds, tests, and runs the project Networked Graphics MV3500 examples.</description> + <import file="nbproject/build-impl.xml"/> + + <!-- TODO target to test all examples as quick unit test --> + + <target name="test.examples"> + <!-- invoke single-process tests first --> + <!-- invoke two-process tests next, perhaps following patterns in open-dis7-java --> + </target> + + <target name="clean.pduLogAdditions"> + <delete verbose="true"> + <fileset dir="pduLog"> + <include name="Pdusave*.dislog"/> + <exclude name="Pdusave.dislog"/><!-- version control default example --> + </fileset> + </delete> + </target> + <!-- + + There exist several targets which are by default empty and which can be + used for execution of your tasks. These targets are usually executed + before and after some main targets. They are: + + -pre-init: called before initialization of project properties + -post-init: called after initialization of project properties + -pre-compile: called before javac compilation + -post-compile: called after javac compilation + -pre-compile-single: called before javac compilation of single file + -post-compile-single: called after javac compilation of single file + -pre-compile-test: called before javac compilation of JUnit tests + -post-compile-test: called after javac compilation of JUnit tests + -pre-compile-test-single: called before javac compilation of single JUnit test + -post-compile-test-single: called after javac compilation of single JUunit test + -pre-jar: called before JAR building + -post-jar: called after JAR building + -post-clean: called after cleaning build products + + (Targets beginning with '-' are not intended to be called on their own.) + + Example of inserting an obfuscator after compilation could look like this: + + <target name="-post-compile"> + <obfuscate> + <fileset dir="${build.classes.dir}"/> + </obfuscate> + </target> + + For list of available properties check the imported + nbproject/build-impl.xml file. + + + Another way to customize the build is by overriding existing main targets. + The targets of interest are: + + -init-macrodef-javac: defines macro for javac compilation + -init-macrodef-junit: defines macro for junit execution + -init-macrodef-debug: defines macro for class debugging + -init-macrodef-java: defines macro for class execution + -do-jar: JAR building + run: execution of project + -javadoc-build: Javadoc generation + test-report: JUnit report generation + + An example of overriding the target for project execution could look like this: + + <target name="run" depends="Networked_Graphics_MV3500_examples-impl.jar"> + <exec dir="bin" executable="launcher.exe"> + <arg file="${dist.jar}"/> + </exec> + </target> + + Notice that the overridden target depends on the jar target and not only on + the compile target as the regular run target does. Again, for a list of available + properties which you can use, check the target you are overriding in the + nbproject/build-impl.xml file. + + --> + + <target name="view.examples.javadoc.local" depends="javadoc" + description="view local MV3500 assignments javadoc in web browser (via Netbeans only)"> + <!-- no online javadoc --> + <echo message="dist/javadoc/index.html"/> + <nbbrowse file="dist/javadoc/index.html"/> + </target> + + <target name="view.examples.gitlab" description="view gitlab MV3500 examples in web browser (via Netbeans only)"> + <echo message="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/examples"/> + <nbbrowse url="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/examples"/> + </target> +</project>