File tree Expand file tree Collapse file tree 5 files changed +70
-0
lines changed
Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1010#include " JSIBox2dWorld.h"
1111#include " JSIBox2dBodyDef.h"
1212#include " JSIBox2dPolygonShape.h"
13+ #include " JSIBox2dCircleShape.h"
1314#include " JSIBox2dFixtureDef.h"
1415
1516namespace Box2d {
@@ -22,6 +23,7 @@ namespace Box2d {
2223 installFunction (" b2World" , JSIBox2dWorld::createCtor ());
2324 installFunction (" b2BodyDef" , JSIBox2dBodyDef::createCtor ());
2425 installFunction (" b2PolygonShape" , JSIBox2dPolygonShape::createCtor ());
26+ installFunction (" b2CircleShape" , JSIBox2dCircleShape::createCtor ());
2527 installFunction (" b2FixtureDef" , JSIBox2dFixtureDef::createCtor ());
2628 }
2729 };
Original file line number Diff line number Diff line change 1+ //
2+ // Created by Tomek Zawadzki on 26.02.23.
3+ //
4+
5+ #pragma once
6+
7+ #include " box2d/b2_circle_shape.h"
8+
9+ namespace Box2d {
10+ using namespace facebook ;
11+
12+ class JSIBox2dCircleShape : public JsiWrappingSharedPtrHostObject <b2CircleShape> {
13+ public:
14+
15+ JSI_HOST_FUNCTION (SetRadius) {
16+ getObject ()->m_radius = arguments[0 ].asNumber ();
17+ return jsi::Value::undefined ();
18+ }
19+
20+ JSI_EXPORT_FUNCTIONS (JSI_EXPORT_FUNC(JSIBox2dCircleShape, SetRadius))
21+
22+ /* *
23+ * Constructor
24+ */
25+ JSIBox2dCircleShape (const b2CircleShape &shape)
26+ : JsiWrappingSharedPtrHostObject<b2CircleShape>(
27+ std::make_shared<b2CircleShape>(std::move(shape))) {}
28+
29+ /* *
30+ * Returns the underlying object from a host object of this type
31+ */
32+ static std::shared_ptr<b2CircleShape> fromValue (jsi::Runtime &runtime,
33+ const jsi::Value &obj) {
34+ return obj.asObject (runtime)
35+ .asHostObject <JSIBox2dCircleShape>(runtime)
36+ ->getObject ();
37+ }
38+
39+ static const jsi::HostFunctionType
40+ createCtor () {
41+ return JSI_HOST_FUNCTION_LAMBDA {
42+ b2CircleShape shape;
43+
44+ return jsi::Object::createFromHostObject (
45+ runtime,
46+ std::make_shared<JSIBox2dCircleShape>(
47+ std::move (shape)
48+ )
49+ );
50+ };
51+ };
52+ };
53+ }
Original file line number Diff line number Diff line change 77#include " box2d/b2_shape.h"
88#include " JSIBox2dShape.h"
99#include " JSIBox2dPolygonShape.h"
10+ #include " JSIBox2dCircleShape.h"
1011
1112namespace Box2d {
1213 class Utils {
@@ -17,6 +18,9 @@ namespace Box2d {
1718 if (obj.isHostObject <JSIBox2dPolygonShape>(runtime)) {
1819 return JSIBox2dPolygonShape::fromValue (runtime, value).get ();
1920 }
21+ if (obj.isHostObject <JSIBox2dCircleShape>(runtime)) {
22+ return JSIBox2dCircleShape::fromValue (runtime, value).get ();
23+ }
2024 }
2125 return nullptr ;
2226 }
Original file line number Diff line number Diff line change 11import { NativeModules , Platform } from 'react-native' ;
22import type {
33 b2BodyDef ,
4+ b2CircleShape ,
45 b2FixtureDef ,
56 b2PolygonShape ,
67 b2Vec2 ,
@@ -18,6 +19,7 @@ declare global {
1819 b2World : ( vec : b2Vec2 ) => b2World ;
1920 b2BodyDef : ( ) => b2BodyDef ;
2021 b2PolygonShape : ( ) => b2PolygonShape ;
22+ b2CircleShape : ( ) => b2CircleShape ;
2123 b2FixtureDef : ( ) => b2FixtureDef ;
2224 } ;
2325}
Original file line number Diff line number Diff line change @@ -35,6 +35,15 @@ export interface b2PolygonShape extends b2Shape {
3535 SetAsBox ( hx : number , hy : number ) : void ;
3636}
3737
38+ export interface b2CircleShape extends b2Shape {
39+ /**
40+ * Set the radius of the circle.
41+ * @param r Radius of the circle.
42+ * @return Circle shape.
43+ **/
44+ SetRadius ( r : number ) : void ;
45+ }
46+
3847export interface b2FixtureDef {
3948 /**
4049 * The density, usually in kg/m^2.
You can’t perform that action at this time.
0 commit comments