Class Vec4f

  • public final class Vec4f
    extends Object
    4D Vector based upon four float components. Implementation borrowed from [gfxbox2]( and its data layout from JOAL's Vec3f.
    • Constructor Detail

      • Vec4f

        public Vec4f()
      • Vec4f

        public Vec4f​(Vec4f o)
      • Vec4f

        public Vec4f​(Vec3f o,
                     float w)
        Creating new Vec4f using { o, w }.
      • Vec4f

        public Vec4f​(float[] xyzw)
      • Vec4f

        public Vec4f​(float x,
                     float y,
                     float z,
                     float w)
    • Method Detail

      • copy

        public Vec4f copy()
      • set

        public Vec4f set​(Vec4f o)
        this = o, returns this.
      • set

        public Vec4f set​(Vec3f o,
                         float w)
        this = { o, w }, returns this.
      • set

        public Vec4f set​(float x,
                         float y,
                         float z,
                         float w)
        this = { x, y, z, w }, returns this.
      • set

        public Vec4f set​(float[] xyzw)
        this = xyzw, returns this.
      • set

        public void set​(int i,
                        float val)
        Sets the ith component, 0 <= i < 4
      • get

        public float[] get​(float[] xyzw)
        xyzw = this, returns xyzw.
      • get

        public float get​(int i)
        Gets the ith component, 0 <= i < 4
      • x

        public float x()
      • y

        public float y()
      • z

        public float z()
      • w

        public float w()
      • setX

        public void setX​(float x)
      • setY

        public void setY​(float y)
      • setZ

        public void setZ​(float z)
      • setW

        public void setW​(float w)
      • max

        public Vec4f max​(Vec4f m)
        this = max(this, m), returns this.
      • min

        public Vec4f min​(Vec4f m)
        this = min(this, m), returns this.
      • mul

        public Vec4f mul​(float val)
        Returns this * val; creates new vector
      • mul

        public Vec4f mul​(Vec4f a,
                         Vec4f b)
        this = a * b, returns this.
      • scale

        public Vec4f scale​(float s)
        this = this * s, returns this.
      • scale

        public Vec4f scale​(float sx,
                           float sy,
                           float sz,
                           float sw)
        this = this * { sx, sy, sz, sw }, returns this.
      • plus

        public Vec4f plus​(Vec4f arg)
        Returns this + arg; creates new vector
      • plus

        public Vec4f plus​(Vec4f a,
                          Vec4f b)
        this = a + b, returns this.
      • add

        public Vec4f add​(float dx,
                         float dy,
                         float dz,
                         float dw)
        this = this + { dx, dy, dz, dw }, returns this.
      • add

        public Vec4f add​(Vec4f b)
        this = this + b, returns this.
      • minus

        public Vec4f minus​(Vec4f arg)
        Returns this - arg; creates new vector
      • minus

        public Vec4f minus​(Vec4f a,
                           Vec4f b)
        this = a - b, returns this.
      • sub

        public Vec4f sub​(Vec4f b)
        this = this - b, returns this.
      • isZero

        public boolean isZero()
        Return true if all components are zero, i.e. it's absolute value < #EPSILON.
      • length

        public float length()
        Return the length of this vector, a.k.a the norm or magnitude
      • lengthSq

        public float lengthSq()
        Return the squared length of this vector, a.k.a the squared norm or squared magnitude
      • normalize

        public Vec4f normalize()
        Normalize this vector in place
      • distSq

        public float distSq​(Vec4f o)
        Return the squared distance between this vector and the given one.

        When comparing the relative distance between two points it is usually sufficient to compare the squared distances, thus avoiding an expensive square root operation.

      • dist

        public float dist​(Vec4f o)
        Return the distance between this vector and the given one.
      • dot

        public float dot​(Vec4f o)
        Return the dot product of this vector and the given one
        the dot product as float
      • cosAngle

        public float cosAngle​(Vec4f o)
        Return the cosines of the angle between two vectors
      • angle

        public float angle​(Vec4f o)
        Return the angle between two vectors in radians
      • isEqual

        public boolean isEqual​(Vec4f o,
                               float epsilon)
        Equals check using a given FloatUtil.EPSILON value and FloatUtil.isEqual(float, float, float).

        Implementation considers following corner cases:

        • NaN == NaN
        • +Inf == +Inf
        • -Inf == -Inf
        o - comparison value
        epsilon - consider using FloatUtil.EPSILON
        true if all components differ less than epsilon, otherwise false.