1
1
#include " FastCryptoHostObject.h"
2
2
#include < jsi/jsi.h>
3
3
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
+
4
11
namespace margelo {
5
12
6
13
using namespace facebook ;
@@ -14,6 +21,48 @@ std::vector<jsi::PropNameID> FastCryptoHostObject::getPropertyNames(jsi::Runtime
14
21
jsi::Value FastCryptoHostObject::get (jsi::Runtime& runtime, const jsi::PropNameID& propNameId) {
15
22
auto propName = propNameId.utf8 (runtime);
16
23
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
+
17
66
throw std::runtime_error (" Not yet implemented!" );
18
67
}
19
68
0 commit comments