Skip to content

GameMath

Matthew Daly edited this page Jan 3, 2023 · 7 revisions

Namespace: Verdant

class GameMath

public static class GameMath

Navigate

Properties

Property Description
Random The global Random instance, used by any internal random number generation.

Methods

float AngleBetweenPoints

public static float AngleBetweenPoints(Vec2 a, Vec2 target)

Given two points in 2D space, get the angle between them.

Returns: A float representing the angle between the two points.

Parameter Description
Vec2 a The first point.
Vec2 target The second point.

Vec2 Vec2FromAngle

public static Vec2 Vec2FromAngle(float angle)

Given an angle, calculate an appropriate Vec2.

Returns: A Vec2 with a magnitude of 1, pointing in the direction of the angle.

Parameter Description
float angle The angle of the vector.

float GetDistance

public static float GetDistance(Vec2 a, Vec2 b)

Given two points in 2D space, get the distance between them.

Returns: The distance between the two points.

Parameter Description
Vec2 a The first point.
Vec2 b The second point.

bool CheckRectIntersection

public static bool CheckRectIntersection(float x1, float y1, int w1, int h1, float x2, float y2, int w2, int h2)

Check if two AABBs are intersecting.

Returns: Returns true if the AABBs are intersecting, and false otherwise.

Parameter Description
float x1 The x coordinate of the first AABB.
float y1 The y coordinate of the first AABB.
int w1 The width of the first AABB.
int h1 The height of the first AABB.
float x2 The x coordinate of the second AABB.
float y2 The y coordinate of the second AABB.
int w2 The width of the second AABB.
int h2 The height of the second AABB.

bool CheckRectIntersection

public static bool CheckRectIntersection(Vec2 pos1, int w1, int h1, Vec2 pos2, int w2, int h2)

Check if two AABBs are intersecting.

Returns: Returns true if the AABBs are intersecting, and false otherwise.

Parameter Description
Vec2 pos1 The position of the first AABB.
int w1 The width of the first AABB.
int h1 The height of the first AABB.
Vec2 pos2 The position of the second AABB.
int w2 The width of the second AABB.
int h2 The height of the second AABB.

bool CheckPointOnRectIntersection

public static bool CheckPointOnRectIntersection(Vec2 point, float x, float y, int w, int h)

Check if a 2D point is intersecting with an AABB.

Returns: Returns true if the point is within the AABB, and false otherwise.

Parameter Description
Vec2 point The point.
float x The x coordinate of the AABB.
float y The y coordinate of the AABB.
int w The width of the AABB.
int h The height of the AABB.

float RandomFloat

public static float RandomFloat()

Generate a random float value.

Returns: A random float value.

float RandomFloat

public static float RandomFloat(float min, float max)

Generate a random float value within a given bounds.

Returns: A random float value.

Parameter Description
float min The minimum value of the float.
float max The maximum value of the float.
Clone this wiki locally