Skip to content

Physics

Functions

Bitmap Circle Collision

Bitmap Circle Collision

Tests if a bitmap drawn at pt would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, const point_2d &pt, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap drawn at x, y would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, double x, double y, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a circle. You can use this to detect collisions between bitmaps and circles.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, const matrix_2d &translation, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn at pt would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, const point_2d &pt, const circle &circ)

Bitmap Circle Collision

Tests if a bitmap cell drawn at x, y would intersect with a circle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
circCircleThe circle to test

Return Type: Boolean

Signatures:

bool bitmap_circle_collision(bitmap bmp, int cell, double x, double y, const circle &circ)

Bitmap Collision

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
x1DoubleThe x location where the first bitmap is drawn
y1DoubleThe y location where the first bitmap is drawn
bmp2BitmapThe second bitmap
x2DoubleThe x location where the second bitmap is drawn
y2DoubleThe y location where the second bitmap is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, double x1, double y1, bitmap bmp2, double x2, double y2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
pt1Point 2dThe point where bitmap 1 is drawn
bmp2BitmapThe second bitmap
pt2Point 2dThe point where bitmap 2 is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, const point_2d &pt1, bitmap bmp2, const point_2d &pt2)

Bitmap Collision

Check if two bitmaps collide, based on their cell and transform matricies.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
matrix1Matrix 2dThe transformation for the first matrix
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
matrix2Matrix 2dThe transformation for the second matrix

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, const matrix_2d &matrix1, bitmap bmp2, int cell2, const matrix_2d &matrix2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
pt1Point 2dThe point where bitmap 1 is drawn
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
pt2Point 2dThe point where bitmap 2 is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, const point_2d &pt1, bitmap bmp2, int cell2, const point_2d &pt2)

Bitmap Collision

Check if two bitmaps collide.

Parameters:

NameTypeDescription
bmp1BitmapThe first bitmap
cell1IntegerThe cell of the first bitmap.
x1DoubleThe x location where the first bitmap is drawn
y1DoubleThe y location where the first bitmap is drawn
bmp2BitmapThe second bitmap
cell2IntegerThe cell of the second bitmap.
x2DoubleThe x location where the second bitmap is drawn
y2DoubleThe y location where the second bitmap is drawn

Return Type: Boolean

Signatures:

bool bitmap_collision(bitmap bmp1, int cell1, double x1, double y1, bitmap bmp2, int cell2, double x2, double y2)

Bitmap Point Collision

Bitmap Point Collision

Tests if a bitmap drawn using the passed in translation matrix would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
translationMatrix 2dThe translation matrix that represents the position, scale, and rotation of the bitmap when it is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, const matrix_2d &translation, const point_2d &pt)

Bitmap Point Collision

Tests if a bitmap drawn at the bmp_pt point would draw a pixel at point pt. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
bmp_ptPoint 2dThe point where the bitmap is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, const point_2d &bmp_pt, const point_2d &pt)

Bitmap Point Collision

Tests if a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
bmp_xDoubleThe x location where the bitmap is drawn
bmp_yDoubleThe y location where the bitmap is drawn
xDoubleThe x location of the point to test
yDoubleThe y location of the point to test

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, double bmp_x, double bmp_y, double x, double y)

Bitmap Point Collision

Tests if a bitmap cell drawn using the passed in translation matrix would draw a pixel at the passed in point.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test.
cellIntegerThe cell of the bitmap to check.
translationMatrix 2dThe translation matrix that represents the position, scale, and rotation of the bitmap when it is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, const matrix_2d &translation, const point_2d &pt)

Bitmap Point Collision

Tests if a cell of a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to test
bmp_ptPoint 2dThe point where the bitmap is drawn.
ptPoint 2dThe point in the resulting drawing that is being tested.

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, const point_2d &bmp_pt, const point_2d &pt)

Bitmap Point Collision

Tests if a cell of a bitmap drawn at x,y would draw a pixel at the passed in point. Use to check collisions between a point and a bitmap.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to test
bmp_xDoubleThe x location where the bitmap is drawn
bmp_yDoubleThe y location where the bitmap is drawn
xDoubleThe x location of the point to test
yDoubleThe y location of the point to test

Return Type: Boolean

Signatures:

bool bitmap_point_collision(bitmap bmp, int cell, double bmp_x, double bmp_y, double x, double y)

Bitmap Quad Collision

Bitmap Quad Collision

Tests if a bitmap drawn at pt would intersect with a quad.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
qQuadThe quad to test

Return Type: Boolean

Signatures:

bool bitmap_quad_collision(bitmap bmp, const point_2d &pt, const quad &q)

Bitmap Quad Collision

Tests if a bitmap drawn at x, y would intersect with a quad.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
qQuadThe quad to test

Return Type: Boolean

Signatures:

bool bitmap_quad_collision(bitmap bmp, double x, double y, const quad &q)

Bitmap Quad Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a quad. You can use this to detect collisions between bitmaps and quads.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
qQuadThe quad to test

Return Type: Boolean

Signatures:

bool bitmap_quad_collision(bitmap bmp, int cell, const matrix_2d &translation, const quad &q)

Bitmap Quad Collision

Tests if a bitmap cell drawn at pt would intersect with a quad.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
qQuadThe quad to test

Return Type: Boolean

Signatures:

bool bitmap_quad_collision(bitmap bmp, int cell, const point_2d &pt, const quad &q)

Bitmap Quad Collision

Tests if a bitmap cell drawn at x, y would intersect with a quad.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
qQuadThe quad to test

Return Type: Boolean

Signatures:

bool bitmap_quad_collision(bitmap bmp, int cell, double x, double y, const quad &q)

Bitmap Ray Collision

Bitmap Ray Collision

Tests if a bitmap drawn at pt would intersect with a ray.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool bitmap_ray_collision(bitmap bmp, const point_2d &pt, const point_2d &origin, const vector_2d &heading)

Bitmap Ray Collision

Tests if a bitmap drawn at x, y would intersect with a ray.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool bitmap_ray_collision(bitmap bmp, double x, double y, const point_2d &origin, const vector_2d &heading)

Bitmap Ray Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a ray. You can use this to detect collisions between bitmaps and rays.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool bitmap_ray_collision(bitmap bmp, int cell, const matrix_2d &translation, const point_2d &origin, const vector_2d &heading)

Bitmap Ray Collision

Tests if a bitmap cell drawn at pt would intersect with a ray.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool bitmap_ray_collision(bitmap bmp, int cell, const point_2d &pt, const point_2d &origin, const vector_2d &heading)

Bitmap Ray Collision

Tests if a bitmap cell drawn at x, y would intersect with a ray.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool bitmap_ray_collision(bitmap bmp, int cell, double x, double y, const point_2d &origin, const vector_2d &heading)

Bitmap Rectangle Collision

Bitmap Rectangle Collision

Tests if a bitmap drawn at pt would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, const point_2d &pt, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap drawn at x, y would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, double x, double y, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a rectangle. You can use this to detect collisions between bitmaps and rectangles.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, const matrix_2d &translation, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a bitmap cell drawn at pt would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, const point_2d &pt, const rectangle &rect)

Bitmap Rectangle Collision

Tests if a cell of the bitmap drawn at x, y would intersect with a rectangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
rectRectangleThe rectangle to test

Return Type: Boolean

Signatures:

bool bitmap_rectangle_collision(bitmap bmp, int cell, double x, double y, const rectangle &rect)

Bitmap Triangle Collision

Bitmap Triangle Collision

Tests if a bitmap drawn at pt would intersect with a triangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
ptPoint 2dThe location where the bitmap is drawn
triTriangleThe triangle to test

Return Type: Boolean

Signatures:

bool bitmap_triangle_collision(bitmap bmp, const point_2d &pt, const triangle &tri)

Bitmap Triangle Collision

Tests if a bitmap drawn at x, y would intersect with a triangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
triTriangleThe triangle to test

Return Type: Boolean

Signatures:

bool bitmap_triangle_collision(bitmap bmp, double x, double y, const triangle &tri)

Bitmap Triangle Collision

Tests if a bitmap cell drawn using a passed in translation, will intersect with a triangle. You can use this to detect collisions between bitmaps and triangles.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
translationMatrix 2dThe matrix used to transfrom the bitmap when drawing
triTriangleThe triangle to test

Return Type: Boolean

Signatures:

bool bitmap_triangle_collision(bitmap bmp, int cell, const matrix_2d &translation, const triangle &tri)

Bitmap Triangle Collision

Tests if a bitmap cell drawn at pt would intersect with a triangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe location where the bitmap is drawn
triTriangleThe triangle to test

Return Type: Boolean

Signatures:

bool bitmap_triangle_collision(bitmap bmp, int cell, const point_2d &pt, const triangle &tri)

Bitmap Triangle Collision

Tests if a bitmap cell drawn at x, y would intersect with a triangle.

Parameters:

NameTypeDescription
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn
triTriangleThe triangle to test

Return Type: Boolean

Signatures:

bool bitmap_triangle_collision(bitmap bmp, int cell, double x, double y, const triangle &tri)

Calculate Collision Direction

Calculate Collision Direction

Returns the direction of the collision between a collider quad and a collidee quad relative to the collider quad. If the quads are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderQuadThe quad that is colliding
collideeQuadThe quad that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const quad &collider, const quad &collidee)

Calculate Collision Direction

Returns the direction of the collision between a collider circle and a collidee circle relative to the collider circle. If the circles are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderCircleThe circle that is colliding
collideeCircleThe circle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const circle &collider, const circle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a circle and a quad relative to the circle. If the circle and quad are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderCircleThe circle that is colliding
collideeQuadThe quad that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const circle &collider, const quad &collidee)

Calculate Collision Direction

Returns the direction of the collision between a circle and a rectangle relative to the circle. If the circle and rectangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderCircleThe circle that is colliding
collideeRectangleThe rectangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const circle &collider, const rectangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a circle and a sprite relative to the circle. If the circle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderCircleThe circle that is colliding
collideeSpriteThe sprite that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const circle &collider, const sprite collidee)

Calculate Collision Direction

Returns the direction of the collision between a circle and a triangle relative to the circle. If the circle and triangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderCircleThe circle that is colliding
collideeTriangleThe triangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const circle &collider, const triangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a quad and a circle relative to the quad. If the quad and circle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderQuadThe quad that is colliding
collideeCircleThe circle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const quad &collider, const circle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a quad and a rectangle relative to the quad. If the quad and rectangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderQuadThe quad that is colliding
collideeRectangleThe rectangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const quad &collider, const rectangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a quad and a sprite relative to the quad. If the quad and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderQuadThe quad that is colliding
collideeSpriteThe sprite that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const quad &collider, const sprite collidee)

Calculate Collision Direction

Returns the direction of the collision between a quad and a triangle relative to the quad. If the quad and triangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderQuadThe quad that is colliding
collideeTriangleThe triangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const quad &collider, const triangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a rectangle and a circle relative to the rectangle. If the rectangle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle that is colliding
collideeCircleThe circle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const rectangle &collider, const circle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a rectangle and a quad relative to the rectangle. If the rectangle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle that is colliding
collideeQuadThe quad that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const rectangle &collider, const quad &collidee)

Calculate Collision Direction

Returns the direction of the collision between a collider rectangle and a collidee rectangle relative to the collider rectangle. If the rectangles are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle that is colliding
collideeRectangleThe rectangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const rectangle &collider, const rectangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a rectangle and a sprite relative to the rectangle. If the rectangle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle that is colliding
collideeSpriteThe sprite that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const rectangle &collider, const sprite collidee)

Calculate Collision Direction

Returns the direction of the collision between a rectangle and a triangle relative to the rectangle. If the rectangle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle that is colliding
collideeTriangleThe triangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const rectangle &collider, const triangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a sprite and a circle relative to the sprite. If the sprite and circle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderSpriteThe sprite that is colliding
collideeCircleThe circle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const sprite collider, const circle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a sprite and a quad relative to the sprite. If the sprite and quad are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderSpriteThe sprite that is colliding
collideeQuadThe quad that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const sprite collider, const quad &collidee)

Calculate Collision Direction

Returns the direction of the collision between a sprite and a rectangle relative to the sprite. If the sprite and rectangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderSpriteThe sprite that is colliding
collideeRectangleThe rectangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const sprite collider, const rectangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between two sprites relative to the collider sprite. If the sprites are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderSpriteThe sprite that is colliding
collideeSpriteThe sprite that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const sprite collider, const sprite collidee)

Calculate Collision Direction

Returns the direction of the collision between a sprite and a triangle relative to the sprite. If the sprite and triangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderSpriteThe sprite that is colliding
collideeTriangleThe triangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const sprite collider, const triangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a triangle and a circle relative to the triangle. If the triangle and circle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderTriangleThe triangle that is colliding
collideeCircleThe circle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const triangle &collider, const circle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a triangle and a quad relative to the triangle. If the triangle and quad are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderTriangleThe triangle that is colliding
collideeQuadThe quad that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const triangle &collider, const quad &collidee)

Calculate Collision Direction

Returns the direction of the collision between a triangle and a rectangle relative to the triangle. If the triangle and rectangle are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderTriangleThe triangle that is colliding
collideeRectangleThe rectangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const triangle &collider, const rectangle &collidee)

Calculate Collision Direction

Returns the direction of the collision between a triangle and a sprite relative to the triangle. If the triangle and sprite are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderTriangleThe triangle that is colliding
collideeSpriteThe sprite that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const triangle &collider, const sprite collidee)

Calculate Collision Direction

Returns the direction of the collision between a collider triangle and a collidee triangle relative to the collider triangle. If the triangles are not colliding, this function will return a zero vector.

Parameters:

NameTypeDescription
colliderTriangleThe triangle that is colliding
collideeTriangleThe triangle that is being collided with

Return Type: Vector 2d

Signatures:

vector_2d calculate_collision_direction(const triangle &collider, const triangle &collidee)

Resolve Collision

Resolve Collision

Resolves the collision between a collider quad and a collidee quad by moving the collider quad to the edge of the collidee quad. The direction of the resolution is determined by the direction parameter. If the quads are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderQuadThe quad which will be altered if there is a collision
collideeQuadThe quad which will not be altered
directionVector 2dThe direction of the collision relative to the collider quad, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(quad &collider, const quad &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a collider circle and a collidee circle by moving the collider circle to the edge of the collidee circle. The direction of the resolution is determined by the direction parameter. If the circles are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderCircleThe circle which will be altered if there is a collision
collideeCircleThe circle which will not be altered
directionVector 2dThe direction of the collision relative to the collider circle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(circle &collider, const circle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a circle and a quad by moving the circle to the edge of the quad. The direction of the resolution is determined by the direction parameter. If the circle and quad are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderCircleThe circle which will be altered if there is a collision
collideeQuadThe quad which will not be altered
directionVector 2dThe direction of the collision relative to the circle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(circle &collider, const quad &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a circle and a rectangle by moving the circle to the edge of the rectangle. The direction of the resolution is determined by the direction parameter. If the circle and rectangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderCircleThe circle which will be altered if there is a collision
collideeRectangleThe rectangle which will not be altered
directionVector 2dThe direction of the collision relative to the circle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(circle &collider, const rectangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a circle and a sprite by moving the circle to the edge of the sprite. The direction of the resolution is determined by the direction parameter. If the circle and sprite are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderCircleThe circle which will be altered if there is a collision
collideeSpriteThe sprite which will not be altered
directionVector 2dThe direction of the collision relative to the circle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(circle &collider, const sprite collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a circle and a triangle by moving the circle to the edge of the triangle. The direction of the resolution is determined by the direction parameter. If the circle and triangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderCircleThe circle which will be altered if there is a collision
collideeTriangleThe triangle which will not be altered
directionVector 2dThe direction of the collision relative to the circle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(circle &collider, const triangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a quad and a circle by moving the quad to the edge of the circle. The direction of the resolution is determined by the direction parameter. If the quad and circle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderQuadThe quad which will be altered if there is a collision
collideeCircleThe circle which will not be altered
directionVector 2dThe direction of the collision relative to the quad, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(quad &collider, const circle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a quad and a rectangle by moving the quad to the edge of the rectangle. The direction of the resolution is determined by the direction parameter. If the quad and rectangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderQuadThe quad which will be altered if there is a collision
collideeRectangleThe rectangle which will not be altered
directionVector 2dThe direction of the collision relative to the quad, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(quad &collider, const rectangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a quad and a sprite by moving the quad to the edge of the sprite. The direction of the resolution is determined by the direction parameter. If the quad and sprite are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderQuadThe quad which will be altered if there is a collision
collideeSpriteThe sprite which will not be altered
directionVector 2dThe direction of the collision relative to the quad, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(quad &collider, const sprite collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a quad and a triangle by moving the quad to the edge of the triangle. The direction of the resolution is determined by the direction parameter. If the quad and triangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderQuadThe quad which will be altered if there is a collision
collideeTriangleThe triangle which will not be altered
directionVector 2dThe direction of the collision relative to the quad, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(quad &collider, const triangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a rectangle and a circle by moving the rectangle to the edge of the circle. The direction of the resolution is determined by the direction parameter. If the rectangle and circle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle which will be altered if there is a collision
collideeCircleThe circle which will not be altered
directionVector 2dThe direction of the collision relative to the rectangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(rectangle &collider, const circle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a rectangle and a quad by moving the rectangle to the edge of the quad. The direction of the resolution is determined by the direction parameter. If the rectangle and quad are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle which will be altered if there is a collision
collideeQuadThe quad which will not be altered
directionVector 2dThe direction of the collision relative to the rectangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(rectangle &collider, const quad &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between two rectangles by moving the collider rectangle to the edge of the collidee rectangle. The direction of the resolution is determined by the direction parameter. If the rectangles are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle which will be altered if there is a collision
collideeRectangleThe rectangle which will not be altered
directionVector 2dThe direction of the collision relative to the collider rectangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(rectangle &collider, const rectangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a rectangle and a sprite by moving the rectangle to the edge of the sprite. The direction of the resolution is determined by the direction parameter. If the rectangle and sprite are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle which will be altered if there is a collision
collideeSpriteThe sprite which will not be altered
directionVector 2dThe direction of the collision relative to the rectangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(rectangle &collider, const sprite collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a rectangle and a triangle by moving the rectangle to the edge of the triangle. The direction of the resolution is determined by the direction parameter. If the rectangle and triangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderRectangleThe rectangle which will be altered if there is a collision
collideeTriangleThe triangle which will not be altered
directionVector 2dThe direction of the collision relative to the rectangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(rectangle &collider, const triangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a sprite and a circle by moving the sprite to the edge of the circle. The direction of the resolution is determined by the direction parameter. If the sprite and circle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderSpriteThe sprite which will be altered if there is a collision
collideeCircleThe circle which will not be altered
directionVector 2dThe direction of the collision relative to the sprite, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(sprite collider, const circle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a sprite and a quad by moving the sprite to the edge of the quad. The direction of the resolution is determined by the direction parameter. If the sprite and quad are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderSpriteThe sprite which will be altered if there is a collision
collideeQuadThe quad which will not be altered
directionVector 2dThe direction of the collision relative to the sprite, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(sprite collider, const quad &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a sprite and a rectangle by moving the sprite to the edge of the rectangle. The direction of the resolution is determined by the direction parameter. If the sprite and rectangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderSpriteThe sprite which will be altered if there is a collision
collideeRectangleThe rectangle which will not be altered
directionVector 2dThe direction of the collision relative to the sprite, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(sprite collider, const rectangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between two sprites by moving the collider sprite to the edge of the collidee sprite. The direction of the resolution is determined by the direction parameter. If the sprites are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderSpriteThe sprite which will be altered if there is a collision
collideeSpriteThe sprite which will not be altered
directionVector 2dThe direction of the collision relative to the collider sprite, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(sprite collider, const sprite collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a sprite and a triangle by moving the sprite to the edge of the triangle. The direction of the resolution is determined by the direction parameter. If the sprite and triangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderSpriteThe sprite which will be altered if there is a collision
collideeTriangleThe triangle which will not be altered
directionVector 2dThe direction of the collision relative to the sprite, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(sprite collider, const triangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a triangle and a circle by moving the triangle to the edge of the circle. The direction of the resolution is determined by the direction parameter. If the triangle and circle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderTriangleThe triangle which will be altered if there is a collision
collideeCircleThe circle which will not be altered
directionVector 2dThe direction of the collision relative to the triangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(triangle &collider, const circle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a triangle and a quad by moving the triangle to the edge of the quad. The direction of the resolution is determined by the direction parameter. If the triangle and quad are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderTriangleThe triangle which will be altered if there is a collision
collideeQuadThe quad which will not be altered
directionVector 2dThe direction of the collision relative to the triangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(triangle &collider, const quad &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a triangle and a rectangle by moving the triangle to the edge of the rectangle. The direction of the resolution is determined by the direction parameter. If the triangle and rectangle are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderTriangleThe triangle which will be altered if there is a collision
collideeRectangleThe rectangle which will not be altered
directionVector 2dThe direction of the collision relative to the triangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(triangle &collider, const rectangle &collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a triangle and a sprite by moving the triangle to the edge of the sprite. The direction of the resolution is determined by the direction parameter. If the triangle and sprite are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderTriangleThe triangle which will be altered if there is a collision
collideeSpriteThe sprite which will not be altered
directionVector 2dThe direction of the collision relative to the triangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(triangle &collider, const sprite collidee, const vector_2d &direction)

Resolve Collision

Resolves the collision between a collider triangle and a collidee triangle by moving the collider triangle to the edge of the collidee triangle. The direction of the resolution is determined by the direction parameter. If the triangles are not colliding, this function will return false.

Parameters:

NameTypeDescription
colliderTriangleThe triangle which will be altered if there is a collision
collideeTriangleThe triangle which will not be altered
directionVector 2dThe direction of the collision relative to the collider triangle, expressed as a vector. If a zero vector is passed, the function will not resolve the collision.

Return Type: Boolean

Signatures:

bool resolve_collision(triangle &collider, const triangle &collidee, const vector_2d &direction)

Sprite Bitmap Collision

Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, double x, double y)

Usage:


Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
ptPoint 2dThe point where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, int cell, const point_2d &pt)

Sprite Bitmap Collision

Tests if a sprite will collide with a bitmap drawn at the indicated location.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
bmpBitmapThe bitmap to test
cellIntegerThe cell of the bitmap to check
xDoubleThe x location where the bitmap is drawn
yDoubleThe y location where the bitmap is drawn

Return Type: Boolean

Signatures:

bool sprite_bitmap_collision(sprite s, bitmap bmp, int cell, double x, double y)

Sprite Circle Collision

Tests if a sprite is drawn within an given area (circle).

Parameters:

NameTypeDescription
sSpriteThe sprite to test
cCircleThe circle to check

Return Type: Boolean

Signatures:

bool sprite_circle_collision(sprite s, const circle &c)

Sprite Collision

Tests if two given sprites s1 and s2 are collided

Parameters:

NameTypeDescription
s1Spritethe first Sprite to test
s2Spritethe second Sprite to test

Return Type: Boolean

Signatures:

bool sprite_collision(sprite s1, sprite s2)

Usage:


Sprite Point Collision

Tests if a sprite is drawn at a given point.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
ptPoint 2dThe point to check

Return Type: Boolean

Signatures:

bool sprite_point_collision(sprite s, const point_2d &pt)

Usage:


Sprite Quad Collision

Tests if a sprite is drawn within an given area (quad).

Parameters:

NameTypeDescription
sSpriteThe sprite to test
qQuadThe quad to check

Return Type: Boolean

Signatures:

bool sprite_quad_collision(sprite s, const quad &q)

Sprite Ray Collision

Tests if a sprite is drawn along a given ray.

Parameters:

NameTypeDescription
sSpriteThe sprite to test
originPoint 2dThe origin of the ray
headingVector 2dThe heading of the ray

Return Type: Boolean

Signatures:

bool sprite_ray_collision(sprite s, const point_2d &origin, const vector_2d &heading)

Sprite Rectangle Collision

Tests if a sprite is drawn within an given area (rectangle).

Parameters:

NameTypeDescription
sSpriteThe sprite to test
rectRectangleThe rectangle to check

Return Type: Boolean

Signatures:

bool sprite_rectangle_collision(sprite s, const rectangle &rect)

Usage:


Sprite Triangle Collision

Tests if a sprite is drawn within an given area (triangle).

Parameters:

NameTypeDescription
sSpriteThe sprite to test
tTriangleThe triangle to check

Return Type: Boolean

Signatures:

bool sprite_triangle_collision(sprite s, const triangle &t)

Apply Matrix

Apply Matrix

Use a matrix to transform all of the points in a quad.

Parameters:

NameTypeDescription
matrixMatrix 2dThe matrix with the transformations needed.
qQuadThe quad to transform.

Signatures:

void apply_matrix(const matrix_2d &matrix, quad &q)

Apply Matrix

Use a matrix to transform all of the points in a triangle.

Parameters:

NameTypeDescription
mMatrix 2dThe matrix to be applied to the triangle.
triTriangleThe triangle to tranform.

Signatures:

void apply_matrix(const matrix_2d &m, triangle &tri)

Identity Matrix

Returns the identity matrix. When a matrix_2d or Vector is multiplied by the identity matrix the result is the original matrix or vector.

Return Type: Matrix 2d

Signatures:

matrix_2d identity_matrix()

Matrix Inverse

Calculate the inverse of a matrix.

Parameters:

NameTypeDescription
mMatrix 2dThe matrix to invert.

Return Type: Matrix 2d

Signatures:

matrix_2d matrix_inverse(const matrix_2d &m)

Matrix Multiply

Matrix Multiply

Multiplies the Point 2d parameter v with the [Matrix 2d](/api/physics/#matrix-2d) m and returns the result as a Point 2d. Use this to transform the vector with the matrix (to apply scaling, rotation or translation effects).

Parameters:

NameTypeDescription
mMatrix 2dThe matrix with the transformation to apply.
ptPoint 2dThe point to be transformed.

Return Type: Point 2d

Signatures:

point_2d matrix_multiply(const matrix_2d &m, const point_2d &pt)

Matrix Multiply

Multiplies the two Matrix 2d parameters, m1 by m2, and returns the result as a new Matrix 2d. Use this to combine the effects to two matrix transformations.

Parameters:

NameTypeDescription
m1Matrix 2dThe first matrix
m2Matrix 2dThe second matrix

Return Type: Matrix 2d

Signatures:

matrix_2d matrix_multiply(const matrix_2d &m1, const matrix_2d &m2)

Matrix Multiply

Multiplies the Vector parameter v with the Matrix 2d m and returns the result as a Vector. Use this to transform the vector with the matrix (to apply scaling, rotation or translation effects).

Parameters:

NameTypeDescription
mMatrix 2dThe matrix with the transformation to apply.
vVector 2dThe vector to be transformed.

Return Type: Vector 2d

Signatures:

vector_2d matrix_multiply(const matrix_2d &m, const vector_2d &v)

Matrix To String

This function returns a string representation of a Matrix.

Parameters:

NameTypeDescription
matrixMatrix 2dThe matrix to convert to a string.

Return Type: String

Signatures:

string matrix_to_string(const matrix_2d &matrix)

Rotation Matrix

Returns a rotation matrix that rotates 2d points by the angle.

Parameters:

NameTypeDescription
degDoubleThe amount to rotate points

Return Type: Matrix 2d

Signatures:

matrix_2d rotation_matrix(double deg)

Scale Matrix

Scale Matrix

Create a scale matrix that scales x and y to different degrees.

Parameters:

NameTypeDescription
scalePoint 2dThe amount to scale, with separate x and y components.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(const point_2d &scale)

Scale Matrix

Create a scale matrix that scales x and y to different degrees.

Parameters:

NameTypeDescription
scaleVector 2dThe amount to scale, with separate x and y components.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(const vector_2d &scale)

Scale Matrix

Returns a matrix that can be used to scale 2d points (both x and y).

Parameters:

NameTypeDescription
scaleDoubleThe amount to scale points by.

Return Type: Matrix 2d

Signatures:

matrix_2d scale_matrix(double scale)

Scale Rotate Translate Matrix

Create a matrix that can scale, rotate then translate geometry points.

Parameters:

NameTypeDescription
scalePoint 2dThe amount to scale
degDoubleThe amount to rotate
translatePoint 2dThe amount to move

Return Type: Matrix 2d

Signatures:

matrix_2d scale_rotate_translate_matrix(const point_2d &scale, double deg, const point_2d &translate)

Translation Matrix

Translation Matrix

Returns a translation matric used to translate 2d points by the distance in the point_2d.

Parameters:

NameTypeDescription
ptPoint 2dThe point to translate to.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(const point_2d &pt)

Translation Matrix

Returns a translation matric used to translate 2d points by the distance in the vector_2d.

Parameters:

NameTypeDescription
ptVector 2dThe point to translate to.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(const vector_2d &pt)

Translation Matrix

Returns a matrix that can be used to translate 2d points. Moving them by dx and dy.

Parameters:

NameTypeDescription
dxDoubleThe amount to move points along the x axis.
dyDoubleThe amount to move points along the y axis.

Return Type: Matrix 2d

Signatures:

matrix_2d translation_matrix(double dx, double dy)

Angle Between

Calculates the angle from one vector to another.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe second vector

Return Type: Double

Signatures:

double angle_between(const vector_2d &v1, const vector_2d &v2)

Usage:


Dot Product

Calculates the dot product (scalar product) between the two vector parameters provided (v1 and v2). It returns the result as a scalar value. If the result is 0.0 it means that the vectors are orthogonal (at right angles to each other). If v1 and v2 are unit vectors (length of 1.0) and the dot product is 1.0, it means that v1 and v2 vectors are parallel.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Double

Signatures:

double dot_product(const vector_2d &v1, const vector_2d &v2)

Usage:


Is Zero Vector

Returns if the vector is a null/zero vector — having no size or direction.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Boolean

Signatures:

bool is_zero_vector(const vector_2d &v)

Ray Intersection Point

Casts a ray in a heading and returns true is it intersects with a line

Parameters:

NameTypeDescription
from_ptPoint 2dThe origin of the ray
headingVector 2dThe direction the ray is heading (as a Vector 2d)
lLineThe line to be checked
ptPoint 2dOutputs the point where the line and ray intersect

Return Type: Boolean

Signatures:

bool ray_intersection_point(const point_2d &from_pt, const vector_2d &heading, const line &l, point_2d &pt)

Unit Vector

Returns the unit vector of the parameter vector (v). The unit vector has a magnitude of 1, resulting in a vector that indicates the direction of the original vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d unit_vector(const vector_2d &v)

Usage:


Vector Add

Adds the two passed in vectors returns the result as new Vector 2d.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector.
v2Vector 2dThe other vector.

Return Type: Vector 2d

Signatures:

vector_2d vector_add(const vector_2d &v1, const vector_2d &v2)

Usage:


Vector Angle

Calculates the angle of a vector

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_angle(const vector_2d v)

Usage:


Vector From Angle

Returns a Vector 2d from the supplied angle and distance.

Parameters:

NameTypeDescription
angleDoubleThe angle in degrees
magnitudeDoubleThe length of the vector

Return Type: Vector 2d

Signatures:

vector_2d vector_from_angle(double angle, double magnitude)

Usage:


Vector From Line

Returns a vector that points from the start to the end of a line.

Parameters:

NameTypeDescription
lLineThe line

Return Type: Vector 2d

Signatures:

vector_2d vector_from_line(const line &l)

Vector From Point To Rect

Returns a vector from a point to a rectangle.

Parameters:

NameTypeDescription
ptPoint 2dThe point
rectRectangleThe rectangle

Return Type: Vector 2d

Signatures:

vector_2d vector_from_point_to_rect(const point_2d &pt, const rectangle &rect)

Vector In Rect

Returns true if the resulting vector would end in the rectangle if placed at the origin.

Parameters:

NameTypeDescription
vVector 2dThe vector
rectRectangleThe rectangle

Return Type: Boolean

Signatures:

bool vector_in_rect(const vector_2d &v, const rectangle &rect)

Vector Invert

Returns a new Vector that is an inverted version of the parameter vector (v). In other words, the -/+ sign of the x and y values are changed.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d vector_invert(const vector_2d &v)

Usage:


Vector Limit

Returns a scaled vector that ensures the new vector points in the same direction as v, but has a magnitude that is limited to the length specified in the limit prameter.

Parameters:

NameTypeDescription
vVector 2dThe vector
limitDoubleIts maximum magnitude

Return Type: Vector 2d

Signatures:

vector_2d vector_limit(const vector_2d &v, double limit)

Vector Magnitude

Returns the magnitude (or “length”) of the vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_magnitude(const vector_2d &v)

Usage:


Vector Magnitude Squared

Returns the squared magnitude (or “length”) of the vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Double

Signatures:

double vector_magnitude_squared(const vector_2d &v)

Usage:


Vector Multiply

Multiplies the vector by the passed in value.

Parameters:

NameTypeDescription
v1Vector 2dThe original vector
sDoubleThe amount to multiply by

Return Type: Vector 2d

Signatures:

vector_2d vector_multiply(const vector_2d &v1, double s)

Usage:


Vector Normal

Returns a new Vector 2d that is perpendicular (“normal”) to the parameter vector v provided. The concept of a “normal” vector is usually extracted from (or associated with) a line. Note: when passed a zero or null vector (a vector with no magnitude or direction) then this function returns a zero/null vector.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: Vector 2d

Signatures:

vector_2d vector_normal(const vector_2d &v)

Usage:


Vector Out Of Circle From Circle

Returns a vector to back one circle out of another, assuming the first circle was moving at a specified velocity.

Parameters:

NameTypeDescription
srcCircleThe circle that is moving
boundsCircleThe area you want to move the circle out of
velocityVector 2dThe circle’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_circle_from_circle(const circle &src, const circle &bounds, const vector_2d &velocity)

Vector Out Of Circle From Point

Returns the vector out to move a point back out of a circle, given the point was moving at the specified velocity.

Parameters:

NameTypeDescription
ptPoint 2dThe point that is moving
cCircleThe circle you want to move the point out of
velocityVector 2dThe point’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_circle_from_point(const point_2d &pt, const circle &c, const vector_2d &velocity)

Vector Out Of Rect From Circle

Returns a vector that can be used to move a circle back out of a rectangle, given that the circle is moving at the specified velocity.

Parameters:

NameTypeDescription
cCircleThe circle that is moving
rectRectangleThe area you wan to move the circle out of
velocityVector 2dThe circle’s velocity

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_circle(const circle &c, const rectangle &rect, const vector_2d &velocity)

Vector Out Of Rect From Point

Determines the vector needed to move back from point pt out of rectangle rect given the point was moving at the velocity specified.

Parameters:

NameTypeDescription
ptPoint 2dThe point you want to move out of a rectangle
rectRectangleThe rectangle to move out of
velocityVector 2dThe velocity of the point. This is used to determine where the point should return to.

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_point(const point_2d &pt, const rectangle &rect, const vector_2d &velocity)

Vector Out Of Rect From Rect

Returns the vector needed to move rectangle src back out of rectangle bounds assuming the rectangle was moving at the velocity specified.

Parameters:

NameTypeDescription
srcRectangleThe rectangle you want to move.
boundsRectangleThe area you want to move the rectangle out of
velocityVector 2dThe velocity of the src rectangle

Return Type: Vector 2d

Signatures:

vector_2d vector_out_of_rect_from_rect(const rectangle &src, const rectangle &bounds, const vector_2d &velocity)

Vector Point To Point

Returns a Vector 2d created from the difference from the p1 to the second p2 points (Point2D).

Parameters:

NameTypeDescription
startPoint 2dThe starting point
end_ptPoint 2dThe ending point

Return Type: Vector 2d

Signatures:

vector_2d vector_point_to_point(const point_2d &start, const point_2d &end_pt)

Usage:


Vector Subtract

Subtracts the second vector parameter (v2) from the first vector (v1) and returns the result as new Vector 2d.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector.
v2Vector 2dThe other vector.

Return Type: Vector 2d

Signatures:

vector_2d vector_subtract(const vector_2d &v1, const vector_2d &v2)

Usage:


Vector To

Vector To

Returns a new Vector 2d using the x and y value of a Point 2d parameter. This is a vector from the origin to that point.

Parameters:

NameTypeDescription
p1Point 2dThe point

Return Type: Vector 2d

Signatures:

vector_2d vector_to(const point_2d &p1)

Vector To

Returns a vector to the indicated point.

Parameters:

NameTypeDescription
xDoubleThe amount to move horizontally
yDoubleThe amount to move vertically

Return Type: Vector 2d

Signatures:

vector_2d vector_to(double x, double y)

Usage:


Vector To String

Get a text description of the Vector 2d.

Parameters:

NameTypeDescription
vVector 2dThe vector

Return Type: String

Signatures:

string vector_to_string(const vector_2d &v)

Usage:


Vectors Equal

Determines if two vectors are the same.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Boolean

Signatures:

bool vectors_equal(const vector_2d &v1, const vector_2d v2)

Vectors Not Equal

Determines if two vectors are not the same.

Parameters:

NameTypeDescription
v1Vector 2dThe first vector
v2Vector 2dThe other vector

Return Type: Boolean

Signatures:

bool vectors_not_equal(const vector_2d &v1, const vector_2d v2)

Types

Matrix 2d

FieldTypeDescription
elementsDoubleThe elements of the matrix

In SplashKit, matrices can be used to combine together a number of operations that need to be performed on Vector 2d values. You can translate, rotate and scale, and combine these together into a single matrix that can then be applied to vectors and points.