Skip to content

Commit a649bb0

Browse files
committed
adding box2d as submodule
1 parent b0d76d4 commit a649bb0

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "externals/box2d"]
2+
path = externals/box2d
3+
url = [email protected]:erincatto/box2d.git

cpp/FastCryptoHostObject.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
#include "FastCryptoHostObject.h"
22
#include <jsi/jsi.h>
33

4+
#include <box2d/box2d/b2_math.h>
5+
#include <box2d/box2d/b2_world.h>
6+
#include <box2d/box2d/b2_body.h>
7+
#include <box2d/box2d/b2_polygon_shape.h>
8+
#include <box2d/box2d/b2_fixture.h>
9+
#include <android/log.h>
10+
411
namespace margelo {
512

613
using namespace facebook;
@@ -14,6 +21,48 @@ std::vector<jsi::PropNameID> FastCryptoHostObject::getPropertyNames(jsi::Runtime
1421
jsi::Value FastCryptoHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) {
1522
auto propName = propNameId.utf8(runtime);
1623

24+
b2Vec2 gravity(0.0f, -10.0f);
25+
b2World world(gravity);
26+
__android_log_print(ANDROID_LOG_DEBUG, "overscore", "createWorld");
27+
28+
// ground box
29+
b2BodyDef groundBodyDef;
30+
groundBodyDef.position.Set(0.0f, -10.0f);
31+
b2Body* groundBody = world.CreateBody(&groundBodyDef);
32+
// ground polygon
33+
b2PolygonShape groundBox;
34+
groundBox.SetAsBox(50.0f, 10.0f);
35+
groundBody->CreateFixture(&groundBox, 0.0f);
36+
37+
// dynamic body
38+
b2BodyDef bodyDef;
39+
bodyDef.type = b2_dynamicBody;
40+
bodyDef.position.Set(0.0f, 4.0f);
41+
b2Body* body = world.CreateBody(&bodyDef);
42+
//attach
43+
b2PolygonShape dynamicBox;
44+
dynamicBox.SetAsBox(1.0f, 1.0f);
45+
46+
b2FixtureDef fixtureDef;
47+
fixtureDef.shape = &dynamicBox;
48+
fixtureDef.density = 1.0f;
49+
fixtureDef.friction = 0.3f;
50+
51+
body->CreateFixture(&fixtureDef);
52+
53+
54+
// simulating the world
55+
float timeStep = 1.0f / 60.0f;
56+
int32 velocityIterations = 6;
57+
int32 positionIterations = 2;
58+
for (int32 i = 0; i < 60; ++i)
59+
{
60+
world.Step(timeStep, velocityIterations, positionIterations);
61+
b2Vec2 position = body->GetPosition();
62+
float angle = body->GetAngle();
63+
__android_log_print(ANDROID_LOG_DEBUG, "overscore","%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
64+
}
65+
1766
throw std::runtime_error("Not yet implemented!");
1867
}
1968

externals/box2d

Submodule box2d added at 9dc24a6

scripts/copy-box2d.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
cp

0 commit comments

Comments
 (0)