Class Toolbox


  • public class Toolbox
    extends Object
    Class that contains some useful functions
    Author:
    Darius Dinger
    • Constructor Summary

      Constructors 
      Constructor Description
      Toolbox()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float[] addElement​(float[] array, float element)
      Adding an float element to an float array
      static int[] addElement​(int[] array, int element)
      Adding an int element to an int array
      static <T> T[] addElement​(T[] array, T element)
      Adding an element to an array
      static String arrayToString​(float[] arr, String seperator)
      Convert a float array into a string
      static float[] calcTangent​(float v0x, float v0y, float v0z, float v1x, float v1y, float v1z, float v2x, float v2y, float v2z, float v0u, float v0v, float v1u, float v1v, float v2u, float v2v)
      Calculating tangent for a triangle
      static Color generateRandomColor()  
      static float[] matrixToFloatArray​(javax.vecmath.Matrix4f mat)
      Transforming a matrix4f from vecmtath to a 16 valued float array.
      Maybe not the most performant procedure...
      static float max​(float... values)
      Getting the greatest float of values
      static float min​(float... values)
      Getting the smallest float of values
      static float randomFloat​(float min, float max)
      Generating a random float between min and max
      static int randomInt​(int min, int max)
      Generating a random integer between min and max
      static javax.vecmath.Vector2f randomVector​(javax.vecmath.Vector2f min, javax.vecmath.Vector2f max)
      Generating random vector between min and max
      static javax.vecmath.Vector3f randomVector​(javax.vecmath.Vector3f min, javax.vecmath.Vector3f max)
      Generating random vector between min and max
      static float[] stringToArrayf​(String str, String seperator)
      Convert a string into a float array
      static int[] stringToArrayi​(String str, String seperator)
      Convert a string into a integer array
      static float[] toArrayf​(List<Float> floats)
      Converting a list of floats into a float array.
      static int[] toArrayi​(List<Integer> ints)
      Converting a list of integers into a int array.
    • Constructor Detail

      • Toolbox

        public Toolbox()
    • Method Detail

      • addElement

        public static <T> T[] addElement​(T[] array,
                                         T element)
        Adding an element to an array
        Type Parameters:
        T - Type of the array data
        Parameters:
        array - Array where the element should be added
        element - Element to add into array
        Returns:
        New array with element added
      • addElement

        public static int[] addElement​(int[] array,
                                       int element)
        Adding an int element to an int array
        Parameters:
        array - Array where the element should be added
        element - Element to add into array
        Returns:
        New array with element added
      • addElement

        public static float[] addElement​(float[] array,
                                         float element)
        Adding an float element to an float array
        Parameters:
        array - Array where the element should be added
        element - Element to add into array
        Returns:
        New array with element added
      • matrixToFloatArray

        public static float[] matrixToFloatArray​(javax.vecmath.Matrix4f mat)
        Transforming a matrix4f from vecmtath to a 16 valued float array.
        Maybe not the most performant procedure...
        Parameters:
        mat - Matrix to transform
        Returns:
        Transformed float array
      • generateRandomColor

        public static Color generateRandomColor()
        Returns:
        Random color
      • toArrayf

        public static float[] toArrayf​(List<Float> floats)
        Converting a list of floats into a float array. Because java hates that...
        Parameters:
        floats - Float list to convert
        Returns:
        Converted float array
      • toArrayi

        public static int[] toArrayi​(List<Integer> ints)
        Converting a list of integers into a int array.
        Parameters:
        ints - Integer list to convert
        Returns:
        Converted int array
      • arrayToString

        public static String arrayToString​(float[] arr,
                                           String seperator)
        Convert a float array into a string
        Parameters:
        arr - Array to convert
        seperator - Sperator of the string
        Returns:
        Generated string
      • stringToArrayf

        public static float[] stringToArrayf​(String str,
                                             String seperator)
        Convert a string into a float array
        Parameters:
        str - String to convert
        seperator - Seperator of the string
        Returns:
        Generated float array
      • stringToArrayi

        public static int[] stringToArrayi​(String str,
                                           String seperator)
        Convert a string into a integer array
        Parameters:
        str - String to convert
        seperator - Seperator of the string
        Returns:
        Generated int array
      • randomFloat

        public static float randomFloat​(float min,
                                        float max)
        Generating a random float between min and max
        Parameters:
        min - Min value of the float
        max - Max value of the float
        Returns:
        Generated value
      • randomInt

        public static int randomInt​(int min,
                                    int max)
        Generating a random integer between min and max
        Parameters:
        min - Min value of the integer
        max - Max value of the integer
        Returns:
        Generated value
      • randomVector

        public static javax.vecmath.Vector3f randomVector​(javax.vecmath.Vector3f min,
                                                          javax.vecmath.Vector3f max)
        Generating random vector between min and max
        Parameters:
        min - Min vector values
        max - Max vector values
        Returns:
        Generated vector
      • randomVector

        public static javax.vecmath.Vector2f randomVector​(javax.vecmath.Vector2f min,
                                                          javax.vecmath.Vector2f max)
        Generating random vector between min and max
        Parameters:
        min - Min vector values
        max - Max vector values
        Returns:
        Generated vector
      • min

        public static float min​(float... values)
        Getting the smallest float of values
        Parameters:
        values - Floats to gets smallest from
        Returns:
        Smallest float of values
      • max

        public static float max​(float... values)
        Getting the greatest float of values
        Parameters:
        values - Floats to gets greatest from
        Returns:
        Greatest float of values
      • calcTangent

        public static float[] calcTangent​(float v0x,
                                          float v0y,
                                          float v0z,
                                          float v1x,
                                          float v1y,
                                          float v1z,
                                          float v2x,
                                          float v2y,
                                          float v2z,
                                          float v0u,
                                          float v0v,
                                          float v1u,
                                          float v1v,
                                          float v2u,
                                          float v2v)
        Calculating tangent for a triangle
        Parameters:
        v0x - X coordinate of vertex 0
        v0y - Y coordinate of vertex 0
        v0z - Z coordinate of vertex 0
        v1x - X coordinate of vertex 1
        v1y - Y coordinate of vertex 1
        v1z - Z coordinate of vertex 1
        v2x - X coordinate of vertex 2
        v2y - Y coordinate of vertex 2
        v2z - Z coordinate of vertex 2
        v0u - U coordinate of vertex 0
        v0v - V coordinate of vertex 0
        v1u - U coordinate of vertex 1
        v1v - V coordinate of vertex 1
        v2u - U coordinate of vertex 2
        v2v - V coordinate of vertex 2
        Returns:
        Tangent as float array [x, y, z]