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.

Macros#

NV_VEC2(x, y)#

Initialize vector.

Parameters:
  • x – X component

  • y – Y component

Returns:

nvVector2

static inline nvVector2 *NV_VEC2_NEW(nv_float x, nv_float y)#

Initialize and store vector on HEAP.

Parameters:
  • x – X component

  • y – Y component

Returns:

nvVector2 *

NV_TO_VEC2(x)#

Cast void * to nvVector2.

This is useful for directly passing indexed data from nvArray

Parameters:
  • x – Vector

Returns:

nvVector2

NV_TO_VEC2P(x)#

Cast void * to nvVector2 pointer.

This is useful for modifying vector elements of nvArray

Parameters:
  • x – Vector

Returns:

nvVector2 *

Methods#

static inline bool nvVector2_eq(nvVector2 a, nvVector2 b)#

Check if two vectors are equal.

Parameters:
  • a – Left-hand vector

  • b – Right-hand vector

Returns:

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