Skip to content
Snippets Groups Projects
Commit 065a917d authored by Brutzman, Don's avatar Brutzman, Don
Browse files

autogenerate addition of utility methods

parent 1ccd068e
No related branches found
No related tags found
No related merge requests found
// autogenerated using string template dis7javalicense.txt
/** /**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. * Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt * This work is provided under a BSD open-source license, see project license.html and license.txt
*/ */
// header autogenerated using string template dis7javalicense.txt
package edu.nps.moves.dis7.pdus; package edu.nps.moves.dis7.pdus;
...@@ -38,7 +37,7 @@ public class EntityStatePdu extends EntityInformationInteractionFamilyPdu implem ...@@ -38,7 +37,7 @@ public class EntityStatePdu extends EntityInformationInteractionFamilyPdu implem
/** describes the location of the entity in the world */ /** describes the location of the entity in the world */
protected Vector3Double entityLocation = new Vector3Double(); protected Vector3Double entityLocation = new Vector3Double();
/** describes the orientation of the entity, in euler angles */ /** describes the orientation of the entity, in euler angles with units of radians */
protected EulerAngles entityOrientation = new EulerAngles(); protected EulerAngles entityOrientation = new EulerAngles();
/** a series of bit flags that are used to help draw the entity, such as smoking, on fire, etc. */ /** a series of bit flags that are used to help draw the entity, such as smoking, on fire, etc. */
...@@ -47,7 +46,7 @@ public class EntityStatePdu extends EntityInformationInteractionFamilyPdu implem ...@@ -47,7 +46,7 @@ public class EntityStatePdu extends EntityInformationInteractionFamilyPdu implem
/** parameters used for dead reckoning */ /** parameters used for dead reckoning */
protected DeadReckoningParameters deadReckoningParameters = new DeadReckoningParameters(); protected DeadReckoningParameters deadReckoningParameters = new DeadReckoningParameters();
/** 11 characters that can be used for entity identifiication, debugging, or to draw unique strings on the side of entities in the world */ /** 11 characters that can be used for entity identification, debugging, or to draw unique strings on the side of entities in the world */
protected EntityMarking marking = new EntityMarking(); protected EntityMarking marking = new EntityMarking();
/** a series of bit flags uid 55 */ /** a series of bit flags uid 55 */
...@@ -532,4 +531,129 @@ public int unmarshal(java.nio.ByteBuffer byteBuffer) throws Exception ...@@ -532,4 +531,129 @@ public int unmarshal(java.nio.ByteBuffer byteBuffer) throws Exception
return sb.toString(); return sb.toString();
} }
// EntityStateUtilityMethods
/** Direction enumerations */
public enum Direction
{
/** NORTH direction along Y axis */
NORTH,
/** NORTHEAST direction */
NORTHEAST,
/** EAST direction along X axis */
EAST,
/** SOUTHEAST direction */
SOUTHEAST,
/** SOUTH direction along -Y axis */
SOUTH,
/** SOUTHWEST direction */
SOUTHWEST,
/** WEST direction along -X axis */
WEST,
/** NORTHWEST direction */
NORTHWEST
}
/** Utility method to set entity linear velocity using speed and direction
* @param speed in meters/second
* @param direction using Directions enumerations
* @see Direction
* @return same object to permit progressive setters */
public final EntityStatePdu setEntityLinearVelocity (float speed, Direction direction)
{
float xFactor = 0.0f;
float yFactor = 0.0f;
switch (direction)
{
case NORTH:
xFactor = 0.0f; yFactor = 1.0f;
break;
case EAST:
xFactor = 1.0f; yFactor = 0.0f;
break;
case SOUTH:
xFactor = 0.0f; yFactor = -1.0f;
break;
case WEST:
xFactor = -1.0f; yFactor = 0.0f;
break;
case NORTHEAST:
xFactor = 0.7071f; yFactor = 0.7071f;
break;
case SOUTHEAST:
xFactor = -0.7071f; yFactor = 0.7071f;
break;
case SOUTHWEST:
xFactor = -0.7071f; yFactor = -0.7071f;
break;
case NORTHWEST:
xFactor = 0.7071f; yFactor = -0.7071f;
break;
default:
System.err.println("*** unexpected internal error, encountered illegal EntityStatePdu Direction");
}
Vector3Float newVelocity = new Vector3Float().setX(xFactor*speed).setY(yFactor*speed).setZ(getEntityLinearVelocity().z);
setEntityLinearVelocity(newVelocity);
return this;
}
/** Setter for {@link EntityStatePdu#entityLocation}
* @param x location
* @param y location
* @param z location
* @return same object to permit progressive setters */
public EntityStatePdu setEntityLocation(double x, double y, double z)
{
// TODO autogenerate such utility constructors
entityLocation = new Vector3Double().setX(x).setY(y).setZ(z);
return this;
}
/** Advance location using linear velocities for a single timestep
* @param timestep duration of travel
* @return same object to permit progressive setters */
public EntityStatePdu advanceEntityLocation(double timestep)
{
Vector3Double location = getEntityLocation();
Vector3Float velocity = getEntityLinearVelocity();
setEntityLocation(location.getX() + velocity.getX() * timestep,
location.getY() + velocity.getY() * timestep,
location.getZ() + velocity.getZ() * timestep);
return this;
}
/** Marking utility to clear character values
* @return same object to permit progressive setters */
public EntityStatePdu clearMarking()
{
byte[] emptyByteArray = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
marking.setCharacters(emptyByteArray);
return this;
}
/** Marking utility to set character values, 11 characters maximum
*@param newMarking new 11-character string to assign as marking value
* @return same object to permit progressive setters */
public EntityStatePdu setMarking(String newMarking)
{
if ((newMarking == null) || newMarking.isEmpty())
clearMarking();
else if (newMarking.length() > 11)
System.err.println ("*** marking '" + newMarking + "' is greater than 11 characters, truncating");
newMarking = String.format("%11s", newMarking);
marking.setCharacters(newMarking.getBytes());
return this;
}
/** Marking utility to get character values as a string
* @return 11-character String value corresponding to marking */
public String getMarkingString()
{
return new String(marking.getCharacters());
}
} // end of class } // end of class
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment