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
-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix3f
covariance
(FloatBuffer buffer, int startPosition, int endPosition, Matrix3f storeResult) Return the sample covariance of the 3-D vectors in the specified FloatBuffer range.static float
cylinderRadius
(FloatBuffer buffer, int startPosition, int endPosition, int axisIndex) Return the radius of a bounding cylinder for the specified FloatBuffer range.static FloatBuffer
ensureCapacity
(int minFloats, FloatBuffer bufferToReuse) Reuse the specified FloatBuffer, if it has the required capacity.static int
Count the number of times the specified value occurs in the specified IntBuffer range.static void
get
(FloatBuffer buffer, int startPosition, Vector3f storeVector) Read a Vector3f starting from the specified position.static Vector3f
maxAbs
(FloatBuffer buffer, int startPosition, int endPosition, Vector3f storeResult) Find the maximum absolute coordinate for each axis in the specified FloatBuffer range.static float
maxLength
(FloatBuffer buffer, int startPosition, int endPosition) Find the magnitude of the longest 3-D vector in the specified FloatBuffer range.static void
maxMin
(FloatBuffer buffer, int startPosition, int endPosition, Vector3f storeMaxima, Vector3f storeMinima) Find the maximum and minimum coordinates of 3-D vectors in the specified FloatBuffer range.static Vector3f
mean
(FloatBuffer buffer, int startPosition, int endPosition, Vector3f storeResult) Determine the arithmetic mean of 3-D vectors in the specified FloatBuffer range.static void
put
(FloatBuffer buffer, int startPosition, Vector3f vector) Write a Vector3f starting at the specified position.static void
rotate
(FloatBuffer buffer, int startPosition, int endPosition, Quaternion rotation) Apply the specified rotation to 3-D vectors in the specified FloatBuffer range.static void
transform
(FloatBuffer buffer, int startPosition, int endPosition, Transform transform) Apply the specified coordinate transform to 3-D vectors in the specified FloatBuffer range.static void
translate
(FloatBuffer buffer, int startPosition, int endPosition, 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 Matrix3f covariance(FloatBuffer buffer, int startPosition, int endPosition, 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)
-
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)
-
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)
-
maxAbs
public static Vector3f maxAbs(FloatBuffer buffer, int startPosition, int endPosition, 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, Vector3f storeMaxima, 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)
-
mean
public static Vector3f mean(FloatBuffer buffer, int startPosition, int endPosition, 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)
-
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)
-
rotate
public static void rotate(FloatBuffer buffer, int startPosition, int endPosition, 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)
-
transform
public static void transform(FloatBuffer buffer, int startPosition, int endPosition, 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, 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)
-