Package jme3utilities.math
Class MyBuffer
java.lang.Object
jme3utilities.math.MyBuffer
Utility methods that operate on buffers, especially float buffers containing
3-D vectors. Unlike the com.jme3.util.BufferUtils methods, these methods
ignore buffer limits.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic com.jme3.math.Matrix3fcovariance(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Matrix3f storeResult) Return the sample covariance of the 3-D vectors in the specified FloatBuffer range.static floatcylinderRadius(FloatBuffer buffer, int startPosition, int endPosition, int axisIndex) Return the radius of a bounding cylinder for the specified FloatBuffer range.static VectorSetdistinct(FloatBuffer buffer, int startPosition, int endPosition) Enumerate all distinct 3-D vectors in the specified FloatBuffer range, distinguishing 0 from -0.static FloatBufferensureCapacity(int minFloats, FloatBuffer bufferToReuse) Reuse the specified FloatBuffer, if it has the required capacity.static voidfill(FloatBuffer buffer, float... floatValues) Fill the specified FloatBuffer with a cyclic sequence of values.static intCount the number of times the specified value occurs in the specified IntBuffer range.static voidget(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f storeVector) Read a Vector3f starting from the specified position.static booleanisAllFinite(FloatBuffer buffer, int startPosition, int endPosition) Test whether all values in the specified FloatBuffer range are finite.listNeighbors(FloatBuffer buffer, int startPosition, int endPosition, float maxDistance) Enumerate all pairs of 3-D vectors in the specified FloatBuffer range whose Euclidean distance is less that the specified limit.static com.jme3.math.Vector3fmaxAbs(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult) Find the maximum absolute coordinate for each axis in the specified FloatBuffer range.static floatmaxLength(FloatBuffer buffer, int startPosition, int endPosition) Find the magnitude of the longest 3-D vector in the specified FloatBuffer range.static voidmaxMin(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeMaxima, com.jme3.math.Vector3f storeMinima) Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range.static com.jme3.math.Vector3fmean(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult) Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.static voidnormalize(FloatBuffer buffer, int startPosition, int endPosition) Normalize 3-D vectors in the specified FloatBuffer range.static voidput(FloatBuffer buffer, int startPosition, com.jme3.math.Vector3f vector) Write a Vector3f starting at the specified position.static voidput(FloatBuffer buffer, int startPosition, com.jme3.math.Vector4f vector) Write a Vector4f starting at the specified position.static intRead an index from a Buffer and advance the buffer's position.static voidrotate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation) Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.static voidrotateBinormals(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation) Apply the specified rotation to the binormals in the specified FloatBuffer range.static voidscale(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f scale) Apply the specified scale factors to 3-D vectors in the specified FloatBuffer range.static float[]toFloatArray(FloatBuffer buffer, int startPosition, int endPosition) Copy data in the specified FloatBuffer range to a new array.static int[]toIntArray(IntBuffer buffer, int startPosition, int endPosition) Copy data in the specified IntBuffer range to a new array.static voidtransform(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Transform transform) Apply the specified coordinate transform to 3-D vectors in the specified FloatBuffer range.static voidtranslate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f offsetVector) Add the specified offset to 3-D vectors in the specified FloatBuffer range.
-
Field Details
-
logger
message logger for this class
-
-
Method Details
-
covariance
public static com.jme3.math.Matrix3f covariance(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Matrix3f storeResult) Return the sample covariance of the 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition-6)endPosition- the position at which the vectors end (≥startPosition+6, ≤capacity)storeResult- storage for the result (modified if not null)- Returns:
- the unbiased sample covariance (either storeResult or a new matrix, not null)
-
cylinderRadius
public static float cylinderRadius(FloatBuffer buffer, int startPosition, int endPosition, int axisIndex) Return the radius of a bounding cylinder for the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)axisIndex- the cylinder's height axis: 0→X, 1→Y, 2→Z- Returns:
- the radius of the minimum bounding cylinder centered at the origin (≥0)
-
distinct
Enumerate all distinct 3-D vectors in the specified FloatBuffer range, distinguishing 0 from -0.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)- Returns:
- a new VectorSet (not null)
-
ensureCapacity
Reuse the specified FloatBuffer, if it has the required capacity. If no buffer is specified, allocate a new one.- Parameters:
minFloats- the required capacity (in floats, ≥0)bufferToReuse- the buffer to reuse, or null for none- Returns:
- a buffer with at least the required capacity (either storeResult or a new direct buffer)
-
fill
Fill the specified FloatBuffer with a cyclic sequence of values.- Parameters:
buffer- the buffer to modify (not null)floatValues- the sequence of values (not null, unaffected)
-
frequency
Count the number of times the specified value occurs in the specified IntBuffer range.- Parameters:
buffer- the buffer that contains the data (not null, unaffected)startPosition- the position at which the data start (≥0, ≤endPosition)endPosition- the position at which the data end (≥startPosition, ≤capacity)intValue- the value to search for- Returns:
- the number of occurrences found (≥0)
-
get
Read a Vector3f starting from the specified position. Does not alter the buffer's position.- Parameters:
buffer- the buffer to read from (not null, unaffected)startPosition- the position at which to start reading (≥0)storeVector- storage for the vector (not null, modified)- See Also:
-
BufferUtils.populateFromBuffer(com.jme3.math.Vector3f, java.nio.FloatBuffer, int)
-
isAllFinite
Test whether all values in the specified FloatBuffer range are finite.- Parameters:
buffer- the buffer that contains the data (not null, unaffected)startPosition- the position at which the data start (≥0, ≤endPosition)endPosition- the position at which the data end (≥startPosition, ≤capacity)- Returns:
- false if any value is NaN or infinite, otherwise true
-
listNeighbors
public static Set<IntPair> listNeighbors(FloatBuffer buffer, int startPosition, int endPosition, float maxDistance) Enumerate all pairs of 3-D vectors in the specified FloatBuffer range whose Euclidean distance is less that the specified limit.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)maxDistance- the desired limit (≥0)- Returns:
- a new list of zero-origin index pairs
-
maxAbs
public static com.jme3.math.Vector3f maxAbs(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult) Find the maximum absolute coordinate for each axis in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)storeResult- storage for the result (modified if not null)- Returns:
- the half extent for each axis (either storeResult or a new instance)
-
maxLength
Find the magnitude of the longest 3-D vector in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)- Returns:
- the radius of the minimum bounding sphere centered at the origin (≥0)
-
maxMin
public static void maxMin(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeMaxima, com.jme3.math.Vector3f storeMinima) Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range. An empty range stores infinities.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)storeMaxima- storage for maxima (not null, modified)storeMinima- storage for minima (not null, modified)- See Also:
-
BoundingBox.containAABB(java.nio.FloatBuffer)
-
mean
public static com.jme3.math.Vector3f mean(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f storeResult) Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, unaffected)startPosition- the position at which the vectors start (≥0, ≤endPosition-3)endPosition- the position at which the vectors end (≥startPosition+3, ≤capacity)storeResult- storage for the result (modified if not null)- Returns:
- the mean (either storeResult or a new vector, not null)
-
normalize
Normalize 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, modified)startPosition- the position at which the vectors start (≥0, ≤endPosition-3)endPosition- the position at which the vectors end (≥startPosition+3, ≤capacity)
-
put
Write a Vector3f starting at the specified position. Does not alter the buffer's position.- Parameters:
buffer- the buffer to write to (not null, modified)startPosition- the position at which to start writing (≥0)vector- the input vector (not null, unaffected)- See Also:
-
BufferUtils.setInBuffer(com.jme3.math.Vector3f, java.nio.FloatBuffer, int)
-
put
Write a Vector4f starting at the specified position. Does not alter the buffer's position.- Parameters:
buffer- the buffer to write to (not null, modified)startPosition- the position at which to start writing (≥0)vector- the input vector (not null, unaffected)- See Also:
-
BufferUtils.setInBuffer(com.jme3.math.Vector4f, java.nio.FloatBuffer, int)
-
readIndex
Read an index from a Buffer and advance the buffer's position.- Parameters:
buffer- a Buffer of bytes or ints or shorts (not null)- Returns:
- index (≥0)
-
rotate
public static void rotate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation) Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, MODIFIED)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)rotation- the rotation to apply (not null, unaffected)
-
rotateBinormals
public static void rotateBinormals(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Quaternion rotation) Apply the specified rotation to the binormals in the specified FloatBuffer range. The W components are left untouched.- Parameters:
buffer- the buffer that contains the binormals (not null, MODIFIED)startPosition- the position at which the binormals start (≥0, ≤endPosition)endPosition- the position at which the binormals end (≥startPosition, ≤capacity)rotation- the rotation to apply (not null, unaffected)
-
scale
public static void scale(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f scale) Apply the specified scale factors to 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, MODIFIED)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)scale- the scale factor to apply to each axis (not null, unaffected)
-
toFloatArray
Copy data in the specified FloatBuffer range to a new array.- Parameters:
buffer- the buffer that contains the data (not null, unaffected)startPosition- the position at which the data start (≥0, ≤endPosition)endPosition- the position at which the data end (≥startPosition, ≤capacity)- Returns:
- a new array (not null)
-
toIntArray
Copy data in the specified IntBuffer range to a new array.- Parameters:
buffer- the buffer that contains the data (not null, unaffected)startPosition- the position at which the data start (≥0, ≤endPosition)endPosition- the position at which the data end (≥startPosition, ≤capacity)- Returns:
- a new array (not null)
-
transform
public static void transform(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Transform transform) Apply the specified coordinate transform to 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, MODIFIED)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)transform- the transform to apply (not null, unaffected)
-
translate
public static void translate(FloatBuffer buffer, int startPosition, int endPosition, com.jme3.math.Vector3f offsetVector) Add the specified offset to 3-D vectors in the specified FloatBuffer range.- Parameters:
buffer- the buffer that contains the vectors (not null, MODIFIED)startPosition- the position at which the vectors start (≥0, ≤endPosition)endPosition- the position at which the vectors end (≥startPosition, ≤capacity)offsetVector- the vector to add (not null, unaffected)
-