2#include <box2cpp/box2cpp.h>
3#include <tmxlite/Map.hpp>
6#ifndef CORI_PIXELS_PER_METER
7 #define CORI_PIXELS_PER_METER 16
12 namespace Components {
196 const b2Hull hull = b2ComputeHull(vertices.data(), vertices.size());
197 if (hull.count == 0) {
198 std::string str_vertices;
199 for (
auto [x, y] : vertices) {
200 str_vertices +=
"(" + std::to_string(x) +
", " + std::to_string(x) +
")";
202 CORI_CORE_CHECK(hull.count != 0,
"Failed to create ConvexHull. Vertices: {}", str_vertices);
207 return b2ComputeHull(vertices.data(), vertices.size());
211 operator b2Hull& () {
215 operator const b2Hull* ()
const {
227 Polygon(
const b2Polygon& polygon) : b2Polygon(polygon) {}
230 return b2MakeOffsetRoundedBox(halfSize.x, halfSize.y, offset, rotation, radius);
234 return b2MakeBox(halfSize.x, halfSize.y);
238 return b2MakeRoundedBox(halfSize.x, halfSize.y, radius);
242 return b2MakePolygon(hull, radius);
246 return b2MakeOffsetRoundedPolygon(hull, offset, rotation, radius);
254 Circle(
const b2Circle& circle) : b2Circle(circle) {}
255 Circle(
const Vec2 center,
const float radius) : b2Circle{center, radius} {}
258 return { center, radius };
266 Capsule(
const b2Capsule& capsule) : b2Capsule(capsule) {}
267 Capsule(
const Vec2 center1,
const Vec2 center2,
const float radius) : b2Capsule{ center1, center2, radius } {}
270 return { center1, center2, radius };
278 Segment(
const b2Segment& segment) : b2Segment(segment) {}
282 return { point1, point2 };
#define CORI_CORE_CHECK(x,...)
void operator*=(Cori::Physics::Vec2 &a, Cori::Physics::Vec2 b)
Capsule(const b2Capsule &capsule)
Capsule(const Vec2 center1, const Vec2 center2, const float radius)
static Capsule Create(Vec2 center1, Vec2 center2, float radius)
Circle(const Vec2 center, const float radius)
static Circle Create(Vec2 center, float radius)
Circle(const b2Circle &circle)
ConvexHull(const b2Hull &hull)
static ConvexHull Create(const std::vector< Vec2 > &vertices)
static Polygon CreatePolygon(const ConvexHull &hull, const Vec2 offset, const Rot rotation=Rot{ 1, 0 }, const float radius=0.0f)
static Polygon CreatePolygon(const ConvexHull &hull, const float radius=0.0f)
Polygon(const b2Polygon &polygon)
static Polygon CreateBox(const Vec2 halfSize, const Vec2 offset, const Rot rotation=Rot{ 1, 0 }, const float radius=0.0f)
static Polygon CreateBox(const Vec2 halfSize)
static Polygon CreateBox(const Vec2 halfSize, const float radius)
static Segment Create(Vec2 point1, Vec2 point2)
Segment(const b2Segment &segment)
Segment(const Vec2 point1, const Vec2 point2)
Entities are the essential part of WorldSystem.
b2Vec2 Vec2
An alias for Box2D native vec2 type, if you see it somewhere, be sure data there is in meters contrar...
glm::vec2 ToPixels(const Vec2 vec)
Converts physical meters to camera space pixels.
WindingOrder GetPolygonWindingOrder(const std::vector< Vec2 > &polygon)
Calculates the winding order of the polygon made up from individual points. Box2D version....
const char * WindingOrderToString(const WindingOrder order)
Converts the WindingOrder enumerator to string, for logging.
b2CollisionPlane CollisionPlane
std::string Vec2ToString(const Vec2 vec)
Converts a native Box2D vec2 to string, for logging.
Vec2 ToMeters(const glm::vec2 vec)
Converts camera space pixels to physical meters.
ShapeUserData(const Cori::World::Entity &entity)
Cori::World::Entity m_Entity