Class PhysicsStatics

Class Documentation

class legion::physics::PhysicsStatics

Public Static Functions

static void DetectConvexConvexCollision(ConvexCollider *convexA, ConvexCollider *convexB, const math::mat4 &transformA, const math::mat4 &transformB, ConvexConvexCollisionInfo &outCollisionInfo, physics_manifold &manifold)

Given 2 ConvexCollider and their respective transforms, checks if the colliders are colliding. The result is recorded in the physics_manifold.

static inline void GetSupportPoint(const math::vec3 &planePosition, const math::vec3 &direction, ConvexCollider *collider, const math::mat4 &colliderTransform, math::vec3 &worldSupportPoint)

Given a transformed ConvexCollider and a direction, Gets the vertex furthest in the given direction.

Return

returns true if a seperating axis was found

Parameters
  • planePosition: The position of the support plane in world space

  • direction: The direction we would like to know the support point of

  • collider: The ConvexCollider in question

  • colliderTransform: A mat4 describing the transform of the collider

  • worldSupportPoint: [out] the resulting support point

static inline void GetSupportPointNoTransform(math::vec3 planePosition, math::vec3 direction, ConvexCollider *collider, const math::mat4 &colliderTransform, math::vec3 &worldSupportPoint)

Given a ConvexCollider and a direction, Gets the vertex furthest in the given direction. The function does this with as little transformation as necessary.

Return

returns true if a seperating axis was found

Parameters
  • planePosition: The position of the support plane in world space

  • direction: The direction we would like to know the support point of

  • collider: The ConvexCollider in question

  • colliderTransform: A mat4 describing the transform of the collider

  • worldSupportPoint: [out] the resulting support point

static float GetSupportPoint(const std::vector<math::vec3> &vertices, const math::vec3 &direction, math::vec3 &outVec)

Given a std::vector of vertices, gets the support point in the given direction.

static inline bool FindSeperatingAxisByExtremePointProjection(ConvexCollider *convexA, ConvexCollider *convexB, const math::mat4 &transformA, const math::mat4 &transformB, PointerEncapsulator<HalfEdgeFace> &refFace, float &maximumSeperation, bool shouldDebug = false)

Given 2 ConvexColliders, convexA and convexB, checks if one of the faces of convexB creates a seperating axis that seperates the given convex shapes.

Return

returns true if a seperating axis was found

Parameters
  • convexA: the reference collider

  • convexB: the collider that will create the seperating axes

  • transformA: the transform of convexA

  • transformB: the transform of convexB

  • refFace: [out] a HalfEdgeEdge* that has a normal parallel to the seperating axis

  • maximumSeperation: [out] the seperation on the given seperating axis

static bool FindSeperatingAxisByGaussMapEdgeCheck(ConvexCollider *convexA, ConvexCollider *convexB, const math::mat4 &transformA, const math::mat4 &transformB, PointerEncapsulator<HalfEdgeEdge> &refEdge, PointerEncapsulator<HalfEdgeEdge> &incEdge, math::vec3 &seperatingAxisFound, float &maximumSeperation, bool shouldDebug = false)

Given 2 ConvexColliders, Goes through every single possible edge combination in order to check for a valid seperating axis. This is done by creating a minkowski face with each edge combination.

Return

returns true if a seperating axis was found

Parameters
  • convexA: the reference collider

  • convexB: the incident collider

  • transformA: the transform of convexA

  • transformB: the transform of convexB

  • refEdge: [out] the resulting reference Edge

  • incEdge: [out] the resulting incident Edge

  • seperatingAxisFound: [out] the resulting seperating axis found

  • seperation: [out] the amount of seperation

static bool DetectConvexSphereCollision(ConvexCollider *convexA, const math::mat4 &transformA, math::vec3 sphereWorldPosition, float sphereRadius, float &maximumSeperation)

Given a ConvexCollider and sphere with a position and a readius, checks if these 2 shapes are colliding.

static std::pair<math::vec3, math::vec3> ConstructAABBFromPhysicsComponentWithTransform(ecs::component_handle<physicsComponent> physicsComponentToUse, const math::mat4 &transform)
static float GetPhysicsComponentSupportPointAtDirection(math::vec3 direction, physicsComponent &physicsComponentToUse)
static std::pair<math::vec3, math::vec3> ConstructAABBFromVertices(const std::vector<math::vec3> &vertices)
static std::pair<math::vec3, math::vec3> ConstructAABBFromTransformedVertices(const std::vector<math::vec3> &vertices, const math::mat4 &transform)
static std::pair<math::vec3, math::vec3> CombineAABB(const std::pair<math::vec3, math::vec3> &first, const std::pair<math::vec3, math::vec3> &second)

Creates one big AABB from two AABBs The first element in the tuple will be the lower bounds The second element in the tuple will be the higher bounds The AABB will be between the two vec3’s in the tuple.

static inline void SutherlandHodgmanFaceClip(math::vec3 &planeNormal, math::vec3 &planePosition, std::vector<ContactVertex> &inputList, std::vector<ContactVertex> &outputList, HalfEdgeEdge *clippingEdge)

Given a 3D plane, clips the vertices in the inputList and places the results in the output list.

static inline void FindClosestPointsToLineSegment(math::vec3 p1, math::vec3 p2, math::vec3 p3, math::vec3 p4, math::vec3 &outp1p2, math::vec3 &outp3p4)

Given a set of points that represent 2 line segments, find a line segment that reperesents the closest points between the 2 lines.

Parameters
  • p1: The start of the first line

  • p2: The end of the second line

  • p3: The start of the third line

  • p4: The end of the fourth line

static inline math::vec2 LinearSystemCramerSolver2D(float a, float b, float c, float d, float e, float f)

Solves a linear system with 2 equations using cramers rule

Note

a,b,c,d is a column major matrix

Parameters
  • a: The value at a11 of the matrix

  • b: The value at a21 of the matrix

  • c: The value at a12 of the matrix

  • d: The value at a22 of the matrix

  • e: The result of the linear transformation in the x axis

  • f: The result of the linear transformation in the y axis

static inline float PointDistanceToPlane(const math::vec3 &planeNormal, const math::vec3 &planePosition, const math::vec3 &point)

Finds the distance of a point given a 3D plane Assumes the plane normal is normalized.

static inline bool IsPointAbovePlane(const math::vec3 &planeNormal, const math::vec3 &planePosition, const math::vec3 &point)

Checks if the distance of a point from a 3D plane is above zero.

static inline bool FindLineToPlaneIntersectionPoint(const math::vec3 &planeNormal, const math::vec3 &planePosition, const math::vec3 &startPoint, const math::vec3 &endPoint, math::vec3 &intersectionPoint)

Given a line going from start point to end point finds the intersection point of the line to a given 3D plane.

Return

Returns true if an intersection is found

static inline bool FindLineToPlaneIntersectionPoint(const math::vec3 &planeNormal, const math::vec3 &planePosition, const math::vec3 &startPoint, const math::vec3 &endPoint, math::vec3 &intersectionPoint, float &interpolant)

Given a line going from start point to end point finds the intersection point of the line to a given 3D plane.

Return

Returns true if an intersection is found

Parameters
  • [out] interpolant: The calculated interpolant required to get from the startPoint to the endPoint

static inline float FindLineToPointInterpolant(const math::vec3 &startPoint, const math::vec3 &endPoint, const math::vec3 &planePosition, const math::vec3 &planeNormal)

Given a line going from a startPoint to and endPoint, finds the interpolant required to intersect a given 3D plane

static inline std::vector<std::vector<math::vec4>> GenerateVoronoi(std::vector<math::vec3> points, math::vec2 xRange, math::vec2 yRange, math::vec2 zRange, math::vec3 containerResolution, bool xPeriodic = false, bool yPeriodic = false, bool zPeriodic = false, int initMem = 8)

Creates a Voronoi diagram based on the given parameters.

Return

A list of lists of vec4’s

Parameters
  • points: A list of points these will serve as the points of the voronoi diagram.

  • xRange: The min and max of the width of the voronoi diagram space.

  • yRange: The min and max of the height of the voronoi diagram space.

  • zRange: The min and max of the depth of the voronoi diagram space.

  • containerResolution: The resolution of the contianer the voronoi diagram will be generated in.

  • xPeriodic: A bool that decides whether x should be periodic.

  • yPeriodic: A bool that decides whether y should be periodic.

  • zPeriodic: A bool that decides whether z should be periodic.

  • initMem: The initial memory amount.

static inline std::vector<std::vector<math::vec4>> GenerateVoronoi(std::vector<math::vec3> points, const double xMin = -5, const double xMax = 5, const double yMin = -5, const double yMax = 5, const double zMin = -5, const double zMax = 5, const double conResX = 10, const double conResY = 10, const double conResZ = 10, bool xPeriodic = false, bool yPeriodic = false, bool zPeriodic = false, int initMem = 8)

Creates a Voronoi diagram based on the given parameters.

Return

A list of lists of vec4’s

Parameters
  • points: A list of points these will serve as the points of the voronoi diagram.

  • xMin: The min of the width of the voronoi diagram space.

  • xMax: The max of the width of the voronoi diagram space.

  • yMin: The min of the height of the voronoi diagram space.

  • yMax: The max of the height of the voronoi diagram space

  • zMin: The min of the depth of the voronoi diagram space.

  • zMax: The max of the depth of the voronoi diagram space

  • conResX: The x resolution of the contianer the voronoi diagram will be generated in.

  • conResY: The y resolution of the contianer the voronoi diagram will be generated in.

  • conResZ: The z resolution of the contianer the voronoi diagram will be generated in.

  • xPeriodic: A bool that decides whether x should be periodic.

  • yPeriodic: A bool that decides whether y should be periodic.

  • zPeriodic: A bool that decides whether z should be periodic.

  • initMem: The initial memory amount.

static inline std::vector<std::vector<math::vec4>> GenerateVoronoi(voro::container &con, std::vector<math::vec3> points)

Creates a Voronoi diagram based on the given parameters.

Return

A list of lists of vec4’s

Parameters
  • con: The container that hold the parameters and generates the voronoi diagram.

  • points: A list of points these will serve as the points of the voronoi diagram.

static inline std::vector<std::vector<math::vec4>> GenerateVoronoi(voro::container &con)

Creates a Voronoi diagram based on the given parameters.

Return

A list of lists of vec4’s

Parameters
  • con: The container that hold the parameters and generates the voronoi diagram.

static inline bool CollideAABB(const math::vec3 low0, const math::vec3 high0, const math::vec3 low1, const math::vec3 high1)

Checks collision between two AABB colliders and returns whether there is collision.

Return

Whether there is collision

Parameters
  • low0: the lower bounds of the first collider

  • high0: the higher bounds of the first collider

  • low1: the lower bounds of the second collider

  • high1: the higher bounds of the second collider

static inline bool CollideAABB(const std::pair<math::vec3, math::vec3> col0, const std::pair<math::vec3, math::vec3> col1)

Checks collision between two AABB colliders and returns whether there is collision.

Return

Whether there is collision

Parameters
  • col0: the lower and higher bounds of the first collider

  • col1: the lower and higher bounds of the second collider