Skip to content

Commit 71f4e5c

Browse files
committed
v1.1.2: add body.setTransform(xf) signature
1 parent 0e58a85 commit 71f4e5c

21 files changed

+109
-34
lines changed

dist/planck-with-testbed.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,12 @@ declare class Body$1 {
16291629
* @param angle The world rotation in radians.
16301630
*/
16311631
setTransform(position: Vec2Value, angle: number): void;
1632+
/**
1633+
* Set the position of the body's origin and rotation. Manipulating a body's
1634+
* transform may cause non-physical behavior. Note: contacts are updated on the
1635+
* next call to World.step.
1636+
*/
1637+
setTransform(xf: Transform): void;
16321638
synchronizeTransform(): void;
16331639
/**
16341640
* Update fixtures in broad-phase.

dist/planck-with-testbed.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.planck = {}));
33
})(this, function(exports2) {
44
"use strict";/**
5-
* Planck.js v1.1.1
5+
* Planck.js v1.1.2
66
* @license The MIT license
77
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
88
*
@@ -2641,11 +2641,15 @@
26412641
Body2.prototype.getTransform = function() {
26422642
return this.m_xf;
26432643
};
2644-
Body2.prototype.setTransform = function(position, angle) {
2644+
Body2.prototype.setTransform = function(a2, b2) {
26452645
if (this.isWorldLocked() == true) {
26462646
return;
26472647
}
2648-
this.m_xf.setNum(position, angle);
2648+
if (typeof b2 === "number") {
2649+
this.m_xf.setNum(a2, b2);
2650+
} else {
2651+
this.m_xf.setTransform(a2);
2652+
}
26492653
this.m_sweep.setTransform(this.m_xf);
26502654
var broadPhase = this.m_world.m_broadPhase;
26512655
for (var f = this.m_fixtureList; f; f = f.m_next) {

dist/planck-with-testbed.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck-with-testbed.mjs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.1.1
2+
* Planck.js v1.1.2
33
* @license The MIT license
44
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
55
*
@@ -2637,11 +2637,15 @@ var Body = (
26372637
Body2.prototype.getTransform = function() {
26382638
return this.m_xf;
26392639
};
2640-
Body2.prototype.setTransform = function(position, angle) {
2640+
Body2.prototype.setTransform = function(a2, b2) {
26412641
if (this.isWorldLocked() == true) {
26422642
return;
26432643
}
2644-
this.m_xf.setNum(position, angle);
2644+
if (typeof b2 === "number") {
2645+
this.m_xf.setNum(a2, b2);
2646+
} else {
2647+
this.m_xf.setTransform(a2);
2648+
}
26452649
this.m_sweep.setTransform(this.m_xf);
26462650
var broadPhase = this.m_world.m_broadPhase;
26472651
for (var f = this.m_fixtureList; f; f = f.m_next) {

dist/planck-with-testbed.mjs.map

+1-1
Large diffs are not rendered by default.

dist/planck.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,12 @@ declare class Body$1 {
16291629
* @param angle The world rotation in radians.
16301630
*/
16311631
setTransform(position: Vec2Value, angle: number): void;
1632+
/**
1633+
* Set the position of the body's origin and rotation. Manipulating a body's
1634+
* transform may cause non-physical behavior. Note: contacts are updated on the
1635+
* next call to World.step.
1636+
*/
1637+
setTransform(xf: Transform): void;
16321638
synchronizeTransform(): void;
16331639
/**
16341640
* Update fixtures in broad-phase.

dist/planck.js

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/planck.mjs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Planck.js v1.1.1
2+
* Planck.js v1.1.2
33
* @license The MIT license
44
* @copyright Copyright (c) 2024 Erin Catto, Ali Shakiba
55
*
@@ -2637,11 +2637,15 @@ var Body = (
26372637
Body2.prototype.getTransform = function() {
26382638
return this.m_xf;
26392639
};
2640-
Body2.prototype.setTransform = function(position, angle) {
2640+
Body2.prototype.setTransform = function(a2, b2) {
26412641
if (this.isWorldLocked() == true) {
26422642
return;
26432643
}
2644-
this.m_xf.setNum(position, angle);
2644+
if (typeof b2 === "number") {
2645+
this.m_xf.setNum(a2, b2);
2646+
} else {
2647+
this.m_xf.setTransform(a2);
2648+
}
26452649
this.m_sweep.setTransform(this.m_xf);
26462650
var broadPhase = this.m_world.m_broadPhase;
26472651
for (var f = this.m_fixtureList; f; f = f.m_next) {

dist/planck.mjs.map

+1-1
Large diffs are not rendered by default.

docs/pages/api/classes/Body.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,15 @@ This will alter the mass and velocity.
916916

917917
### setTransform()
918918

919+
#### setTransform(position, angle)
920+
919921
> **setTransform**(`position`, `angle`): `void`
920922
921923
Set the position of the body's origin and rotation. Manipulating a body's
922924
transform may cause non-physical behavior. Note: contacts are updated on the
923925
next call to World.step.
924926

925-
#### Parameters
927+
##### Parameters
926928

927929
**position**: [`Vec2Value`](../interfaces/Vec2Value)
928930

@@ -932,7 +934,23 @@ The world position of the body's local origin.
932934

933935
The world rotation in radians.
934936

935-
#### Returns
937+
##### Returns
938+
939+
`void`
940+
941+
#### setTransform(xf)
942+
943+
> **setTransform**(`xf`): `void`
944+
945+
Set the position of the body's origin and rotation. Manipulating a body's
946+
transform may cause non-physical behavior. Note: contacts are updated on the
947+
next call to World.step.
948+
949+
##### Parameters
950+
951+
**xf**: [`Transform`](Transform)
952+
953+
##### Returns
936954

937955
`void`
938956

docs/pages/api/classes/World.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ World object.
1313
1414
#### Parameters
1515

16-
**def?**: [`Vec2`](Vec2) \| [`WorldDef`](../interfaces/WorldDef)
16+
**def?**: [`Vec2Value`](../interfaces/Vec2Value) \| [`WorldDef`](../interfaces/WorldDef)
1717

1818
World definition or gravity vector.
1919

docs/pages/api/classes/body.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -916,13 +916,15 @@ This will alter the mass and velocity.
916916

917917
### setTransform()
918918

919+
#### setTransform(position, angle)
920+
919921
> **setTransform**(`position`, `angle`): `void`
920922
921923
Set the position of the body's origin and rotation. Manipulating a body's
922924
transform may cause non-physical behavior. Note: contacts are updated on the
923925
next call to World.step.
924926

925-
#### Parameters
927+
##### Parameters
926928

927929
**position**: [`Vec2Value`](../interfaces/Vec2Value)
928930

@@ -932,7 +934,23 @@ The world position of the body's local origin.
932934

933935
The world rotation in radians.
934936

935-
#### Returns
937+
##### Returns
938+
939+
`void`
940+
941+
#### setTransform(xf)
942+
943+
> **setTransform**(`xf`): `void`
944+
945+
Set the position of the body's origin and rotation. Manipulating a body's
946+
transform may cause non-physical behavior. Note: contacts are updated on the
947+
next call to World.step.
948+
949+
##### Parameters
950+
951+
**xf**: [`Transform`](Transform)
952+
953+
##### Returns
936954

937955
`void`
938956

docs/pages/api/classes/world.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ World object.
1313
1414
#### Parameters
1515

16-
**def?**: [`Vec2`](Vec2) \| [`WorldDef`](../interfaces/WorldDef)
16+
**def?**: [`Vec2Value`](../interfaces/Vec2Value) \| [`WorldDef`](../interfaces/WorldDef)
1717

1818
World definition or gravity vector.
1919

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "planck",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "2D JavaScript/TypeScript physics engine for cross-platform HTML5 game development",
55
"homepage": "https://github.com/piqnt/planck.js",
66
"keywords": [

src/dynamics/Body.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { options } from "../util/options";
1212
import { Vec2, Vec2Value } from "../common/Vec2";
1313
import { Rot } from "../common/Rot";
1414
import { Sweep } from "../common/Sweep";
15-
import { Transform } from "../common/Transform";
15+
import { Transform, TransformValue } from "../common/Transform";
1616
import { Velocity } from "./Velocity";
1717
import { Position } from "./Position";
1818
import { Fixture, FixtureDef, FixtureOpt } from "./Fixture";
@@ -565,13 +565,24 @@ export class Body {
565565
* @param position The world position of the body's local origin.
566566
* @param angle The world rotation in radians.
567567
*/
568-
setTransform(position: Vec2Value, angle: number): void {
568+
setTransform(position: Vec2Value, angle: number): void;
569+
/**
570+
* Set the position of the body's origin and rotation. Manipulating a body's
571+
* transform may cause non-physical behavior. Note: contacts are updated on the
572+
* next call to World.step.
573+
*/
574+
setTransform(xf: Transform): void;
575+
setTransform(a: Vec2Value | Transform, b?: number): void {
569576
_ASSERT && console.assert(this.isWorldLocked() == false);
570577
if (this.isWorldLocked() == true) {
571578
return;
572579
}
580+
if (typeof b === "number") {
581+
this.m_xf.setNum(a as Vec2Value, b);
582+
} else {
583+
this.m_xf.setTransform(a as TransformValue);
584+
}
573585

574-
this.m_xf.setNum(position, angle);
575586
this.m_sweep.setTransform(this.m_xf);
576587

577588
const broadPhase = this.m_world.m_broadPhase;

0 commit comments

Comments
 (0)