Shape

struct nvShape

Collision shape.

Do not initialize manually. Use shape creation functions.

Enums

enum nvShapeType

Shape type enumerator.

Values:

enumerator nvShapeType_CIRCLE

Circle is the simplest collision shape.

enumerator nvShapeType_POLYGON

Convex polygon shape. It’s more complex than circle shape and the calculations gets more expensive as the vertex count goes higher.

Methods

nvShape *nvCircleShape_new(nvVector2 center, nv_float radius)

Create a new circle shape.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • center – Center position relative to body position

  • radius – Radius

Returns:

nvShape *

nvShape *nvPolygonShape_new(nvVector2 *vertices, size_t num_vertices, nvVector2 offset)

Create a new convex polygon shape.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • vertices – Array of vertices

  • offset – Offset to centroid

Returns:

nvShape *

nvShape *nvRectShape_new(nv_float width, nv_float height, nvVector2 offset)

Create a new polygon shape that is a rectangle.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • width – Width

  • height – Height

  • offset – Offset to centroid

Returns:

nvShape *

nvBoxShape_new(width, height, offset)

Create a new polygon shape that is a rectangle.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • width – Width

  • height – Height

  • offset – Offset to centroid

Returns:

nvShape *

nvShape *nvNGonShape_new(size_t n, nv_float radius, nvVector2 offset)

Create a new polygon shape that is a regular n-gon.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • n – Number of vertices or edges

  • radius – Length of a vertex from the centroid

  • offset – Offset to centroid

Returns:

nvShape *

nvShape *nvConvexHullShape_new(nvVector2 *points, size_t num_points, nvVector2 offset, nv_bool center)

Create a new polygon shape from a convex hull of an array of points.

Returns NULL on error. Use nv_get_error to get more information.

Parameters:
  • points – Points to generate a convex hull from

  • num_points – Number of points

  • offset – Offset to centroid

  • bool – Transform hull so the centroid is at origin?

Returns:

nvShape *

void nvShape_free(nvShape *shape)

Free shape.

It’s safe to pass NULL to this function.

Parameters:

shape – Shape

nvAABB nvShape_get_aabb(nvShape *shape, nvTransform xform)

Get AABB of shape.

Parameters:
  • shape – Shape

  • xform – Shape transform

Returns:

nvAABB

nvShapeMassInfo nvShape_calculate_mass(nvShape *shape, nv_float density)

Calculate mass information of shape.

Returns a struct filled with -1 on error. Use nv_get_error to get more information.

Parameters:

shape – Shape

Returns:

nvShapeMassInfo

void nvPolygon_transform(nvShape *shape, nvTransform xform)

Transform the polygon shape vertices.

Parameters:
  • shape – Shape

  • xform – Transform