Vector2

struct nvVector2

2D vector type.

Public Members

nv_float x

X component of the vector.

nv_float y

Y component of the vector.

static const nvVector2 nvVector2_zero = {0.0, 0.0}

Constant zero vector.

NV_VECTOR2(x, y)

Initialize nvVector2 literal.

Parameters:
  • x – X component

  • y – Y component

Returns:

nvVector2

Methods

static inline nv_bool nvVector2_eq(nvVector2 a, nvVector2 b)

Check if two vectors are equal.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nv_bool

static inline nvVector2 nvVector2_add(nvVector2 a, nvVector2 b)

Add two vectors.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nvVector2

static inline nvVector2 nvVector2_sub(nvVector2 a, nvVector2 b)

Subtract two vectors.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nvVector2

static inline nvVector2 nvVector2_mul(nvVector2 v, nv_float s)

Multiply vector by scalar.

Parameters:
  • v – Vector

  • s – Scalar

Returns:

nvVector2

static inline nvVector2 nvVector2_div(nvVector2 v, nv_float s)

Divide vector by scalar.

Parameters:
  • v – Vector

  • s – Scalar

Returns:

nvVector2

static inline nvVector2 nvVector2_neg(nvVector2 v)

Negate a vector.

Parameters:

v – Vector to negate

Returns:

nvVector2

static inline nvVector2 nvVector2_rotate(nvVector2 v, nv_float a)

Rotate vector around the origin.

Parameters:
  • v – Vector to rotate

  • a – Angle in radians

Returns:

nvVector2

static inline nvVector2 nvVector2_perp(nvVector2 v)

Perpendicular vector (+90 degrees).

Parameters:
  • v – Vector

  • a – Angle in radians

Returns:

nvVector2

static inline nvVector2 nvVector2_perpr(nvVector2 v)

Perpendicular vector (-90 degrees).

Parameters:

v – Vector

Returns:

nvVector2

static inline nv_float nvVector2_len2(nvVector2 v)

Calculate squared length (magnitude) of a vector.

Parameters:

v – Vector

Returns:

nv_float

static inline nv_float nvVector2_len(nvVector2 v)

Calculate length (magnitude) of a vector.

Parameters:

v – Vector

Returns:

nv_float

static inline nv_float nvVector2_dot(nvVector2 a, nvVector2 b)

Dot product of two vectors.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nv_float

static inline nv_float nvVector2_cross(nvVector2 a, nvVector2 b)

Z component of cross product of two vectors.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nv_float

static inline nv_float nvVector2_dist2(nvVector2 a, nvVector2 b)

Squared distance from one vector to another.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nv_float

static inline nv_float nvVector2_dist(nvVector2 a, nvVector2 b)

Distance from one vector to another.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

nv_float

static inline nvVector2 nvVector2_normalize(nvVector2 v)

Normalize a vector.

Parameters:

v – Vector to normalize

Returns:

nvVector2

static inline nvVector2 nvVector2_lerp(nvVector2 a, nvVector2 b, nv_float t)

Lerp between two vectors.

Parameters:
  • a – First vector

  • b – Second vector

  • t – Interpolation amount [0, 1]

Returns:

nvVector2

static inline nv_bool nvVector2_is_zero(nvVector2 v)

Is the vector a zero vector?

Parameters:

v – Vector

Returns:

nv_bool