physics.box2d: Rid #include of 'box2d.h'.

This commit is contained in:
Rod Kay
2023-12-31 21:17:53 +11:00
parent 6188ad4e80
commit be98a56d0c
6 changed files with 104 additions and 23 deletions

View File

@@ -17,7 +17,7 @@ extern "C"
%import "../../c_math/generate/c_math_c.i"
%include "../source/c/box2d.h"
# %include "../source/c/box2d.h"
%include "../source/c/box2d-shape.h"
%include "../source/c/box2d-object.h"
%include "../source/c/box2d-joint.h"

View File

@@ -1,7 +1,7 @@
#ifndef C_BOX2D_JOINT_H
#define C_BOX2D_JOINT_H
#include "box2d.h"
#include "c_math.h"
#include "box2d-object.h"

View File

@@ -2,7 +2,7 @@
#define C_BOX2D_OBJECT_H
#include "box2d.h"
#include "c_math.h"
#include "box2d-shape.h"

View File

@@ -1,7 +1,7 @@
#ifndef C_BOX2D_SHAPE_H
#define C_BOX2D_SHAPE_H
#include "box2d.h"
#include "c_math.h"

View File

@@ -43,8 +43,7 @@ public:
b2Fixture* Nearest;
float
ReportFixture
(b2Fixture* fixture,
ReportFixture (b2Fixture* fixture,
const b2Vec2& point,
const b2Vec2& normal,
float fraction)
@@ -57,6 +56,7 @@ public:
};
/// Collisions
//
@@ -223,7 +223,8 @@ b2d_free_Space (struct Space* Self)
void
b2d_Space_Gravity_is (Space* Self, Vector_3* Now)
b2d_Space_Gravity_is (Space* Self,
Vector_3* Now)
{
b2World* the_World = to_World (Self);
@@ -232,7 +233,8 @@ b2d_Space_Gravity_is (Space* Self, Vector_3* Now)
void
b2d_Space_evolve (Space* Self, float By)
b2d_Space_evolve (Space* Self,
float By)
{
b2World* the_World = to_World (Self);
contact_Listener* the_contact_Listener = dynamic_cast <contact_Listener*> (the_World->GetContactManager().m_contactListener);
@@ -244,19 +246,20 @@ b2d_Space_evolve (Space* Self, float By)
void
b2d_Space_add_Object (Space* Self, Object* the_Object)
b2d_Space_add_Object (Space* Self,
Object* the_Object)
{
b2World* the_World = (b2World*) Self;
the_Object->body = the_World->CreateBody (&the_Object->bodyDef);
// the_Object->body->SetUserData (the_Object);
the_Object->body->SetUserData (the_Object);
the_Object->body->CreateFixture (&the_Object->fixtureDef);
}
void
b2d_Space_rid_Object (Space* Self, Object* the_Object)
b2d_Space_rid_Object (Space* Self,
Object* the_Object)
{
((b2World*)Self)->DestroyBody (the_Object->body);
the_Object->body = 0;
@@ -264,7 +267,8 @@ b2d_Space_rid_Object (Space* Self, Object* the_Object)
void
b2d_Space_add_Joint (Space* Self, Joint* the_Joint)
b2d_Space_add_Joint (Space* Self,
Joint* the_Joint)
{
b2World* the_World = (b2World*) Self;
b2JointDef* jointDef = (b2JointDef*) the_Joint;
@@ -375,4 +379,81 @@ b2d_Space_cast_Ray (Space* Self, Vector_3* From,
}
/// Pointcasts
//
class QueryCallback : public b2QueryCallback
{
public:
QueryCallback (const b2Vec2& point)
{
m_point = point;
m_fixture = NULL;
}
bool
ReportFixture (b2Fixture* fixture) override
{
b2Body* body = fixture->GetBody();
bool inside = fixture->TestPoint (m_point);
if (inside)
{
m_fixture = fixture;
return false; // We are done, terminate the query.
}
return true; // Continue the query.
}
b2Vec2 m_point;
b2Fixture* m_fixture;
};
b2d_point_Collision
b2d_Space_cast_Point (Space* Self,
Vector_3* Point)
{
b2d_point_Collision Result;
b2World* the_World = (b2World *)Self;
const b2Vec2 p = b2Vec2 (Point->x,
Point->y);
// Make a small box.
//
b2AABB aabb;
b2Vec2 d;
d.Set (0.001f, 0.001f);
aabb.lowerBound = p - d;
aabb.upperBound = p + d;
printf ("\n");
printf ("b2d_Space_cast_Point ~ p = %f %f\n", p.x, p.y);
// Query the world for overlapping shapes.
//
QueryCallback Callback (p);
the_World->QueryAABB (&Callback, aabb);
if (Callback.m_fixture)
{
Result.near_Object = (Object*) Callback.m_fixture->GetBody()->GetUserData().pointer;
}
else
{
Result.near_Object = NULL;
}
Result.Site_world = *Point;
return Result;
}
} // extern "C"

View File

@@ -2,7 +2,7 @@
#define C_BOX2D_SPACE_H
#include "box2d.h"
#include "c_math.h"
#include "box2d-object.h"
#include "box2d-joint.h"