Class Vec3

java.lang.Object
eu.iv4xr.framework.spatial.Vec3
All Implemented Interfaces:
Serializable

public class Vec3 extends Object implements Serializable
This is a simple 3D vector implementation using floats.
Author:
Naraenda
See Also:
Serialized Form
  • Field Details

    • x

      public float x
    • y

      public float y
    • z

      public float z
  • Constructor Details

    • Vec3

      public Vec3(float x, float y, float z)
      Construct a new vector with three floating point values.
      Parameters:
      x - : The 'x' component
      y - : The 'y' component
      z - : The 'z' component
    • Vec3

      public Vec3(float c)
      Construct a vector containg the same constant value for each of the components.
      Parameters:
      c - : the constant value.
  • Method Details

    • copy

      public Vec3 copy()
      Copies a vector by value.
      Returns:
      New instance of the current vector.
    • zero

      public static Vec3 zero()
      Returns:
      Vec3 {0, 0, 0}
    • one

      public static Vec3 one()
      Returns:
      Vec3 {1, 1, 1}
    • add

      public static Vec3 add(Vec3 a, Vec3 b)
      Returns:
      A + B
    • sub

      public static Vec3 sub(Vec3 a, Vec3 b)
      Returns:
      A - B
    • mul

      public static Vec3 mul(Vec3 a, Vec3 b)
      Returns:
      A * B
    • mul

      public static Vec3 mul(Vec3 a, float c)
      Parameters:
      a - Vector
      c - Scalar
      Returns:
      c * A
    • div

      public static Vec3 div(Vec3 a, float c)
      Parameters:
      a - Vector
      c - Scalar
      Returns:
      (1/c) * A
    • dot

      public static float dot(Vec3 a, Vec3 b)
      Returns:
      A.x * B.x + A.y * B.y + A.z * B.z
    • dist

      public static float dist(Vec3 a, Vec3 b)
      Returns:
      The distance between two vectors a and b. This is the length of the vector a - b.
    • distSq

      public static float distSq(Vec3 a, Vec3 b)
      If d is the length of the vector a - b (so, the distance between them), this method returns d*d. This is cheaper to compute that d itself.
    • cross

      public static Vec3 cross(Vec3 a, Vec3 b)
      Returns:
      The cross product between two vectors.
    • lengthSq

      public float lengthSq()
      Returns:
      The squared distance of this vector.
    • length

      public float length()
      Returns:
      The length of this vector.
    • normalized

      public Vec3 normalized()
      Returns:
      A normalized copy of this vector.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object