Skip to content

Commit 22118e0

Browse files
committed
Add body quat and update types
1 parent 2d1dd8f commit 22118e0

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

index.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module "bullet-raub" {
1010

1111
type TTraceHit = Readonly<{
1212
hit: boolean;
13-
body: Body;
13+
body: TBodyInstance;
1414
pos: TVec3Both;
1515
norm: TVec3Both;
1616
}>;
@@ -32,7 +32,9 @@ declare module "bullet-raub" {
3232
*/
3333
readonly isDestroyed: boolean;
3434

35-
/** Stringification helper. */
35+
/**
36+
* Stringification helper. Shows "Body { ... }".
37+
*/
3638
toString(): string;
3739

3840
/**
@@ -54,11 +56,16 @@ declare module "bullet-raub" {
5456
*/
5557
type: TBodyType;
5658

57-
/** Position in 3D. Default is `[0, 0, 0]`. */
59+
/**
60+
* Position in 3D. Default is `[0, 0, 0]`.
61+
*/
5862
pos: TVec3Either;
5963

64+
/** Rotation euler angles. Default is `[0, 0, 0]`. */
65+
rot: TVec3Either;
66+
6067
/** Rotation quaternion. Default is `[0, 0, 0, 1]`. */
61-
rot: TQuatEither;
68+
quat: TQuatEither;
6269

6370
/** Linear velocity. Default is `[0, 0, 0]`. */
6471
vell: TVec3Either;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"author": "Luis Blanco <luisblanco1337@gmail.com>",
33
"name": "bullet-raub",
4-
"version": "4.0.0",
4+
"version": "4.1.0",
55
"description": "Bullet-driven physics API",
66
"license": "MIT",
77
"main": "index.js",

src/cpp/body.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ void Body::init(Napi::Env env, Napi::Object exports) {
2929
JS_ASSIGN_SETTER(type);
3030
JS_ASSIGN_SETTER(pos);
3131
JS_ASSIGN_SETTER(rot);
32+
JS_ASSIGN_SETTER(quat);
3233
JS_ASSIGN_SETTER(vell);
3334
JS_ASSIGN_SETTER(vela);
3435
JS_ASSIGN_SETTER(size);
@@ -249,6 +250,24 @@ JS_IMPLEMENT_SETTER(Body, rot) { THIS_CHECK; SETTER_VEC3_ARG;
249250
RET_UNDEFINED;
250251
}
251252

253+
JS_IMPLEMENT_GETTER(Body, quat) { THIS_CHECK;
254+
QUAT_TO_OBJ(_cacheRot, quat);
255+
RET_VALUE(quat);
256+
}
257+
258+
259+
JS_IMPLEMENT_SETTER(Body, quat) { THIS_CHECK; SETTER_QUAT_ARG;
260+
CACHE_CAS(_cacheRot, v);
261+
262+
btTransform transform = _body->getCenterOfMassTransform();
263+
transform.setRotation(_cacheRot);
264+
_body->setCenterOfMassTransform(transform);
265+
266+
emit("quat", 1, &value);
267+
268+
RET_UNDEFINED;
269+
}
270+
252271

253272
JS_IMPLEMENT_SETTER(Body, vell) { THIS_CHECK; SETTER_VEC3_ARG;
254273
CACHE_CAS(_cacheVell, v);

src/cpp/body.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ DECLARE_ES5_CLASS(Body, Body);
7777
JS_DECLARE_GETTER(Body, rot);
7878
JS_DECLARE_SETTER(Body, rot);
7979

80+
JS_DECLARE_GETTER(Body, quat);
81+
JS_DECLARE_SETTER(Body, quat);
82+
8083
JS_DECLARE_GETTER(Body, vell);
8184
JS_DECLARE_SETTER(Body, vell);
8285

0 commit comments

Comments
 (0)