From ab9076c83cc3b2e7800eaf0a19febe786458146d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 10 Dec 2013 21:20:13 +0100 Subject: Bug 747: VectorUtil: Make scale(..) creating new float[] deprecated, adding 'in place' variant w/ passing result float[] ; TODO: Replace all variations with 'in place' version to be more memory efficient. Make scale(..) creating new float[] deprecated, adding 'in place' variant w/ passing result float[] TODO: Replace all variations with 'in place' version to be more memory efficient. See Bug747: Validate memory footprint and usage / General performance --- .../classes/com/jogamp/opengl/math/VectorUtil.java | 38 +++++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src/jogl') diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java index 508f1aafd..e1e797088 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java @@ -70,21 +70,49 @@ public class VectorUtil { return newVector; } - /** Scales a vector by param + /** Scales a vector by param creating a new float[] for the result! * @param vector input vector * @param scale constant to scale by - * @return scaled vector + * @return new scaled vector + * @deprecated Use {@link #scale(float[], float[], float)} */ public static float[] scale(float[] vector, float scale) { final float[] newVector = new float[3]; - newVector[0] = vector[0]*scale; - newVector[1] = vector[1]*scale; - newVector[2] = vector[2]*scale; + newVector[0] = vector[0] * scale; + newVector[1] = vector[1] * scale; + newVector[2] = vector[2] * scale; return newVector; } + /** Scales a vector by param using given result float[] + * @param result vector for the result + * @param vector input vector + * @param scale single scale constant for all vector components + */ + public static float[] scale(float[] result, float[] vector, float scale) + { + result[0] = vector[0] * scale; + result[1] = vector[1] * scale; + result[2] = vector[2] * scale; + return result; + } + + /** Scales a vector by param using given result float[] + * @param result vector for the result + * @param vector input vector + * @param scale 3 component scale constant for each vector component + * @return given result vector + */ + public static float[] scale(float[] result, float[] vector, float[] scale) + { + result[0] = vector[0] * scale[0]; + result[1] = vector[1] * scale[1]; + result[2] = vector[2] * scale[2]; + return result; + } + /** Adds to vectors * @param v1 vector 1 * @param v2 vector 2 -- cgit v1.2.3