/* File: LinearVelocity.java CVS Info: $Id: LinearVelocity.java,v 1.2 1998/01/27 18:44:18 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.*; /** * Linear velocity of an entity. * *@version 1.0 *@author Don McGregor (http://www.npsnet.org/~mcgredo) * *
sizeOf = 12 bytes
.
*/
public final int sizeOf = 12; // object is 12 bytes long
/**
*Constructs an new LinearVelocity Vector, LinearVelocity's value is 0.
*/
public LinearVelocity()
{
// default constructor
x = 0;
y = 0;
z = 0;
return;
}
/**
*Constructs a new LinearVelocity Vector with coordinate values 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 LinearVelocity(float pX, float pY, float pZ)
{
x = pX;
y = pY;
z = pZ;
return;
}
public Object clone()
{
LinearVelocity newLinearVelocity = new LinearVelocity(x, y, z);
return newLinearVelocity;
}
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.writeFloat(x);
outputStream.writeFloat(y);
outputStream.writeFloat(z);
}
catch (IOException ioError)
{
throw new
RuntimeException("Exception in LinearVelocity. Error writing to wire.");
}
}
public void deSerialize(DataInputStream pInputStream)
{
try
{
x = pInputStream.readFloat();
y = pInputStream.readFloat();
z = pInputStream.readFloat();
}
catch (IOException ioError)
{
throw new
RuntimeException("Exception in LinearVelocity. 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 + "LinearVelocity x: " + x);
printStream.println(indent + "LinearVelocity y: " + y);
printStream.println(indent + "LinearVelocity z: " + z);
return;
}
// Accessor methods
public void setValues(float pX, float pY, float pZ)
{
x = pX;
y = pY;
z = pZ;
}
public float getX()
{ return x;
}
public void setX(float pX)
{x = pX;
}
public float getY()
{ return y;
}
public void setY(float pY)
{y = pY;
}
public float getZ()
{ return z;
}
public void setZ(float pZ)
{z = pZ;
}
} // end of class LinearVelocity