/* File: WorldCoordinate.java CVS Info: $Id: WorldCoordinate.java,v 1.2 1998/01/27 18:44:35 mcgredo Exp $ Compiler: jdk 1.3 */ package mil.navy.nps.dis; import mil.navy.nps.util.*; // General-purpose utilities import mil.navy.nps.disEnumerations.*; // Enumerations for DIS import java.lang.*; import java.util.*; import java.io.*; /** * Entity location in world coordinates. * *@version 1.0 *@author Don McGregor (http://www.npsnet.org/~mcgredo) * *
* *
sizeOf = 24 bytes
.
*/
public final int sizeOf = 24; // object is 24 bytes long
/**
*Constructs an new WorldCoordinate Object, centered.
*/
public WorldCoordinate()
{
// default constructor
x = 0.0;
y = 0.0;
z = 0.0;
return;
}
/**
*Constructs a new WorldCoordinate Object whose coordinate values are passed in parameters.
*
*@param pX the first coordinate in the cartesian coordinate system
*@param pY the second coordinate in the cartesian coordinate system
*@param pZ the third coordinate in the cartesian coordinate system
*/
public WorldCoordinate(double pX, double pY, double pZ)
{
x = pX;
y = pY;
z = pZ;
return;
}
public Object clone()
{
WorldCoordinate newWorldCoordinate = new WorldCoordinate(x, y, z);
return newWorldCoordinate;
}
/**
*@exception RuntimeException when IO error occurs.
*/
public void serialize(DataOutputStream outputStream)
{
// write out the data to an output stream. Order is important here, since
// it needs to conform to the DIS standard.
//super.serialize(outputStream); // No need to call super, since no ivars are in our direct superclass
try
{
outputStream.writeDouble(x);
outputStream.writeDouble(y);
outputStream.writeDouble(z);
}
catch (IOException ioError)
{
throw new
RuntimeException("Exception in WorldPosition. Error writing to wire.");
}
}
/**
*@exception RuntimeException when IO error occurs.
*/
public void deSerialize(DataInputStream pInputStream)
{
try
{
x = pInputStream.readDouble();
y = pInputStream.readDouble();
z = pInputStream.readDouble();
}
catch (IOException ioError)
{
throw new
RuntimeException("Exception in WorldPosition. Error reading from wire.");
}
}
public int length()
{
return sizeOf; // EntityTypes are this long, always.
}
public void printValues(int indentLevel, PrintStream printStream)
{
// print the values of the object out, with correct level of
// indentation on the page.
StringBuffer indent = ProtocolDataUnit.getPaddingOfLength(indentLevel);
int idx, superclassIndent = indentLevel;
printStream.println(indent + "WorldCoordinate x: " + x);
printStream.println(indent + "WorldCoordinate y: " + y);
printStream.println(indent + "WorldCoordinate z: " + z);
return;
}
// Accessor methods
public double getX()
{ return x;
}
public void setX(double pX)
{x = pX;
}
public double getY()
{ return y;
}
public void setY(double pY)
{y = pY;
}
public double getZ()
{ return z;
}
public void setZ(double pZ)
{z = pZ;
}
} // end of class WorldCoordinate