Class Vec2

All Implemented Interfaces:
PointerInterface

public class Vec2 extends Record
A structure capable of holding a vector with two dimensions, x and y.

The contents of the #graphene_vec2_t structure are private and should
never be accessed directly.

https://ebassi.github.io/graphene/docs/

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • allocVec2

      public static Vec2 allocVec2()
      Allocates a new #graphene_vec2_t structure.

      The contents of the returned structure are undefined.

      Use graphene_vec2_init() to initialize the vector.
      Returns:
      the newly allocated #graphene_vec2_t structure. Use graphene_vec2_free() to free the resources allocated by this function.
    • add

      public void add(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Adds each component of the two passed vectors and places
      each result into the components of @res.
      Parameters:
      b - a #graphene_vec2_t
      res - return location for the result
    • divide

      public void divide(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Divides each component of the first operand @a by the corresponding
      component of the second operand @b, and places the results into the
      vector @res.
      Parameters:
      b - a #graphene_vec2_t
      res - return location for the result
    • dot

      public float dot(@Nonnull Vec2 b)
      Computes the dot product of the two given vectors.
      Parameters:
      b - a #graphene_vec2_t
      Returns:
      the dot product of the vectors
    • equal

      public boolean equal(@Nonnull Vec2 v2)
      Checks whether the two given #graphene_vec2_t are equal.
      Parameters:
      v2 - a #graphene_vec2_t
      Returns:
      `true` if the two vectors are equal, and false otherwise
    • free

      public void free()
      Frees the resources allocated by @v
    • getX

      public float getX()
      Retrieves the X component of the #graphene_vec2_t.
      Returns:
      the value of the X component
    • getY

      public float getY()
      Retrieves the Y component of the #graphene_vec2_t.
      Returns:
      the value of the Y component
    • init

      public Vec2 init(float x, float y)
      Initializes a #graphene_vec2_t using the given values.

      This function can be called multiple times.
      Parameters:
      x - the X field of the vector
      y - the Y field of the vector
      Returns:
      the initialized vector
    • initFromVec2

      public Vec2 initFromVec2(@Nonnull Vec2 src)
      Copies the contents of @src into @v.
      Parameters:
      src - a #graphene_vec2_t
      Returns:
      the initialized vector
    • interpolate

      public void interpolate(@Nonnull Vec2 v2, double factor, @Nonnull Vec2 res)
      Linearly interpolates @v1 and @v2 using the given @factor.
      Parameters:
      v2 - a #graphene_vec2_t
      factor - the interpolation factor
      res - the interpolated vector
    • length

      public float length()
      Computes the length of the given vector.
      Returns:
      the length of the vector
    • max

      public void max(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Compares the two given vectors and places the maximum
      values of each component into @res.
      Parameters:
      b - a #graphene_vec2_t
      res - the resulting vector
    • min

      public void min(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Compares the two given vectors and places the minimum
      values of each component into @res.
      Parameters:
      b - a #graphene_vec2_t
      res - the resulting vector
    • multiply

      public void multiply(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Multiplies each component of the two passed vectors and places
      each result into the components of @res.
      Parameters:
      b - a #graphene_vec2_t
      res - return location for the result
    • near

      public boolean near(@Nonnull Vec2 v2, float epsilon)
      Compares the two given #graphene_vec2_t vectors and checks
      whether their values are within the given @epsilon.
      Parameters:
      v2 - a #graphene_vec2_t
      epsilon - the threshold between the two vectors
      Returns:
      `true` if the two vectors are near each other
    • negate

      public void negate(@Nonnull Vec2 res)
      Negates the given #graphene_vec2_t.
      Parameters:
      res - return location for the result vector
    • normalize

      public void normalize(@Nonnull Vec2 res)
      Computes the normalized vector for the given vector @v.
      Parameters:
      res - return location for the normalized vector
    • scale

      public void scale(float factor, @Nonnull Vec2 res)
      Multiplies all components of the given vector with the given scalar @factor.
      Parameters:
      factor - the scalar factor
      res - return location for the result vector
    • subtract

      public void subtract(@Nonnull Vec2 b, @Nonnull Vec2 res)
      Subtracts from each component of the first operand @a the
      corresponding component of the second operand @b and places
      each result into the components of @res.
      Parameters:
      b - a #graphene_vec2_t
      res - return location for the result
    • toFloat

      public void toFloat(@Nonnull Flt dest)
      Stores the components of @v into an array.
      Parameters:
      dest - return location for an array of floating point values with at least 2 elements
    • one

      public static Vec2 one()
      Retrieves a constant vector with (1, 1) components.
      Returns:
      the one vector
    • xAxis

      public static Vec2 xAxis()
      Retrieves a constant vector with (1, 0) components.
      Returns:
      the X axis vector
    • yAxis

      public static Vec2 yAxis()
      Retrieves a constant vector with (0, 1) components.
      Returns:
      the Y axis vector
    • zero

      public static Vec2 zero()
      Retrieves a constant vector with (0, 0) components.
      Returns:
      the zero vector
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()